I am not sure if this is a programming or statistics question, but I am %99 sure that there should be a numerical problem. So maybe a programmatic solution can be proposed.
I am using MATLAB’s mvnpdf function to calculate multi-variate Gaussian PDF of some observations. Frequently I get “SIGMA must be symmetric and positive definite” errors.
However, I am obtaining the covarince matrix from the data, so the data should be legal. A code to regenerate the problem is:
err_cnt = 0;
for i = 1:1000
try
a = rand(3);
c = cov(a);
m = mean(a);
mvnpdf(a, m, c);
catch me
err_cnt = err_cnt + 1;
end
end
I get ~500-600 errors each time I run.
P.S. I do not generate random data in my case, just generated here to demonstrate.
This happens if the diagonal values of the covariance matrix are (very close to) zero. A simple fix is add a very small constant number to
c.Results in 0 errors.