From what I know, for any square real matrix
A, a matrix generated with the following should be a positive semidefinite (PSD) matrix:
Q = A @ A.T
I have this matrix A, which is sparse and not symmetric. However, regardless of the properties of
A, I think the matrix
Q should be PSD.
However, upon using
np.linalg.eigvals, I get the following:
np.sort(np.linalg.eigvals(Q)) >>>array([-1.54781185e+01+0.j, -7.27494242e-04+0.j, 2.09363431e-04+0.j, ..., 3.55351888e+15+0.j, 5.82221014e+17+0.j, 1.78954577e+18+0.j])
I think the complex eigenvalues result from the numerical instability of the operation. Using
scipy.linalg.eigh, which takes advantage of the fact that the matrix is symmetric, gives,
np.sort(eigh(Q, eigvals_only=True)) >>>array([-3.10854357e+01, -6.60108485e+00, -7.34059692e-01, ..., 3.55351888e+15, 5.82221014e+17, 1.78954577e+18])
which again, contains negative eigenvalues.
My goal is to perform Cholesky decomposition on the matrix Q, however, I keep getting this error message saying that the matrix Q is not positive definite, which can be again confirmed with the negative eigenvalues shown above.
Does anyone know why the matrix is not PSD? Thank you.
-1.54...e+01is effectively zero compared to the largest eigenvalue of
1.78...e+18.There are many ways to fix the problem, but which one(s) to recommend depend on how you compute this matrix, what it represents, and what you want to do with the Cholesky decomposition. Maybe you could edit in that information? $\endgroup$
CHOLMODthat is for sparse matrices. $\endgroup$
lme4::lmerat the end of the day is (computationally) a CHOLMOD. You get that decomposition done and the rest almost glides through). $\endgroup$