Log density fails to pass to the RWMH stage

Hi Johannes,

I encountered another issue after using your branch here https://git.dynare.org/Dynare/dynare/-/merge_requests/1762. When I run the nonlinear estimation, it seems that Dynare found the mode (with the Nelder-Mead method I set) but fails to pass that log density value to the next steps. Here’s the error message:

Final value of minus the log posterior (or likelihood):-1363.512977 

 (minus) the hessian matrix at the "mode" is not positive definite!
=> posterior variance of the estimated parameters are not positive.
You should try to change the initial values of the parameters using
the estimated_params_init block, or use another optimization routine.
Warning: The results below are most likely wrong! 
> In dynare_estimation_1 (line 315)
  In dynare_estimation (line 105)
  In rbc.driver (line 200)
  In dynare (line 293) 
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. 
> In dynare_estimation_1 (line 338)
  In dynare_estimation (line 105)
  In rbc.driver (line 200)
  In dynare (line 293) 

    prior mean     mode    s.d. prior pstdev

alpha   0.500   0.3900     NaN unif 0.1730 
beta    0.750   0.9893     NaN unif 0.1440 
delta   0.105   0.1246     NaN unif 0.0316 
rho     0.750   0.9078     NaN unif 0.3790 

Log data density [Laplace approximation] is NaN.

Error using chol
Matrix must be positive definite.

Error in posterior_sampler_initialization (line 84)
d = chol(vv);

Error in posterior_sampler (line 60)
    posterior_sampler_initialization(TargetFun, xparam1, vv,

Error in dynare_estimation_1 (line 465)

Error in dynare_estimation (line 105)

Error in rbc.driver (line 200)

Error in dynare (line 293)
evalin('base',[fname '.driver']) ;

It seems that the issue is still on the 2nd-order estimation, as the 1st-order one is running fine.
Attached here is the mod file and the data file for an MWE. I’m simply estimating an RBC model with some fake data I generated.Thanks!
fake_data_2.csv (8.4 KB)
rbc.mod (2.1 KB)

If you add mode_check -plots, you will see that the slice through the posterior for beta looks ugly. The problem seems to be that the standard Hessian cannot be easily computed as the likelihood is not differentiable. You should try using the mcmc_jumping_covariance-option, e.g. with identity_matrix