Merge pull request #856 from rattoma/optimizer_number_5
Fixed issues related to newratflag.time-shift
commit
28f2e2abd0
|
@ -4864,7 +4864,9 @@ Uses Chris Sims's @code{csminwel}
|
||||||
|
|
||||||
@item 5
|
@item 5
|
||||||
Uses Marco Ratto's @code{newrat}. This value is not compatible with non
|
Uses Marco Ratto's @code{newrat}. This value is not compatible with non
|
||||||
linear filters or DSGE-VAR models
|
linear filters or DSGE-VAR models.
|
||||||
|
This is a slice optimizer: most iterations are a sequence of univariate optimization step, one for each estimated parameter or shock.
|
||||||
|
Uses @code{csminwel} for line search in each step.
|
||||||
|
|
||||||
@item 6
|
@item 6
|
||||||
Uses a Monte-Carlo based optimization routine (see
|
Uses a Monte-Carlo based optimization routine (see
|
||||||
|
@ -4983,6 +4985,25 @@ Initial approximation for the inverse of the Hessian matrix of the posterior ker
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
@item 5
|
||||||
|
Available options are:
|
||||||
|
|
||||||
|
@table @code
|
||||||
|
|
||||||
|
@item 'MaxIter'
|
||||||
|
Maximum number of iterations. Default: @code{1000}
|
||||||
|
|
||||||
|
@item 'Hessian'
|
||||||
|
Triggers three types of Hessian computations. @code{0}: outer product gradient; @code{1} default DYNARE Hessian routine; @code{2} 'mixed' outer product gradient, where diagonal elements are obtained using second order derivation formula and outer product is used for correlation structure.
|
||||||
|
Both @{0} and @{2} options require univariate filters, to ensure using maximum number of individual densities and a positive definite Hessian.
|
||||||
|
Both @{0} and @{2} are quicker than default DYNARE numeric Hessian, but provide decent starting values for Metropolis for large models (option @{2} being more accurate than @{0}).
|
||||||
|
Default: @code{1}.
|
||||||
|
|
||||||
|
@item 'TolFun'
|
||||||
|
Stopping criteria. Default: @code{1e-5} for numerical derivatives @code{1e-7} for analytic derivatives.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
|
||||||
@item 6
|
@item 6
|
||||||
Available options are:
|
Available options are:
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ end
|
||||||
if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
|
if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
|
||||||
%prepare settings for newrat
|
%prepare settings for newrat
|
||||||
if options_.mode_compute==5
|
if options_.mode_compute==5
|
||||||
%get whether analytical Hessian with non-analytical mode-finding is requested
|
%get whether outer product Hessian is requested
|
||||||
newratflag=[];
|
newratflag=[];
|
||||||
if ~isempty(options_.optim_opt)
|
if ~isempty(options_.optim_opt)
|
||||||
options_list = read_key_value_string(options_.optim_opt);
|
options_list = read_key_value_string(options_.optim_opt);
|
||||||
|
@ -246,19 +246,14 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
|
||||||
if options_.analytic_derivation,
|
if options_.analytic_derivation,
|
||||||
options_analytic_derivation_old = options_.analytic_derivation;
|
options_analytic_derivation_old = options_.analytic_derivation;
|
||||||
options_.analytic_derivation = -1;
|
options_.analytic_derivation = -1;
|
||||||
if ~isempty(newratflag) && newratflag~=0 %gradient explicitly specified
|
if ~isempty(newratflag) && newratflag~=0 %numerical hessian explicitly specified
|
||||||
error('newrat: analytic_derivation is incompatible with numerical Hessian.')
|
error('newrat: analytic_derivation is incompatible with numerical Hessian.')
|
||||||
else %use default
|
else %use default
|
||||||
newratflag=0; %use analytical gradient
|
newratflag=0; %exclude DYNARE numerical hessian
|
||||||
end
|
end
|
||||||
elseif ~options_.analytic_derivation
|
elseif ~options_.analytic_derivation
|
||||||
if isempty(newratflag)
|
if isempty(newratflag)
|
||||||
newratflag=options_.newrat.hess; %use default gradient
|
newratflag=options_.newrat.hess; %use default numerical dynare hessian
|
||||||
end
|
|
||||||
if newratflag==0 %Analytic Hessian wanted, but not automatically computed by newrat itself
|
|
||||||
if ~((options_.kalman_algo == 2) || (options_.kalman_algo == 4)) %kalman_algo not compatible
|
|
||||||
error('Analytical Hessian with non-analytical mode-finding requires kalman_algo=2 or 4.')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -281,11 +276,39 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
|
||||||
[junk1, junk2, hh] = feval(objective_function,xparam1, ...
|
[junk1, junk2, hh] = feval(objective_function,xparam1, ...
|
||||||
dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
|
dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
|
||||||
options_.analytic_derivation = ana_deriv_old;
|
options_.analytic_derivation = ana_deriv_old;
|
||||||
elseif ~(isequal(options_.mode_compute,5) && newratflag==0),
|
elseif ~(isequal(options_.mode_compute,5) && newratflag~=1),
|
||||||
% with flag==0, we force to use the hessian from outer
|
% with flag==0, we force to use the hessian from outer
|
||||||
% product gradient of optimizer 5
|
% product gradient of optimizer 5
|
||||||
hh = reshape(hessian(objective_function,xparam1, ...
|
hh = reshape(hessian(objective_function,xparam1, ...
|
||||||
options_.gstep,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_),nx,nx);
|
options_.gstep,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_),nx,nx);
|
||||||
|
elseif isequal(options_.mode_compute,5)
|
||||||
|
% other numerical hessian options available with optimizer 5
|
||||||
|
%
|
||||||
|
% if newratflag == 0
|
||||||
|
% compute outer product gradient of optimizer 5
|
||||||
|
%
|
||||||
|
% if newratflag == 2
|
||||||
|
% compute 'mixed' outer product gradient of optimizer 5
|
||||||
|
% with diagonal elements computed with numerical second order derivatives
|
||||||
|
%
|
||||||
|
% uses univariate filters, so to get max # of available
|
||||||
|
% densitities for outer product gradient
|
||||||
|
kalman_algo0 = options_.kalman_algo;
|
||||||
|
compute_hessian = 1;
|
||||||
|
if ~((options_.kalman_algo == 2) || (options_.kalman_algo == 4)),
|
||||||
|
options_.kalman_algo=2;
|
||||||
|
if options_.lik_init == 3,
|
||||||
|
options_.kalman_algo=4;
|
||||||
|
end
|
||||||
|
elseif newratflag==0, % hh already contains outer product gradient with univariate filter
|
||||||
|
compute_hessian = 0;
|
||||||
|
end
|
||||||
|
if compute_hessian,
|
||||||
|
crit = options_.newrat.tolerance.f;
|
||||||
|
newratflag = newratflag>0;
|
||||||
|
hh = reshape(mr_hessian(0,xparam1,objective_function,newratflag,crit,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_), nx, nx);
|
||||||
|
end
|
||||||
|
options_.kalman_algo = kalman_algo0;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -481,7 +481,7 @@ csminwel.maxiter=1000;
|
||||||
options_.csminwel=csminwel;
|
options_.csminwel=csminwel;
|
||||||
|
|
||||||
%newrat optimization routine
|
%newrat optimization routine
|
||||||
newrat.hess=1; %analytic hessian
|
newrat.hess=1; % dynare numerical hessian
|
||||||
newrat.tolerance.f=1e-5;
|
newrat.tolerance.f=1e-5;
|
||||||
newrat.tolerance.f_analytic=1e-7;
|
newrat.tolerance.f_analytic=1e-7;
|
||||||
newrat.maxiter=1000;
|
newrat.maxiter=1000;
|
||||||
|
|
|
@ -177,10 +177,9 @@ switch minimizer_algorithm
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
[opt_par_values,hessian_mat,gg,fval,invhess] = newrat(objective_function,start_par_value,analytic_grad,crit,nit,0,varargin{:});
|
[opt_par_values,hessian_mat,gg,fval,invhess] = newrat(objective_function,start_par_value,analytic_grad,crit,nit,0,varargin{:});
|
||||||
|
%hessian_mat is the plain outer product gradient Hessian
|
||||||
if options_.analytic_derivation %Hessian is already analytic one, reset option
|
if options_.analytic_derivation %Hessian is already analytic one, reset option
|
||||||
options_.analytic_derivation = ana_deriv;
|
options_.analytic_derivation = ana_deriv;
|
||||||
elseif ~options_.analytic_derivation && newratflag ==0 %Analytic Hessian wanted, but not computed yet
|
|
||||||
hessian_mat = reshape(mr_hessian(0,opt_par_values,objective_function,1,crit,varargin{:}), n_params, n_params);
|
|
||||||
end
|
end
|
||||||
case 6
|
case 6
|
||||||
[opt_par_values, hessian_mat, Scale, fval] = gmhmaxlik(objective_function, start_par_value, ...
|
[opt_par_values, hessian_mat, Scale, fval] = gmhmaxlik(objective_function, start_par_value, ...
|
||||||
|
|
Loading…
Reference in New Issue