Test of whether matrix is Symmetric Positive Definite is giving wrong result when matrix is not symmetric

I'm computing a multivariate normal probability density with an estimated covariance matrix as follows:
% Update the conditional likelihood given the data
p_yk_g_seq_Ykm1(j) = mvnpdf(yk, ykp1_est, Sk);
and getting the following error
Error using mvnpdf (line 127)
SIGMA must be a square, symmetric, positive definite matrix.
Here are some checks I did in the debugger when this error occurred:
K>> Sk
Sk =
0.0540 -0.0001
-0.0001 0.0540
K>> issymmetric(Sk)
ans =
logical
0
Clearly it is not symmetric.
But when I tried to check if Sk is symmetic positive definite using the method described here in the documentaion:
K>> try chol(Sk)
disp('Matrix is symmetric positive definite.')
catch ME
disp('Matrix is not symmetric positive definite')
end
ans =
0.2323 -0.0002
0 0.2323
Matrix is symmetric positive definite.
This confused me. What is going on here? Is it non-symmetric or not PD or both?
Looking in the code for mvnpdf it actually uses this check:
[R,err] = cholcov(Sigma,0);
So maybe the method from the documentation page linked above is wrong or out of date?
Or maybe it tests for positive semi-definite but not symmetric positive semi-definite.

 Accepted Answer

From the chol documentation page: "If A is nonsymmetric , then chol treats the matrix as symmetric and uses only the diagonal and upper triangle of A." Is the symmetric matrix generated using the diagonal and upper triangle of your matrix SPD?
I'll ask the documentation staff to take a look at the page to which you linked.

4 Comments

Not sure what you mean by "Is the symmetric matrix generated using the diagonal and upper triangle of your matrix SPD?". The matrix is not symmetric, that is the problem. Although I think it is positive definite.
CHOLesky decomposition mathematically can be only applied on symetric (SPD) matrix.
Under MATLAB, in case that the storage matrix A is not symmetric and used as input argument, meaning Aij ~= Aji, MATLAB CHOL function uses only the upper part, and IGNORE the lower part, meaning it assumes as if there is a virtual symetric SPD matrix where Aij = Aji for i > j, the true storage values Aij i > j (lower part) is ignored.
Example:
AV = [2 1;
1 2];
L=chol(AV)
L = 2×2
1.4142 0.7071 0 1.2247
A = [ 2 1;
-10 2]; % perturb A(2,1) with an arbitrary value
L=chol(A) % A is assumed to be AV
L = 2×2
1.4142 0.7071 0 1.2247
L'*L
ans = 2×2
2.0000 1.0000 1.0000 2.0000
On the link determine-matrix-is-positive-definite I guess it test only the positiveness of the corresponding virrtual symmetric matrix, not the symmetric of the input.
Unfortunately in some sources the positiveness is a mathematics notion that only defined for symmetric matrix, so the "SPD" jus link both characters that is always be assotiated in mathemtical world, but not in MATLAB less strict validation for CHOL function.
I thought the PD and SPD properties are not restricted to symmetric matrices, as previously discussed in this answer thread
The definition of PD and PSD can be extended to non-symmetric matrices, but all of the interesting theorems connecting eigenvalues and determinants to positive-definiteness hold only for symmetric\Hermitian matrices.

Sign in to comment.

More Answers (1)

But when I tried to check if Sk is symmetic positive definite using the method described here in the documentaion:
All of the tests at this link are predicated on the assumption that Sk is already symmetric. In other words, they are really intended as tests of postive or non-negative definiteness, not of symmetry.
Therefore, you should just symmetrize the matrix and be done with it,
Sk=(Sk+Sk.')/2;
This does not change the status of Sk as a PSD or PD matrix.

3 Comments

Thanks, that's what I will do. So I think the title of that documentation page should be changed from 'Determine Whether Matrix Is Symmetric Positive Definite' to 'Determine Whether Matrix Is Positive Definite' or perhaps. 'Determine Whether Symmetric Matrix Is Positive Definite'
Alternatively, the page could be amended to provide the following test which seems to check both symmetric and positive definite (I assume so since this is what raised the error in my case):
[~,err] = cholcov(Pk,0)
assert(err == 0)
Yes all the changes suggested in the doc page are reasonable.

Sign in to comment.

Products

Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!