Skip to content

Commit

Permalink
Further linalg improvements in GpRegressor
Browse files Browse the repository at this point in the history
  • Loading branch information
C-bowman committed Dec 31, 2021
1 parent 0133a26 commit 499c3c2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions inference/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ def loo_predictions(self):
"""
# Use the Cholesky decomposition of the covariance to find its inverse
I = eye(len(self.x))
iK = solve_triangular(self.L.T, solve_triangular(self.L, I, lower=True))
iK = solve_triangular(self.L, eye(self.L.shape[0]), lower=True)
iK = iK.T @ iK
var = 1.0 / diag(iK)

mu = self.y - self.alpha * var
Expand All @@ -443,12 +444,12 @@ def loo_likelihood(self, theta):
try:
K_xx = self.cov.build_covariance(theta[self.cov_slice]) + self.sig
mu = self.mean.build_mean(theta[self.mean_slice])
L = cholesky(K_xx)

# Use the Cholesky decomposition of the covariance to find its inverse
I = eye(len(self.x))
iK = solve_triangular(L.T, solve_triangular(L, I, lower=True))
alpha = solve_triangular(L.T, solve_triangular(L, self.y - mu, lower=True))
L = cholesky(K_xx)
iK = solve_triangular(L, eye(L.shape[0]), lower=True)
iK = iK.T @ iK
alpha = iK.dot(self.y - mu)
var = 1.0 / diag(iK)
return -0.5 * (var * alpha ** 2 + log(var)).sum()
except:
Expand Down

0 comments on commit 499c3c2

Please sign in to comment.