newrat: distinguish between TolFun (optimizer termination criterion) and TolGstep/TolGstepRel, used for tuning gradient step

Allows using e.g. TolFun=1.e-5 with coarser values for TolGstep; helpful whenmaximizing non smooth surfaces (e.g. PKF or very large models), where numerical noise may count. By default TolGstep=TolFun as in usual historical behavior.
covariance-quadratic-approximation
Marco Ratto 2023-02-14 17:22:59 +01:00 committed by Johannes Pfeifer
parent d25d95b3b5
commit 3ee963c908
4 changed files with 23 additions and 4 deletions

View File

@ -562,6 +562,8 @@ options_.csminwel=csminwel;
%newrat optimization routine
newrat.hess=1; % dynare numerical hessian
newrat.robust=false;
newrat.tolerance.gstep = NaN;
newrat.tolerance.gstep_rel = NaN;
newrat.tolerance.f=1e-5;
newrat.tolerance.f_analytic=1e-7;
newrat.maxiter=1000;

View File

@ -289,6 +289,8 @@ switch minimizer_algorithm
end
nit=options_.newrat.maxiter;
robust = options_.newrat.robust;
gstep_crit = options_.newrat.tolerance.gstep;
gstep_crit_rel = options_.newrat.tolerance.gstep_rel;
Verbose = options_.newrat.verbosity;
Save_files = options_.newrat.Save_files;
if ~isempty(options_.optim_opt)
@ -308,6 +310,10 @@ switch minimizer_algorithm
robust = options_list{i,2};
case 'TolFun'
crit = options_list{i,2};
case 'TolGstep'
gstep_crit = options_list{i,2};
case 'TolGstepRel'
gstep_crit_rel = options_list{i,2};
case 'verbosity'
Verbose = options_list{i,2};
case 'SaveFiles'
@ -321,8 +327,12 @@ switch minimizer_algorithm
Save_files = 0;
Verbose = 0;
end
if isnan(gstep_crit)
gstep_crit = crit;
end
hess_info.gstep=options_.gstep;
hess_info.htol = 1.e-4;
hess_info.htol = gstep_crit;
hess_info.htol_rel = gstep_crit_rel;
hess_info.h1=options_.gradient_epsilon*ones(n_params,1);
hess_info.robust=robust;
% here we force 7th input argument (flagg) to be 0, since outer product

View File

@ -83,6 +83,11 @@ hess_info.h1 = min(hess_info.h1,0.9.*hmax);
if htol0<hess_info.htol
hess_info.htol=htol0;
end
if not(isnan(hess_info.htol_rel))
htol1=hess_info.htol;
hess_info.htol=abs(hess_info.htol_rel*f0);
end
xh1=x;
f1=zeros(size(f0,1),n);
f_1=f1;
@ -298,4 +303,6 @@ else
hh1 = [];
end
htol1=hhtol;
if isnan(hess_info.htol_rel)
htol1=hhtol;
end

View File

@ -69,7 +69,7 @@ icount=0;
nx=length(x);
xparam1=x;
%ftol0=1.e-6;
htol_base = max(1.e-7, ftol0);
htol_base = max(1.e-7, hess_info.htol);
flagit=0; % mode of computation of hessian in each iteration; hard-coded outer-product of gradients as it performed best in tests
ftol=ftol0;
gtol=1.e-3;
@ -232,7 +232,7 @@ while norm(gg)>gtol && check==0 && jit<nit
if flagit==2
hh=hh0;
elseif flagg>0
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagg,ftol0,hess_info,bounds,prior_std,Save_files,varargin{:});
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagg,htol_base,hess_info,bounds,prior_std,Save_files,varargin{:});
if flagg==2
hh = reshape(dum,nx,nx);
ee=eig(hh);