> Hi,
> I need to performe a (numerical) cholesky factorization of a sparse
> matrix (20x20) but I'm getting a error.
OK, my previous reply didn't make much sense, so here is one that is
meaningful. In cvxopt (a standard Sage spkg) there is an interface to sparse Cholesky
factorization.
There aren't too many hooks for cvxopt in Sage, and, moreover, cvxopt
does not provide a straightforward interface, you need to solve matrix
linear equations to get L, see
http://abel.ee.ucla.edu/cvxopt/userguide/spsolvers.html#positive-definite-linear-equations
so it's a bit of a walk:
sage: preparser(False) # somehow, preparser breaks cvxopt :(
sage: import cvxopt
sage: from cvxopt import cholmod
sage: A=cvxopt.sparse(cvxopt.matrix([[1,1],[1,2]])); A
<2x2 sparse matrix, tc='d', nnz=4>
sage: print A
[ 1.00e+00 1.00e+00]
[ 1.00e+00 2.00e+00]
sage: F = cholmod.symbolic(A)
sage: cholmod.numeric(A,F)
sage: Lt=cvxopt.cholmod.spsolve(F,A,sys=4); Lt
<2x2 sparse matrix, tc='d', nnz=3>
sage: print Lt
[ 1.00e+00 1.00e+00]
[ 0 1.00e+00]
Achtung! This only works in the case the decomposition PAP^T=LL^T
computed by cholmod (and stored in F), where P is a permutation
matrix, has P=identity. More generally, you need to be more careful:
either cvxopt.cholmod.symbolic() must be called with the parameter
p specified to be the identity (permutation) matrix, or it can (perhaps)
be retrieved using cvxopt.cholmod.spsolve() with appropriate B and sys=...
Well, perhaps you actually do not need to know L explicitly, just to
solve these matrix equations...
By the way, you can extract entries of Lt using syntax like this:
sage: Lt[1,0]
0.0
sage: Lt[1,1]
1.0
note that
sage: type(Lt[1,0])
<type 'float'>
so they can be converted back to Sage types.
HTH,
Dmitrii
PS. cvxopt has its own google group:
https://groups.google.com/forum/?fromgroups=#!forum/cvxopt