On 2012-10-29, Raniere Gaia Silva <[email protected]> wrote:
> 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

> I look at this thread
> https://groups.google.com/forum/?fromgroups=#!searchin/sage-devel/cholesky/sage-devel/AW4pmKx49H4/7iuet3rWYQgJ
> but it didn't help very much (and is a little old).
>
> Bellow a minimal example of the problem.
>
> {{{
> sage: D = matrix(RDF, 2, 2, [[1, 1],[1,2]])
> sage: D
> [1.0 1.0]
> [1.0 2.0]
> sage: D.cholesky()
> [1.0 0.0]
> [1.0 1.0]
> sage: D = matrix(RDF, 2, 2, [[1, 1],[1,2]], sparse=True)
> sage: D
> [1.0 1.0]
> [1.0 2.0]
> sage: D.cholesky()
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
>
> /home/raniere/documents/cnpq_126874_2012-3/src_sage/<ipython console>
> in <module>()
>
> /home/raniere/opt/sage/local/lib/python2.7/site-packages/sage/matrix/matrix2.so
> in sage.matrix.matrix2.Matrix.cholesky (sage/matrix/matrix2.c:47860)()
>
> TypeError: base ring of the matrix must be exact, not Real Double Field
> }}}
>
> Thanks,
> Raniere
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/sage-support?hl=en.


Reply via email to