Added new tool. When using the instruction get_prior_info(2) in the mod file (after the
definition of the priors) Dynare tries to compute the prior mode using Chris Sims' optimization routine. git-svn-id: https://www.dynare.org/svn/dynare/trunk@2724 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
7691c17b15
commit
a9d7088ced
|
@ -92,8 +92,8 @@ function get_prior_info(info)
|
|||
end
|
||||
|
||||
M_.dname = M_.fname;
|
||||
|
||||
if info% Prior simulations.
|
||||
|
||||
if info==1% Prior simulations.
|
||||
results = prior_sampler(0,M_,bayestopt_,options_,oo_);
|
||||
disp(['Prior mass = ' num2str(results.prior.mass)])
|
||||
disp(['BK indeterminacy share = ' num2str(results.bk.indeterminacy_share)])
|
||||
|
@ -106,7 +106,52 @@ function get_prior_info(info)
|
|||
disp(['Analytical steady state problem share = ' num2str(results.ass.problem_share)])
|
||||
end
|
||||
|
||||
|
||||
if info==2% Prior optimization.
|
||||
|
||||
k = find(~isnan(bayestopt_.p5));
|
||||
xparam1(k) = bayestopt_.p5(k);
|
||||
|
||||
look_for_admissible_initial_condition = 1;
|
||||
scale = 1.0;
|
||||
iter = 0;
|
||||
|
||||
while look_for_admissible_initial_condition
|
||||
xinit = xparam1+scale*randn(size(xparam1));
|
||||
if all(xinit>bayestopt_.p3) && all(xinit<bayestopt_.p4)
|
||||
look_for_admissible_initial_condition = 0;
|
||||
else
|
||||
if iter == 2000;
|
||||
scale = scale/1.1;
|
||||
iter = 0;
|
||||
else
|
||||
iter = iter+1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[xparams,lpd,hessian] = ...
|
||||
maximize_prior_density(xinit, bayestopt_.pshape, ...
|
||||
bayestopt_.p6, ...
|
||||
bayestopt_.p7, ...
|
||||
bayestopt_.p3, ...
|
||||
bayestopt_.p4);
|
||||
disp(' ')
|
||||
disp(' ')
|
||||
disp('------------------')
|
||||
disp('PRIOR OPTIMIZATION')
|
||||
disp('------------------')
|
||||
disp(' ')
|
||||
|
||||
|
||||
|
||||
for i = 1:length(xparams)
|
||||
disp(['deep parameter ' int2str(i) ': ' get_the_name(i,0) '.'])
|
||||
disp([' Initial condition ....... ' num2str(xinit(i)) '.'])
|
||||
disp([' Prior mode .............. ' num2str(bayestopt_.p5(i)) '.'])
|
||||
disp([' Optimized prior mode .... ' num2str(xparams(i)) '.'])
|
||||
disp(' ')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
function [xparams,lpd,hessian] = ...
|
||||
maximize_prior_density(iparams, prior_shape, prior_hyperparameter_1, prior_hyperparameter_2, prior_inf_bound, prior_sup_bound)
|
||||
% Maximizes the logged prior density using Chris Sims' optimization routine.
|
||||
%
|
||||
% INPUTS
|
||||
% iparams [double] vector of initial parameters.
|
||||
% prior_shape [integer] vector specifying prior densities shapes.
|
||||
% prior_hyperparameter_1 [double] vector, first hyperparameter.
|
||||
% prior_hyperparameter_2 [double] vector, second hyperparameter.
|
||||
% prior_inf_bound [double] vector, prior's lower bound.
|
||||
% prior_sup_bound [double] vector, prior's upper bound.
|
||||
%
|
||||
% OUTPUTS
|
||||
% xparams [double] vector, prior mode.
|
||||
% lpd [double] scalar, value of the logged prior density at the mode.
|
||||
% hessian [double] matrix, Hessian matrix at the prior mode.
|
||||
|
||||
% Copyright (C) 2009 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
number_of_estimated_parameters = length(iparams);
|
||||
H0 = 1e-4*eye(number_of_estimated_parameters);
|
||||
crit = 1e-7;
|
||||
nit = 1000;
|
||||
verbose = 2;
|
||||
gradient_method = 2;
|
||||
|
||||
[lpd,xparams,grad,hessian,itct,fcount,retcodehat] = ...
|
||||
csminwel('minus_logged_prior_density',iparams,H0,[],crit,nit,gradient_method, ...
|
||||
prior_shape, prior_hyperparameter_1, prior_hyperparameter_2, prior_inf_bound, prior_sup_bound);
|
||||
|
||||
lpd = -lpd;
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
function [f,fake] = minus_logged_prior_density(xparams,pshape,p6,p7,p3,p4)
|
||||
% Evaluates minus the logged prior density.
|
||||
%
|
||||
% INPUTS
|
||||
% xparams [double] vector of parameters.
|
||||
% pshape [integer] vector specifying prior densities shapes.
|
||||
% p6 [double] vector, first hyperparameter.
|
||||
% p7 [double] vector, second hyperparameter.
|
||||
% p3 [double] vector, prior's lower bound.
|
||||
% p4 [double] vector, prior's upper bound.
|
||||
%
|
||||
% OUTPUTS
|
||||
% f [double] value of minus the logged prior density.
|
||||
|
||||
% Copyright (C) 2009 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
fake = 1;
|
||||
f = - priordens(xparams,pshape,p6,p7,p3,p4);
|
Loading…
Reference in New Issue