Estimation with mode_compute = 6: "Error: matrix must be positive definite"


I am running an estimation using Occbin and mode_compute = 6. Depending on the exact setup of the problem, I occasionally run into a hard error:

Error using chol
Matrix must be positive definite.

Error in gmhmaxlik_core (line 194)
    dd = transpose(chol(CovJump));

Error in gmhmaxlik (line 100)
    [PostMode, PostVariance, Scale, PostMean] = gmhmaxlik_core(fun, OldPostMode, bounds, gmhmaxlikOptions, Scale, flag, MeanPar, OldPostVariance, varargin{:});

That is, the minimiser makes it all the way to the “last call”, and then fails due to the jumping matrix not being positive definite. Presumably, however, the matrix must have been positive definite while tuning the scale parameter and so on, so this seemed an unusual moment for an error.

It might be that this is the intended behaviour, but if so could I suggest adding some minimal error handling and a user-friendly error message (like the error messages when the initial likelihood is NaN)?

I have never encountered this before. Do you have a code to replicate the problem?

I do, but the runtime is extensive (~36 hours), at least on my computer. Happy to provide it if that’s reasonable for you, but I appreciate you obviously have other committments as well. An alternative is that I could run the process again with a Matlab breakpoint inserted just before the crash, and then save all the internals (M_, oo, and so on) so you don’t need to start the process from scratch, if that would be more helpful.

  1. Yes, setting a breakpoint and saving the workspace would help.
  2. What was the command window output of the first iterations? The error should only happen if the parameter vector does not move at all.