csminwel1.m: two small fixes

- gh always exists, no need to check
- allow having non-bad gradient in first iteration
time-shift
Johannes Pfeifer 2021-01-21 19:33:30 +01:00 committed by Stéphane Adjemian (Charybdis)
parent 5bee25c06e
commit b652b6d932
Signed by: stepan
GPG Key ID: 295C1FE89E17EB3C
1 changed files with 8 additions and 11 deletions

View File

@ -228,16 +228,16 @@ while ~done
f2=f;f3=f;f1=f;retcode2=retcode1;retcode3=retcode1;
end
%how to pick gh and xh
if f3 < f - crit && badg3==0 && f3 < f2 && f3 < f1
if f3 < f - crit && badg3==0 && f3 < f2 && f3 < f1 %f3 has improved function, gradient is good and it is smaller than the other two
ih=3;
fh=f3;xh=x3;gh=g3;badgh=badg3;retcodeh=retcode3;
elseif f2 < f - crit && badg2==0 && f2 < f1
elseif f2 < f - crit && badg2==0 && f2 < f1 %f2 has improved function, gradient is good and it is smaller than f2
ih=2;
fh=f2;xh=x2;gh=g2;badgh=badg2;retcodeh=retcode2;
elseif f1 < f - crit && badg1==0
elseif f1 < f - crit && badg1==0 %f1 has improved function, gradient is good
ih=1;
fh=f1;xh=x1;gh=g1;badgh=badg1;retcodeh=retcode1;
else
else % stuck or bad gradient
[fh,ih] = min([f1,f2,f3]);
%disp_verbose(sprintf('ih = %d',ih))
%eval(['xh=x' num2str(ih) ';'])
@ -253,12 +253,10 @@ while ~done
%eval(['retcodeh=retcode' num2str(ih) ';'])
retcodei=[retcode1,retcode2,retcode3];
retcodeh=retcodei(ih);
if exist('gh')
nogh=isempty(gh);
else
nogh=1;
end
if nogh
nogh=isempty(gh);
badgh=1;
if nogh %recompute gradient
if NumGrad
[gh, badgh]=get_num_grad(method,fcn,penalty,fh,xh,epsilon,varargin{:});
elseif grad_fun_provided
@ -268,7 +266,6 @@ while ~done
badgh = ~cost_flag;
end
end
badgh=1;
end
%end of picking
stuck = (abs(fh-f) < crit);