forked from czaj/Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutputf.m
More file actions
39 lines (34 loc) · 1.81 KB
/
outputf.m
File metadata and controls
39 lines (34 loc) · 1.81 KB
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
function stop = outputf(x,optimvalues,state)
global B_backup
persistent LL_backup IterTime
% save tmp1
stop = false;
if isequal(state,'init')
disp('')
fprintf('%6s %6s %8s %16s %17s %18s %17s %12s \n','Iter.','Eval.','dB','Step','f(x)','df(x)','Opt. Cond.','Iter. time');
elseif isequal(state,'iter')
IterTocNote = toc(IterTime);
if optimvalues.iteration == 0
if ~isfield('optimvalues','stepsize') || isempty(optimvalues.stepsize)
optimvalues.stepsize = NaN;
optimvalues.firstorderopt = NaN; % this is to make it work with fminsearch
end
fprintf('%4d %6d %15.10f %15.10f %19.10f %15.10f %15.10f %9.4f\n',optimvalues.iteration,optimvalues.funccount,NaN,optimvalues.stepsize,optimvalues.fval,NaN,optimvalues.firstorderopt,IterTocNote);
B_backup = x;
LL_backup = optimvalues.fval;
else
if ~isfield(optimvalues,'stepsize') || isempty(optimvalues.stepsize) % this is to make it work with fminsearch
optimvalues.stepsize = NaN;
optimvalues.firstorderopt = NaN; % this is to make it work with fminsearch
end
dB = max(abs(x - B_backup));
if isfield(optimvalues,'procedure') && ~isempty(optimvalues.procedure)
fprintf('%4d %6d %15.10f %15.10f %19.10f %15.10f %15.10f %9.4f %s\n',optimvalues.iteration,optimvalues.funccount,dB,optimvalues.stepsize,optimvalues.fval,LL_backup - optimvalues.fval,optimvalues.firstorderopt,IterTocNote,optimvalues.procedure);
else
fprintf('%4d %6d %15.10f %15.10f %19.10f %15.10f %15.10f %9.4f\n',optimvalues.iteration,optimvalues.funccount,dB,optimvalues.stepsize,optimvalues.fval,LL_backup - optimvalues.fval,optimvalues.firstorderopt,IterTocNote);
end
B_backup = x;
LL_backup = optimvalues.fval;
end
end
IterTime = tic;