I am using scikits.sparse.cholmod for python to get cholesky factorization of a symmetric matrix.
I compared the results of cholesky () with matlab chol () . The results have a mismatch between some rows and columns. I am trying to iterate over factorization to get eigenvalues, and this mismatch seems problematic.
Here is my code:
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse import csc_matrix
from scikits.sparse.cholmod import cholesky
A = csr_matrix([[1,2,0,0], [0,0,3, 0], [4,0,5, 0], [0, 0, 1, 2]])
B = (A*A.T)
print "B: "
print B.todense()
for i in range(10):
factor = cholesky(B.tocsc())
l = factor.L()
B = (l.T*l)
print l.todense()
And the lower triangular matrix for the first iteration:
[[ 2.23606798 0. 0. 0. ]
[ 0. 3. 0. 0. ]
[ 0. 1. 2. 0. ]
[ 1.78885438 5. 0. 3.57770876]]
And the lower triangular Matlab matrix:
[2.2361 0 0 0
0 3.0000 0 0
1.7889 5.0000 3.5777 0
0 1.0000 0 2.0000]
The result of Matlab is plausible, as it leads to the correct eigenvalues. Am I doing something wrong with choosing sparse matrix type in python?