changed the behaviour of pdinv: now returns L and Li as well as the inverse

This commit is contained in:
James Hensman 2012-12-06 09:51:13 -08:00
parent 574f9f4e0a
commit c72d1b1a5b
5 changed files with 21 additions and 25 deletions

View file

@ -78,23 +78,23 @@ def jitchol(A,maxtries=5):
def pdinv(A):
"""
Arguments
---------
:param A: A DxD pd numpy array
Returns
-------
inv : the inverse of A
hld: 0.5* the log of the determinant of A
:rval Ai: the inverse of A
:rtype Ai: np.ndarray
:rval L: the Cholesky decomposition of A
:rtype L: np.ndarray
:rval Li: the Cholesky decomposition of Ai
:rtype Li: np.ndarray
:rval logdet: the log of the determinant of A
:rtype logdet: float64
"""
L = jitchol(A)
hld = np.sum(np.log(np.diag(L)))
logdet = 2.*np.sum(np.log(np.diag(L)))
Li = chol_inv(L)
Ai = np.dot(Li.T,Li) #TODO: get the flapack routine form multiplying triangular matrices
inv = sp.lib.lapack.flapack.dpotri(L)[0]
# inv = linalg.flapack.dpotri(L,lower = 1)[0]
inv = np.tril(inv)+np.tril(inv,-1).T
return inv, hld
return Ai, L, Li, logdet
def chol_inv(L):