Hi all. I’m a little worried that this has already been said in the thread and I just missed it in my scrolling, and I see that some of the PosDef exceptions have been from repeated observations leading to true rank deficiencies. So this might not be a helpful comment. Sorry in advance if not.
But: for completeness of troubleshooting, it’s worth pointing out that the squared exponential kernel without any kind of diagonal perturbation is analytic on its entire domain, and so numerically it is incredibly brittle. As an example:
const pts = [randn(2) for _ in 1:1024]
const K = Symmetric([exp(-norm(x-y)^2) for x in pts, y in pts])
@show rank(K) # not 1024
cholesky!(K) # PosDefException
Not sure that that’s what’s going on here, but probably worth keeping in mind. For what it’s worth beyond that, at least in my field of environmental statistics, the squared exponential kernel (or any kernel that is analytic at the origin) yield sample paths with some pretty odd properties that aren’t particularly desirable. For example, observing such a process on an interval [-T, 0] with T > 0 enables perfect prediction of Z(t) for any t (Stein 1999, top pg. 121 or ex. 2.16). I won’t claim that there are no applications where that property is reasonable or desirable, but it certainly isn’t for anything I’ve ever done or probably will ever do.
In whatever code you use to generate covariance matrices, it might help to have an assert for no repeated measurements, which in pseudocode for my notation here might be
if iszero(diagonal_perturbation_parameter)
@assert length(unique(pts)) == length(pts) "Your covariance matrix is rank deficient"
end
or something. If that passes and you’re still having issues, you might consider switching to a kernel that is not analytic at the origin. A Matern class kernel with a convenient half-integer smoothness might be a reasonable drop-in, at the very least in debugging stages where you want to eliminate the possibility of very technical numerical concerns.