-
Notifications
You must be signed in to change notification settings - Fork 0
/
samplePointsPolesPlots.m
298 lines (254 loc) · 8.96 KB
/
samplePointsPolesPlots.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
nepPlot = {'bent_beam', 'buckling_plate', 'gun', 'nep1', 'schrodinger_abc'};
nepPlot = setdiff(nepPlot, 'bent_beam');
dmax = 60; %max degree
tol = 1e-10; %tolerance for phases 1 & 2
N = 10; %default problem size
%nc = 1000; %number of sample points for Sigma
nc = 300; %number of sample points for Sigma
nc2 = 50;
useZZ = 1;
useZ2 = 1;
nb_test_pbs = length(nepPlot);
fprintf('Number of test problems: %3.0f\n',nb_test_pbs)
% Option parameters for nep2rat.m
opts.dmax = dmax;
opts.tol1 = tol;
opts.tol2 = tol;
opts.tol = tol;
%Arrays memory allocation
Z = zeros(nb_test_pbs,nc);
gam = zeros(nb_test_pbs,1); %centers
rad = zeros(nb_test_pbs,1); %radii
half_disc = gam;
% Options for the plot
beta = 3.5; % stretch for the axes. We can probably set a specific one for each problem
nRows = ceil(sqrt(nb_test_pbs));
nCols = ceil(nb_test_pbs/nRows);
mkSizeSigma = 5;
mkPts = 7;
hold off
for kk = 1:nb_test_pbs
switch nepPlot{kk} %generate F
case 'bent_beam' % temporary
gam(kk) = 60;
rad(kk) = 30;
half_disc(kk) = 1; %half disc domain
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'buckling_plate' % The smallest poles are in k*pi/2, and in 4.70
gam(kk) = 11;
rad(kk) = 9;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'canyon_particle'
gam(kk) = -9e-2+1e-6i;
rad(kk) = .1;
half_disc(kk) = 1; %half disc domain
stepSize = 1;
[coeffs,fun,F] = nlevp(nepPlot{kk}, stepSize);
case 'clamped_beam_1d'
gam(kk) = 0;
rad(kk) = 10;
[coeffs,fun,F] = nlevp(nepPlot{kk}, 100);
case 'distributed_delay1'
gam(kk) = 0;
rad(kk) = 2;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'fiber'
gam(kk) = 0;
rad(kk) = 2e-3;
half_disc(kk) = 1; %half disc domain
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'gun'
gam(kk) = 62500;
rad(kk) = 50000;
half_disc(kk) = 1; %half disc domain
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'hadeler'
gam(kk) = -30;
rad(kk) = 11.5;
[coeffs,fun,F] = nlevp(nepPlot{kk},200);
case 'loaded_string'
gam(kk) = 362;%14;
rad(kk) = 358;%11;
%KAPPA = 1; mass = 1; % pole is KAPPA/mass
[coeffs,fun,F] = nlevp(nepPlot{kk},100);%, N, KAPPA, mass);
case 'nep1'
gam(kk) = 0;
rad(kk) = 3;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'nep2'
gam(kk) = 0;
rad(kk) = 2;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'nep3'
gam(kk) = 5i;
rad(kk) = 2; % found 14 evals in this disc
[coeffs,fun,F] = nlevp(nepPlot{kk},N);
case 'neuron_dde'
gam(kk) = 0;
rad(kk) = 15;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'photonic_crystal'
% The poles of the default values are +-1.18-0.005i and +-1.26-0.01
gam(kk) = 11;
rad(kk) = 9;
[coeffs,fun,F] = nlevp(nepPlot{kk}, N);
case 'pillbox_small'
gam(kk) = 0.08;
rad(kk) = 0.05;
half_disc(kk) = 1; %half disc domain
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'railtrack2_rep'
% railtrack2_rep has a pole in 0, so we shifted it in 5 (?)
gam(kk) = 3;
rad(kk) = 2;
[coeffs,fun,F] = nlevp(nepPlot{kk}, N);
case 'railtrack_rep'
gam(kk) = -3;
rad(kk) = 2;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'sandwich_beam'
gam(kk) = 0;
rad(kk) = 2;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'schrodinger_abc'
gam(kk) = -10;
rad(kk) = 5;
[coeffs,fun,F] = nlevp(nepPlot{kk}, N);
case 'square_root'
gam(kk) = 10+50i;
rad(kk) = 50;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'time_delay'
gam(kk) = 0;
rad(kk) = 15;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'time_delay2'
gam(kk) = 0;
rad(kk) = 15;
[coeffs,fun,F] = nlevp(nepPlot{kk});
case 'time_delay3'
gam(kk) = 2;
rad(kk) = 3;
[coeffs,fun,F] = nlevp(nepPlot{kk}, N, 5);
otherwise
gam(kk) = 0;
rad(kk) = 2;
[coeffs,fun,F] = nlevp(nepPlot{kk}, N);
end
Fsize(kk) = length(coeffs{1}); %record the size of each NEP
%fprintf('Pb size %5d\n', Fsize(kk))
fprintf('*******************************\n');
fprintf('kk=%2d, Problem: %s, n =%4d\n',kk, nepPlot{kk},Fsize(kk));
fprintf('*******************************\n');
%Generate set of points Z, Z2 and if needed ZZ = Z U Z2
rng(13); %Fix the random number generator
%Z(kk,:) = rand(1,nc).*exp(rand(1,nc)*2*pi*1i);
Z(kk, :) = disksample(nc, gam(kk), rad(kk));
if half_disc(kk)
negPoints = imag(Z(kk,:)) < 0;
% Z(kk,negPoints) = Z(kk, negPoints)';
Z(kk, :) = halfdisksample(nc, gam(kk), rad(kk));
Z2 = gam(kk) + rad(kk)*exp(1i*linspace(0,pi,nc2)); % half circle
Z2 = [Z2(2:end-1), linspace(-rad(kk), rad(kk), nc2)+gam(kk)];
else
Z2 = gam(kk) + rad(kk)*exp(1i*linspace(0,2*pi,2*nc2));
end
%Z(kk,:) = Z(kk,:)*rad(kk) + gam(kk); % shift to the correct points
if useZZ %merge Z and Z2
ZZ = [Z(kk,:) Z2];
%now look for repetitions and remove
ZRows = [real(ZZ)', imag(ZZ)'];
Z1Rows = union(ZRows,ZRows,'rows');
ZZ = Z1Rows(:,1)' + Z1Rows(:,2)'*1i;
else
ZZ = Z(kk,:);
end
if useZ2
opts.Z2 = Z2;
else
opts.Z2 = ZZ;
end
alg = 0;
%% Surrogate AAA
disp('Surrogate AAA')
alg = alg+1;
algo_used{alg} ='surrogate';
opts.phase1 = 'sur';
opts.phase2 = '';
[Am, Bm, Rm, info] = nep2rat(F, ZZ, opts);
subplot(nRows,nCols, kk)
hold off
plot(ZZ, '.b', 'MarkerSize',mkSizeSigma);
hold on
plot(info.z, 'or', 'MarkerSize',mkPts)
plot(info.pol, 'xr', 'MarkerSize',mkPts)
% %% Set valued AAA original
% disp('Set valued AAA original')
% alg = alg+1;
% algo_used{alg} = 'set valued AAA';
% [r, pol, res, zer, z, ff, w, errvec] = aaa_svOrig(fun, ZZ , 'tol', opts.tol2, 'mmax', opts.dmax+1);
% plot(z, 'o');
% plot(pol, 'x');
%% Weighted AAA
disp('Weighted AAA')
alg = alg+1;
algo_used{alg} = 'weighted AAA';
opts.phase2 = '';
opts.phase1 = 'weighted';
FWAAA.coeffs = coeffs;
FWAAA.fun = fun;
[Am, Bm, Rm, info] = nep2rat(FWAAA, ZZ, opts);
plot(info.z, 'sg', 'MarkerSize',mkPts);
plot(info.pol, '+g', 'MarkerSize',mkPts);
%% Surrogate AAA + LB
disp('Surrogate AAA + LB')
alg = alg+1;
algo_used{alg} = 'surrogate+LB refinement';
opts.phase2 = 'LB';
[Am, Bm, Rm, info] = nep2rat(F, ZZ, opts);
plot(info.zLB(length(info.z)+1:end), 'dk', 'MarkerSize',mkPts);
%
% %% LB after we get ordered poles from surrogate,
% %% and cyclically repeat them
% disp('LB (NLEIGS) with poles from surrogate')
% alg = alg+1;
% algo_used{alg} = 'NLEIGS with surr AAA poles';
% %ADD by GMNP
% if ~isempty(info.msg) || isempty(info.ordpol)
% %sandwich_beam returns a 0-th degree approximation if the tolerance
% %is large, so there are no poles and NLEIGS cannot run.
% setSpecialChar = 1;
% else
% setSpecialChar = 0;
% opts.Xi = info.ordpol(1:length(info.pol));
% end
% if ~setSpecialChar
% opts.cyclic = 1;
% opts.phase1 = 'LB';
% opts.phase2 = '';
% [Am, Bm, Rm, info] = nep2rat(F, ZZ, opts);
% plot(info.zLB, 'o')
% end
% nice title in tex
mytitle = replace(nepPlot{kk}, '_', '\_');
title(mytitle, 'Interpreter', 'latex')
switch nepPlot{kk}
case 'bent_beam'
axis([-80 95 -12 35])
case 'buckling_plate'
axis([-15 35 -10 10])
case 'gun'
axis([-90000 117000 -50000 55000])
case 'nep1'
axis([-5 5 -5 5])
case 'schrodinger_abc'
axis([-17 10 -25 25])
otherwise
axis([real(gam(kk))-rad(kk)*beta real(gam(kk))+rad(kk)*beta imag(gam(kk))-rad(kk)*beta imag(gam(kk))+rad(kk)*beta])
end
end
% legend({'Set $\Sigma$', '$\sigma_i$ for Surrogate AAA', ' $\xi_i$ for Surrogate AAA', '$\sigma_i$ for set-valued AAA', ...
% '$\xi_i$ for set-valued AAA', '$\sigma_i$ for weighted AAA', '$\xi_i$ for weighted AAA', '$\sigma_i$ added by LB refinement', '$\sigma_i$ for SLEPc'}, 'Interpreter', 'latex')
figure(1)
legend({'Set $\Sigma$', '$\sigma_i$ for surr AAA', '$\xi_i$ for surr AAA', ...
'$\sigma_i$ for wght AAA', '$\xi_i$ for wght AAA', '$\sigma_i$ added by LB'}, 'Interpreter', 'latex', 'Location','SouthWest')