From 3fab9d5caa39e1ecd1d3b5ad21f6ad3b8ff89dc6 Mon Sep 17 00:00:00 2001
From: sebastien <sebastien@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Mon, 27 Oct 2008 11:46:18 +0000
Subject: [PATCH] 4.0: merged r2132 and parts of r2191 changesets (modified
 computation of log(det(invhess)) to solve cases in large models where
 det(invhess) is smaller than machine precision)

git-svn-id: https://www.dynare.org/svn/dynare/branches/4.0@2208 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 matlab/dynare_estimation.m | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m
index b0daf28fe8..c56b9308e4 100644
--- a/matlab/dynare_estimation.m
+++ b/matlab/dynare_estimation.m
@@ -619,11 +619,14 @@ if any(bayestopt_.pshape > 0) & options_.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_.bvar_dsge
-    md_Laplace = .5*size(xparam1,1)*log(2*pi) + .5*log(det(invhess)) ...
+    md_Laplace = .5*estim_params_nbr*log(2*pi) + .5*log_det_invhess ...
         - DsgeLikelihood(xparam1,gend,data);
   else
-    md_Laplace = .5*size(xparam1,1)*log(2*pi) + .5*log(det(invhess)) ...
+    md_Laplace = .5*estim_params_nbr*log(2*pi) + .5*log_det_invhess ...
         - DsgeVarLikelihood(xparam1,gend);
   end
   oo_.MarginalDensity.LaplaceApproximation = md_Laplace;    
-- 
GitLab