Commit 3e5ec0ac authored by Marco Ratto's avatar Marco Ratto
Browse files

trap new robust features of optimizer=5 in robust option

parent ee679918
......@@ -290,6 +290,7 @@ switch minimizer_algorithm
nit=options_.newrat.maxiter;
epsilon = options_.gradient_epsilon;
crit_rel = NaN;
robust = false;
Verbose = options_.newrat.verbosity;
Save_files = options_.newrat.Save_files;
if ~isempty(options_.optim_opt)
......@@ -307,6 +308,8 @@ switch minimizer_algorithm
end
case 'NumgradEpsilon'
epsilon = options_list{i,2};
case 'robust'
robust = options_list{i,2};
case 'TolFun'
crit = options_list{i,2};
case 'TolFunRel'
......@@ -328,6 +331,7 @@ switch minimizer_algorithm
hess_info.gstep=options_.gstep;
hess_info.htol = 1.e-4;
hess_info.h1=epsilon*ones(n_params,1);
hess_info.robust=robust;
% here we force 7th input argument (flagg) to be 0, since outer product
% gradient Hessian is handled in dynare_estimation_1
[opt_par_values,hessian_mat,gg,fval,invhess,new_rat_hess_info] = newrat(objective_function,start_par_value,bounds,analytic_grad,crit,nit,0,Verbose,Save_files,hess_info,prior_information.p2,options_.gradient_epsilon,parameter_names,varargin{:}); %hessian_mat is the plain outer product gradient Hessian
......
function [f0, x, ig] = mr_gstep(h1,x,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon,parameter_names,varargin)
function [f0, x, ig] = mr_gstep(h1,x,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon,parameter_names,robust,varargin)
% [f0, x, ig] = mr_gstep(h1,x,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon,parameter_names,varargin)
%
% Gibbs type step in optimisation
......@@ -73,9 +73,13 @@ while i<n
hh(i) = 1/max(1.e-9,abs( (f1(i)+f_1(i)-2*f0)./(h1(i)*h1(i)) ));
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
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));
else
xa=transpose(linspace(x(i)/2, x(i)*3/2, 7));
end
for k=1:7
xh1(i)=xa(k);
fa(k,1) = penalty_objective_function(xh1,func0,penalty,varargin{:});
......@@ -94,6 +98,7 @@ while i<n
end
end
ig(i)=1;
if robust
if not(isequal(xx , check_bounds(xx,bounds)))
xx = check_bounds(xx,bounds);
if xx(i)<x(i)
......@@ -136,6 +141,11 @@ while i<n
f0=ff;
x=xx;
end
else
f0=ff;
x=xx;
x = check_bounds(x,bounds);
end
if Verbose
fprintf(['Done for param %s = %8.4f; f = %8.4f\n'],parameter_names{i},x(i),f0)
end
......
......@@ -186,7 +186,7 @@ while norm(gg)>gtol && check==0 && jit<nit
disp('last step exited with bad status!')
end
end
[fvala, x0, ig] = mr_gstep(h1,x0,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon, parameter_names,varargin{:});
[fvala, x0, ig] = mr_gstep(h1,x0,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon, parameter_names, hess_info.robust, varargin{:});
if not(isequal(x0 , check_bounds(x0,bounds)))
x0 = check_bounds(x0,bounds);
[fvala,exit_flag]=penalty_objective_function(x0,func0,penalty,varargin{:});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment