Avoiding MCMC failure with non positive definite Hessian

Hi everyone,

I really like the way Dynare implements MCMC estimation — many thanks to the Dynare team for all your efforts! — but there’s one situation that it doesn’t handle that well. During model development, it’s not unusual to have an estimated Hessian at the mode that’s not positive definite. One parameter might be dodgy, or it might be hard to find the mode, or there may be scaling problems between different parameters, etc. In those cases, Dynare prints a warning but then causes a Matlab error on line 68 of metropolis_hastings_initialization.m, on the line d = chol(vv);

Sometimes you may want to run Metropolis Hastings anyway for a while, because that often helps to find the real mode and/or to identify which parameters are causing a problem. Here’s the code I use to do that. If you like, you can drop it in as a replacement for line 68 of metropolis_hastings_initialization.m.

 d, notPosDef ] = chol(vv);
if notPosDef
    disp('Warning: using diagonal proposal covariance.');
    diagv = diag(vv);
    diagv(diagv < 0) = 1e-5;
    d = diag(sqrt(diagv));