mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-30 14:35:15 +02:00
Part working version of sympy covariance with new params version.
This commit is contained in:
parent
3968d48ba5
commit
339b5caa76
6 changed files with 182 additions and 479 deletions
|
|
@ -62,41 +62,41 @@ def force_F_ordered(A):
|
|||
print "why are your arrays not F order?"
|
||||
return np.asfortranarray(A)
|
||||
|
||||
# def jitchol(A, maxtries=5):
|
||||
# A = force_F_ordered_symmetric(A)
|
||||
# L, info = lapack.dpotrf(A, lower=1)
|
||||
# if info == 0:
|
||||
# return L
|
||||
# else:
|
||||
# if maxtries==0:
|
||||
# raise linalg.LinAlgError, "not positive definite, even with jitter."
|
||||
# diagA = np.diag(A)
|
||||
# if np.any(diagA <= 0.):
|
||||
# raise linalg.LinAlgError, "not pd: non-positive diagonal elements"
|
||||
# jitter = diagA.mean() * 1e-6
|
||||
|
||||
# return jitchol(A+np.eye(A.shape[0])*jitter, maxtries-1)
|
||||
|
||||
def jitchol(A, maxtries=5):
|
||||
A = force_F_ordered_symmetric(A)
|
||||
L, info = lapack.dpotrf(A, lower=1)
|
||||
if info == 0:
|
||||
return L
|
||||
else:
|
||||
if maxtries==0:
|
||||
raise linalg.LinAlgError, "not positive definite, even with jitter."
|
||||
diagA = np.diag(A)
|
||||
if np.any(diagA <= 0.):
|
||||
raise linalg.LinAlgError, "not pd: non-positive diagonal elements"
|
||||
jitter = diagA.mean() * 1e-6
|
||||
A = np.ascontiguousarray(A)
|
||||
L, info = lapack.dpotrf(A, lower=1)
|
||||
if info == 0:
|
||||
return L
|
||||
else:
|
||||
diagA = np.diag(A)
|
||||
if np.any(diagA <= 0.):
|
||||
raise linalg.LinAlgError, "not pd: non-positive diagonal elements"
|
||||
jitter = diagA.mean() * 1e-6
|
||||
while maxtries > 0 and np.isfinite(jitter):
|
||||
print 'Warning: adding jitter of {:.10e}'.format(jitter)
|
||||
try:
|
||||
return linalg.cholesky(A + np.eye(A.shape[0]).T * jitter, lower=True)
|
||||
except:
|
||||
jitter *= 10
|
||||
finally:
|
||||
maxtries -= 1
|
||||
raise linalg.LinAlgError, "not positive definite, even with jitter."
|
||||
|
||||
return jitchol(A+np.eye(A.shape[0])*jitter, maxtries-1)
|
||||
|
||||
#def jitchol(A, maxtries=5):
|
||||
# A = np.ascontiguousarray(A)
|
||||
# L, info = lapack.dpotrf(A, lower=1)
|
||||
# if info == 0:
|
||||
# return L
|
||||
# else:
|
||||
# diagA = np.diag(A)
|
||||
# if np.any(diagA <= 0.):
|
||||
# raise linalg.LinAlgError, "not pd: non-positive diagonal elements"
|
||||
# jitter = diagA.mean() * 1e-6
|
||||
# while maxtries > 0 and np.isfinite(jitter):
|
||||
# print 'Warning: adding jitter of {:.10e}'.format(jitter)
|
||||
# try:
|
||||
# return linalg.cholesky(A + np.eye(A.shape[0]).T * jitter, lower=True)
|
||||
# except:
|
||||
# jitter *= 10
|
||||
# finally:
|
||||
# maxtries -= 1
|
||||
# raise linalg.LinAlgError, "not positive definite, even with jitter."
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue