mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-21 14:05:14 +02:00
changed the behaviour of pdinv: now returns L and Li as well as the inverse
This commit is contained in:
parent
574f9f4e0a
commit
c72d1b1a5b
5 changed files with 21 additions and 25 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue