diff --git a/matlab/default_option_values.m b/matlab/default_option_values.m index 87721dfad92746c7510ff5fd99aa0f1052c75701..2ca5507d4eaf41c5ceae3f0c1e607014d36ff0b5 100644 --- a/matlab/default_option_values.m +++ b/matlab/default_option_values.m @@ -564,7 +564,7 @@ options_.csminwel=csminwel; %newrat optimization routine newrat.hess=1; % dynare numerical hessian -newrat.robust=0; +newrat.robust=false; newrat.tolerance.f=1e-5; newrat.tolerance.f_analytic=1e-7; newrat.tolerance.gstep = NaN; diff --git a/matlab/optimization/mr_gstep.m b/matlab/optimization/mr_gstep.m index 02ff7ac5299c739726a0532a7e55ff471d7ebe7d..a119dee3907d7f0de484cfe690692556885e6b77 100644 --- a/matlab/optimization/mr_gstep.m +++ b/matlab/optimization/mr_gstep.m @@ -75,11 +75,11 @@ while i<n if gg(i)*(hh(i)*gg(i))/2 > htol(i) [ff, xx,fcount,retcode] = csminit1(func0,x,penalty,f0,gg,0,diag(hh),Verbose,varargin{:}); if retcode && robust -% do_nothing=true; + if abs(x(i))<1.e-6 - xa=transpose(linspace(x(i)/2, sign(x(i))*1.e-6*3/2, 7)); + xa=transpose(linspace(x(i)/2, sign(x(i))*1.e-6*3/2, 7)); else - xa=transpose(linspace(x(i)/2, x(i)*3/2, 7)); + xa=transpose(linspace(x(i)/2, x(i)*3/2, 7)); end for k=1:7 xh1(i)=xa(k); @@ -100,48 +100,48 @@ while i<n end ig(i)=1; if robust - if not(isequal(xx , check_bounds(xx,bounds))) - xx = check_bounds(xx,bounds); - if xx(i)<x(i) - % lower bound - xx(i) = min(xx(i)+h1(i), 0.5*(xx(i)+x(i))); + if not(isequal(xx , check_bounds(xx,bounds))) + xx = check_bounds(xx,bounds); + if xx(i)<x(i) + % lower bound + xx(i) = min(xx(i)+h1(i), 0.5*(xx(i)+x(i))); + else + % upper bound + xx(i) = max(xx(i)-h1(i), 0.5*(xx(i)+x(i))); + end + [ff,exit_flag]=penalty_objective_function(xx,func0,penalty,varargin{:}); + if exit_flag~=1 + disp('last step exited with bad status!') + elseif ff<f0 + f0=ff; + x=xx; + end else - % upper bound - xx(i) = max(xx(i)-h1(i), 0.5*(xx(i)+x(i))); - end - [ff,exit_flag]=penalty_objective_function(xx,func0,penalty,varargin{:}); - if exit_flag~=1 - disp('last step exited with bad status!') - elseif ff<f0 - f0=ff; - x=xx; - end - else - % check improvement wrt predicted one - if abs(f0-ff) < abs(gg(i)*(hh(i)*gg(i))/2/100) || abs(x(i)-xx(i))<1.e-10 - [ff1, xx1, fcount, retcode] = csminit1(func0,x,penalty,f0,-gg,0,diag(hh),Verbose,varargin{:}); - if not(isequal(xx1 , check_bounds(xx1,bounds))) - xx1 = check_bounds(xx1,bounds); - if xx1(i)<x(i) - % lower bound - xx1(i) = min(xx1(i)+h1(i), 0.5*(xx1(i)+x(i))); - else - % upper bound - xx1(i) = max(xx1(i)-h1(i), 0.5*(xx1(i)+x(i))); + % check improvement wrt predicted one + if abs(f0-ff) < abs(gg(i)*(hh(i)*gg(i))/2/100) || abs(x(i)-xx(i))<1.e-10 + [ff1, xx1, fcount, retcode] = csminit1(func0,x,penalty,f0,-gg,0,diag(hh),Verbose,varargin{:}); + if not(isequal(xx1 , check_bounds(xx1,bounds))) + xx1 = check_bounds(xx1,bounds); + if xx1(i)<x(i) + % lower bound + xx1(i) = min(xx1(i)+h1(i), 0.5*(xx1(i)+x(i))); + else + % upper bound + xx1(i) = max(xx1(i)-h1(i), 0.5*(xx1(i)+x(i))); + end + [ff1,exit_flag]=penalty_objective_function(xx1,func0,penalty,varargin{:}); + if exit_flag~=1 + disp('last step exited with bad status!') + end end - [ff1,exit_flag]=penalty_objective_function(xx1,func0,penalty,varargin{:}); - if exit_flag~=1 - disp('last step exited with bad status!') + if ff1<ff + ff=ff1; + xx=xx1; end end - if ff1<ff - ff=ff1; - xx=xx1; - end + f0=ff; + x=xx; end - f0=ff; - x=xx; - end else f0=ff; x=xx;