Commit 6b592cbb authored by Johannes Pfeifer 's avatar Johannes Pfeifer

newrat: Further replacement of varargins by explicit options

parent dc6e3406
......@@ -268,7 +268,7 @@ switch minimizer_algorithm
hess_info.gstep=options_.gstep;
hess_info.htol = 1.e-4;
hess_info.h1=options_.gradient_epsilon*ones(n_params,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,varargin{:}); %hessian_mat is the plain outer product gradient Hessian
[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
case 6
if isempty(prior_information) %Inf will be reset
prior_information.p2=Inf(n_params,1);
......
function [f0, x, ig] = mr_gstep(h1,x,bounds,func0,penalty,htol0,Verbose,Save_files,varargin)
% [f0, x, ig] = mr_gstep(h1,x,bounds,func0,penalty,htol0,Verbose,Save_files,varargin)
function [f0, x, ig] = mr_gstep(h1,x,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon,parameter_names,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
%
......@@ -11,7 +11,7 @@ function [f0, x, ig] = mr_gstep(h1,x,bounds,func0,penalty,htol0,Verbose,Save_fil
% varargin{6} --> BayesInfo
% varargin{1} --> DynareResults
% Copyright (C) 2006-2017 Dynare Team
% Copyright (C) 2006-2020 Dynare Team
%
% This file is part of Dynare.
%
......@@ -30,7 +30,7 @@ function [f0, x, ig] = mr_gstep(h1,x,bounds,func0,penalty,htol0,Verbose,Save_fil
n=size(x,1);
if isempty(h1)
h1=varargin{3}.gradient_epsilon*ones(n,1);
h1=gradient_epsilon*ones(n,1);
end
......@@ -72,10 +72,10 @@ while i<n
gg(i)=(f1(i)'-f_1(i)')./(2.*h1(i));
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)
[f0, x, fc, retcode] = csminit1(func0,x,penalty,f0,gg,0,diag(hh),Verbose,varargin{:});
[f0, x, ~, ~] = csminit1(func0,x,penalty,f0,gg,0,diag(hh),Verbose,varargin{:});
ig(i)=1;
if Verbose
fprintf(['Done for param %s = %8.4f\n'],varargin{6}.name{i},x(i))
fprintf(['Done for param %s = %8.4f\n'],parameter_names{i},x(i))
end
end
xh1=x;
......
function [xparam1, hh, gg, fval, igg, hess_info] = newrat(func0, x, bounds, analytic_derivation, ftol0, nit, flagg, Verbose, Save_files, hess_info, prior_std, varargin)
% [xparam1, hh, gg, fval, igg, hess_info] = newrat(func0, x, bounds, analytic_derivation, ftol0, nit, flagg, Verbose, Save_files, hess_info, varargin)
function [xparam1, hh, gg, fval, igg, hess_info] = newrat(func0, x, bounds, analytic_derivation, ftol0, nit, flagg, Verbose, Save_files, hess_info, prior_std, gradient_epsilon, parameter_names, varargin)
% [xparam1, hh, gg, fval, igg, hess_info] = newrat(func0, x, bounds, analytic_derivation, ftol0, nit, flagg, Verbose, Save_files, hess_info, gradient_epsilon, parameter_names, varargin)
%
% Optimiser with outer product gradient and with sequences of univariate steps
% uses Chris Sims subroutine for line search
......@@ -24,6 +24,8 @@ function [xparam1, hh, gg, fval, igg, hess_info] = newrat(func0, x, bounds, anal
% computation of Hessian
% - prior_std prior standard devation of parameters (can be NaN);
% passed to mr_hessian
% - gradient_epsilon [double] step size in gradient
% - parameter_names [cell] names of parameters for error messages
% - varargin other inputs
% e.g. in dsge_likelihood and others:
% varargin{1} --> DynareDataset
......@@ -167,7 +169,7 @@ while norm(gg)>gtol && check==0 && jit<nit
[fvala,x0,fc,retcode] = csminit1(func0,x0,penalty,fval,ggx,0,iggx,Verbose,varargin{:});
end
x0 = check_bounds(x0,bounds);
[fvala, x0, ig] = mr_gstep(h1,x0,bounds,func0,penalty,htol0,Verbose,Save_files,varargin{:});
[fvala, x0, ig] = mr_gstep(h1,x0,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon, parameter_names,varargin{:});
x0 = check_bounds(x0,bounds);
nig=[nig ig];
disp_verbose('Sequence of univariate steps!!',Verbose)
......
Markdown is supported
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