I’m trying to construct an mcmc sampler for a HMM model which has a Bayesian Linear Regression component. However, as the mcmc iteration progresses, i quickly run into PosDefException errors when trying to simulate a multivariate normal or inverse wishart. Example of error:
ERROR: PosDefException: matrix is not positive definite; Cholesky factorization failed.
Checks on my some of the matrices causing the error reveal that with each update, the values of the matrices get larger and larger, in what i think leads to increasing error in numerical precision. Hence, the minimum eigenvalues of the matrices also increases, up to the point that the tolerance is no longer acceptable for generating multivariate normal or inverse wishart random variables.
Any idea how I can circumvent this problem? for example by perturbing the matrices such that it is still representative enough and also within tolerance. Another possibility is that there is a bug in my algorithm leading to the big numbers and consequential loss of precision, but I wonder if there is a way to deal with the PosDefException
issue as other bugs in the code are not apparent to me now.