marginal_density.m: make computation of log(det(sigma)) robust numerically

mr#2067
Marco Ratto 2022-01-25 10:27:47 +01:00 committed by Johannes Pfeifer
parent 48ec0a60e8
commit 61632ef28f
1 changed files with 8 additions and 1 deletions

View File

@ -69,7 +69,14 @@ parameter_names = bayestopt_.name;
save([M_.dname filesep 'Output' filesep M_.fname '_mean.mat'],'xparam1','hh','parameter_names','SIGMA');
fprintf('Estimation::marginal density: I''m computing the posterior log marginal density (modified harmonic mean)... ');
logdetSIGMA = log(det(SIGMA));
try
% use this robust option to avoid inf/nan
logdetSIGMA = 2*sum(log(diag(chol(SIGMA))));
catch
% in case SIGMA is not positive definite
logdetSIGMA = nan;
fprintf('Estimation::marginal density: the covariance of MCMC draws is not positive definite. You may have too few MCMC draws.');
end
invSIGMA = hh;
marginal = zeros(9,2);
linee = 0;