From cfa7a923fa149fe4186a1f5e3c3e78c9e8112efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Sedna=29?= <stephane.adjemian@univ-lemans.fr> Date: Fri, 13 May 2011 14:55:10 +0200 Subject: [PATCH] Do not compute marginal density (Laplace approximation) if options_.cova_compute==1. (cherry picked from commit ea103ecb846be993fc543fae9b793f586521a370) --- matlab/dynare_estimation_1.m | 40 +++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 9f0e890bf7..cafff9ef3d 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -563,20 +563,22 @@ if any(bayestopt_.pshape > 0) && ~options_.mh_posterior_mode_estimation end end %% Laplace approximation to the marginal log density: - estim_params_nbr = size(xparam1,1); - scale_factor = -sum(log10(diag(invhess))); - log_det_invhess = -estim_params_nbr*log(scale_factor)+log(det(scale_factor*invhess)); - if ~options_.dsge_var - md_Laplace = .5*estim_params_nbr*log(2*pi) + .5*log_det_invhess ... - - DsgeLikelihood(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations); - else - md_Laplace = .5*estim_params_nbr*log(2*pi) + .5*log_det_invhess ... - - DsgeVarLikelihood(xparam1,gend); + if options_.cova_compute + estim_params_nbr = size(xparam1,1); + scale_factor = -sum(log10(diag(invhess))); + log_det_invhess = -estim_params_nbr*log(scale_factor)+log(det(scale_factor*invhess)); + if ~options_.dsge_var + md_Laplace = .5*estim_params_nbr*log(2*pi) + .5*log_det_invhess ... + - DsgeLikelihood(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations); + else + md_Laplace = .5*estim_params_nbr*log(2*pi) + .5*log_det_invhess ... + - DsgeVarLikelihood(xparam1,gend); + end + oo_.MarginalDensity.LaplaceApproximation = md_Laplace; + disp(' ') + disp(sprintf('Log data density [Laplace approximation] is %f.',md_Laplace)) + disp(' ') end - oo_.MarginalDensity.LaplaceApproximation = md_Laplace; - disp(' ') - disp(sprintf('Log data density [Laplace approximation] is %f.',md_Laplace)) - disp(' ') elseif ~any(bayestopt_.pshape > 0) && options_.mh_posterior_mode_estimation disp(' ') disp('RESULTS FROM MAXIMUM LIKELIHOOD') @@ -862,11 +864,15 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ... if options_.load_mh_file && options_.use_mh_covariance_matrix invhess = compute_mh_covariance_matrix; end - if options_.dsge_var - feval(options_.posterior_sampling_method,'DsgeVarLikelihood',options_.proposal_distribution,xparam1,invhess,bounds,gend); + if options_.cova_compute + if options_.dsge_var + feval(options_.posterior_sampling_method,'DsgeVarLikelihood',options_.proposal_distribution,xparam1,invhess,bounds,gend); + else + feval(options_.posterior_sampling_method,'DsgeLikelihood',options_.proposal_distribution,xparam1,invhess,bounds,gend,data,... + data_index,number_of_observations,no_more_missing_observations); + end else - feval(options_.posterior_sampling_method,'DsgeLikelihood',options_.proposal_distribution,xparam1,invhess,bounds,gend,data,... - data_index,number_of_observations,no_more_missing_observations); + error('I Cannot start the MCMC because the hessian of the posterior kernel at the mode was not computed.') end end if options_.mh_posterior_mode_estimation -- GitLab