Skip to content
Snippets Groups Projects
Verified Commit b652b6d9 authored by Johannes Pfeifer's avatar Johannes Pfeifer Committed by Stéphane Adjemian
Browse files

csminwel1.m: two small fixes

- gh always exists, no need to check
- allow having non-bad gradient in first iteration
parent 5bee25c0
Branches
Tags
No related merge requests found
Pipeline #4789 passed
...@@ -228,16 +228,16 @@ while ~done ...@@ -228,16 +228,16 @@ while ~done
f2=f;f3=f;f1=f;retcode2=retcode1;retcode3=retcode1; f2=f;f3=f;f1=f;retcode2=retcode1;retcode3=retcode1;
end end
%how to pick gh and xh %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; ih=3;
fh=f3;xh=x3;gh=g3;badgh=badg3;retcodeh=retcode3; 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; ih=2;
fh=f2;xh=x2;gh=g2;badgh=badg2;retcodeh=retcode2; 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; ih=1;
fh=f1;xh=x1;gh=g1;badgh=badg1;retcodeh=retcode1; fh=f1;xh=x1;gh=g1;badgh=badg1;retcodeh=retcode1;
else else % stuck or bad gradient
[fh,ih] = min([f1,f2,f3]); [fh,ih] = min([f1,f2,f3]);
%disp_verbose(sprintf('ih = %d',ih)) %disp_verbose(sprintf('ih = %d',ih))
%eval(['xh=x' num2str(ih) ';']) %eval(['xh=x' num2str(ih) ';'])
...@@ -253,12 +253,10 @@ while ~done ...@@ -253,12 +253,10 @@ while ~done
%eval(['retcodeh=retcode' num2str(ih) ';']) %eval(['retcodeh=retcode' num2str(ih) ';'])
retcodei=[retcode1,retcode2,retcode3]; retcodei=[retcode1,retcode2,retcode3];
retcodeh=retcodei(ih); retcodeh=retcodei(ih);
if exist('gh')
nogh=isempty(gh); nogh=isempty(gh);
else badgh=1;
nogh=1; if nogh %recompute gradient
end
if nogh
if NumGrad if NumGrad
[gh, badgh]=get_num_grad(method,fcn,penalty,fh,xh,epsilon,varargin{:}); [gh, badgh]=get_num_grad(method,fcn,penalty,fh,xh,epsilon,varargin{:});
elseif grad_fun_provided elseif grad_fun_provided
...@@ -268,7 +266,6 @@ while ~done ...@@ -268,7 +266,6 @@ while ~done
badgh = ~cost_flag; badgh = ~cost_flag;
end end
end end
badgh=1;
end end
%end of picking %end of picking
stuck = (abs(fh-f) < crit); stuck = (abs(fh-f) < crit);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment