Skip to content

Commit 4e6ffe8

Browse files
committed
Use new condition for dp convergence
1 parent 842e06d commit 4e6ffe8

File tree

1 file changed

+12
-55
lines changed
  • src/+datools/+statistical/+ensemble

1 file changed

+12
-55
lines changed

src/+datools/+statistical/+ensemble/ETPF2.m

+12-55
Original file line numberDiff line numberDiff line change
@@ -42,56 +42,11 @@ function analysis(obj, R, y)
4242
Bric = Tx - w*ones(1, ensN);
4343
Aric = ensN*(W - w*w.') - Bric*Bric.';
4444

45-
46-
f = @(D) D*D + Bric*D + D*Bric.' - Aric;
47-
48-
D0 = 1e-6*randn(ensN - 1);
49-
D0 = (D0 + D0.')/2;
50-
D0 = [D0, -sum(D0, 2); -sum(D0), -sum(-sum(D0))];
51-
it = 1;
52-
maxit = 1e3;
53-
fD0 = f(D0);
54-
fnorm = norm(fD0(:));
55-
56-
while fnorm > 1e-12 && it < maxit
57-
k = sylvester(D0 + Bric, D0 + Bric.', fD0);
58-
if isnan(norm(k))
59-
break;
60-
end
61-
alpha = 1;
62-
fnormnew = inf;
63-
while fnormnew > fnorm
64-
65-
66-
67-
68-
D0new = D0 - alpha*k;
69-
D0new = (D0new + D0new.')/2;
70-
fD0new = f(D0new);
71-
fnormnew = norm(fD0new(:));
72-
alpha = alpha/2;
73-
if alpha == 0
74-
break;
75-
end
76-
end
77-
if alpha == 0
78-
break;
79-
end
80-
D0 = D0new;
81-
fD0 = fD0new;
82-
fnorm = fnormnew;
83-
84-
it = it + 1;
85-
end
86-
87-
D = D0;
88-
89-
90-
%rs = @(D) reshape(D, ensN, ensN);
91-
%urs = @(D) reshape(D, ensN*ensN, 1);
92-
%f = @(t, D) urs(-Bric * rs(D) - rs(D)*(Bric.') + Aric - rs(D)*rs(D));
93-
%D = zeros(ensN, ensN);
94-
%D = rs(dp(f, D(:)));
45+
rs = @(D) reshape(D, ensN, ensN);
46+
urs = @(D) reshape(D, ensN*ensN, 1);
47+
f = @(t, D) urs(-Bric * rs(D) - rs(D)*(Bric.') + Aric - rs(D)*rs(D));
48+
D = zeros(ensN, ensN);
49+
D = rs(dp(f, D(:)));
9550

9651

9752
P = sqrt(tau/(ensN - 1))*(eye(ensN) - ones(ensN)/ensN)*randn(ensN)*(eye(ensN) - ones(ensN)/ensN);
@@ -109,11 +64,13 @@ function analysis(obj, R, y)
10964

11065
function y = dp(f, y0)
11166

112-
h = 0.001;
67+
n = sqrt(numel(y0));
68+
69+
h = 0.1;
11370
y = y0;
11471

115-
abstol = 1e-13;
116-
reltol = 1e-13;
72+
abstol = 1e-6;
73+
reltol = 1e-6;
11774

11875
ks = zeros([numel(y0), 7]);
11976

@@ -154,7 +111,8 @@ function analysis(obj, R, y)
154111
hnew = h*min(facmax, max(facmin, fac*(1/err)^(1/(orderE + 1))));
155112
else
156113

157-
if norm(f(0, ynew)) < 1e-9 || t > 1000
114+
% condition used by Acevedo, de Wiljes and Reich.
115+
if norm(reshape(ynew, n, n) - reshape(y, n, n), 'inf') < 1e-3 || t > 1000
158116
break;
159117
end
160118

@@ -174,6 +132,5 @@ function analysis(obj, R, y)
174132

175133
end
176134

177-
178135
end
179136

0 commit comments

Comments
 (0)