-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_ffigure_evals.m
167 lines (164 loc) · 5.67 KB
/
util_ffigure_evals.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
function util_ffigure_evals(par,out)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%this function makes a convergence plot comparing several optimization
%methods
%
%by Hans De Sterck, September 2011
% Editet by Asbjørn Nilsen Riseth, April 2018
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nCurves=0;
% first determine the minimum value of f (because we will plot the
% convergence of f to the minimum value achieved in any of the
% tests)
minval = Inf;
if par.compareNGMRES_sdls==1
minval=min(minval,min(out.out_ngmres_sdls.logf));
end
if par.compareNGMRES_sd==1
minval=min(minval,min(out.out_ngmres_sd.logf));
end
if par.compareNCG==1
minval=min(minval,min(out.out_ncg.TraceFunc(2:end)));
end
if par.compare_sdls==1
minval=min(minval,min(out.out_sdls.logf));
end
if par.compareLBFGS==1
minval=min(minval,min(out.out_lbfgs.TraceFunc(2:end)));
end
if par.compareNGMRESO_sdls==1
minval=min(minval,min(out.out_ngmreso_sdls.logf));
end
if par.compareNGMRESO_sd==1
minval=min(minval,min(out.out_ngmreso_sd.logf));
end
if par.compareNGMRESO_ALS==1
minval=min(minval,min(out.out_ngmreso_als.logf));
end
if par.compareNGMRES_ALS==1
minval=min(minval,min(out.out_ngmres_als.logf));
end
if par.compareALS==1
minval=min(minval,min(out.out_als.logf));
end
%% Then, make the plots
if par.compareNGMRES_sdls==1
var = out.out_ngmres_sdls;
cnum = 1;
mind = 1:par.mispace{cnum}:length(var.logf);
semilogy(var.logfev,var.logf-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='N-GMRES-sdls';
hold on
end
if par.compareNGMRES_sd==1
var = out.out_ngmres_sd;
cnum = 2;
mind = 1:par.mispace{cnum}:length(var.logf);
semilogy(var.logfev,var.logf-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='N-GMRES-sd';
hold on
end
if par.compareNCG==1
var = out.out_ncg;
cnum = 4;
mind = 1:par.mispace{cnum}:length(var.TraceFunc(2:end));
semilogy(var.TraceFuncEvals(2:end),var.TraceFunc(2:end)-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='N-CG';
hold on
end
if par.compare_sdls==1
var = out.out_sdls;
cnum = 5;
mind = 1:par.mispace{cnum}:length(var.logf);
semilogy(var.logfev,var.logf-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='sdls';
hold on
end
if par.compareLBFGS==1
var = out.out_lbfgs;
cnum = 7;
mind = 1:par.mispace{cnum}:length(var.TraceFunc(2:end));
semilogy(var.TraceFuncEvals(2:end),var.TraceFunc(2:end)-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='L-BFGS';
hold on
end
if par.compareNGMRESO_sdls==1
var = out.out_ngmreso_sdls;
cnum = 8;
mind = 1:par.mispace{cnum}:length(var.logf);
semilogy(var.logfev,var.logf-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='N-GMRES-O-sdls';
hold on
end
if par.compareNGMRESO_sd==1
var = out.out_ngmreso_sd;
cnum = 9;
mind = 1:par.mispace{cnum}:length(var.logf);
semilogy(var.logfev,var.logf-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='N-GMRES-O-sd';
hold on
end
if par.compareNGMRESO_ALS==1
var = out.out_ngmreso_als;
cnum = 10;
mind = 1:par.mispace{cnum}:length(var.logf);
semilogy(var.logfev,var.logf-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='N-GMRES-O-ALS';
hold on
end
if par.compareNGMRES_ALS==1
var = out.out_ngmres_als;
cnum = 11;
mind = 1:par.mispace{cnum}:length(var.logf);
semilogy(var.logfev,var.logf-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='N-GMRES-ALS';
hold on
end
if par.compareALS==1
var = out.out_als;
cnum = 12;
mind = 1:par.mispace{cnum}:length(var.logf);
semilogy(var.logfev,var.logf-minval+par.epsi, ...
par.fs{cnum},'LineWidth',1,'MarkerIndices',mind)
nCurves=nCurves+1;
legendstr{nCurves}='ALS';
hold on
end
% optionally indicate the restart points in red for the N-GMRES runs
if par.par_ngmres.logRestart & par.restartfigure
% TODO: Update / fix this
if par.compareNGMRES_sdls==1
logfMod=out.out_ngmres_sdls.logf-minval;
logfMod(out.out_ngmres_sdls.logRestart==0)=NaN;
semilogy(logfMod+par.epsi,'or')
end
if par.compareNGMRES_sd==1
logfMod=out.out_ngmres_sd.logf-minval;
logfMod(out.out_ngmres_sd.logRestart==0)=NaN;
semilogy(logfMod+par.epsi,'+r')
end
% TODO: Add logrestart plots for NGMRES{,O}_ALS
end
hold off
legend(legendstr)
xlabel('f and g evaluations')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%