Fixed issues related to newratflag.
This options relates to alternative numerical hessian computations: optim=('Hessian',1) is the default dynare numeric Hessian optim=('Hessian',0) is the outer product gradient optim=('Hessian',2) is the 'mixed' outer product gradient, where diagonal elements using second order derivation formula, Both 0 and 2 cases require univariate filters, to ensure using maximum number of individual densities.time-shift
parent
87cb00bd7d
commit
c881cfff17
|
@ -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