Hello,
I am computing the eigenvectors of some large data with something like this:
XN is a matrix of size m x n containing some normalized data per row, where n is much larger than m. I would not like to use svd directly, but rather try an approach that computes the eigenvalues of just the m dimensions, as below:
[UU, S, ~] = svd((1/nr_groups) * (XN * XN'));
SIQ = pinv(sqrt(S));
U = (1/sqrt(nr_groups)) * (XN' * UU) * SIQ;
W = U(:,1:K); end
Then I compute the covariance of some data: xsigma = cov(data);
and then I project this covariance using the projection matrix W computed above:
psigma = W' * xsigma * W;
Then I want to use this psigma, along with some mean data with mvnpdf. This generally works fine but on some occasion I got this error:
Error using mvnpdf SIGMA must be a square, symmetric, positive definite matrix.
Basically for some value of psigma if I do the following:
mvnpdf(data, miu, psigma)
I get an error.
But if I copy the upper part into the lower part with something like this:
ts = triu(psigma) + triu(psigma, 1)';
and then use it:
mvnpdf(data, miu, ts)
I don't get the error anymore.
It sounds like a numerical problem, but doing the triu trick seems a bit odd to me.
Also, here is the problematic covariance matrix:
1.0e-03 *
0.031810217117700 0.002944646130627 0.062672109562341 0.027222257033394
0.002944646130627 0.006499918688582 0.009385092678967 0.003494166116038
0.062672109562340 0.009385092678967 0.153523119650464 0.066650626341073
0.027222257033394 0.003494166116038 0.066650626341073 0.036189655028314
If you try that with mvnpdf you get the error, while if you "correct" the symmetry by the trick mentioned above it seems to work.
Any help is welcome. Thanks.