Hennich
Hennich

Reputation: 699

Cholesky/LDL-decomposition for semidefinite matrices in python

I am looking for Cholesky/LDL-decomposition for semi-definite matrices in python.

Search-results:

My instances are rather small, about $100\times100$, so a symbolic solution is fine (the bottleneck is in some other place).

Upvotes: 2

Views: 2765

Answers (2)

percusse
percusse

Reputation: 3106

With SciPy v1.1.0 and later, you can use scipy.linalg.ldl for the factorization of indefinite matrices.

example : Creating a positive definite matrix arr

>>> import numpy as np
>>> import scipy.linalg as la

>>> arr = np.random.rand(100,97)
>>> M = arr @ arr.T
>>> l, d, p = la.ldl(M)
>>> np.allclose(l.dot(d).dot(l.T) - M, np.zeros([100, 100]))
True

Upvotes: 2

kiyo
kiyo

Reputation: 1999

You can just use an LU decomposition. For symmetric or hermitian matrices they are equivalent up to some sign ambiguities.

Upvotes: 2

Related Questions