Skip to content

Commit

Permalink
saved cholesky output to avoid re-doing same computation
Browse files Browse the repository at this point in the history
  • Loading branch information
PFLeget committed May 16, 2024
1 parent aa786f7 commit 3ed365d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions treegp/gp_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ def return_gp_predict(self, y, X1, X2, kernel, y_err, return_cov=False):
:param y_err: Error of y. (n_samples)
"""
HT = kernel.__call__(X2, Y=X1)
K = kernel.__call__(X1) + np.eye(len(y)) * y_err**2
factor = (cholesky(K, overwrite_a=True, lower=False), False)
alpha = cho_solve(factor, y, overwrite_b=False)
y_predict = np.dot(HT, alpha.reshape((len(alpha), 1))).T[0]
if self._alpha is None:
K = kernel.__call__(X1) + np.eye(len(y)) * y_err**2
factor = (cholesky(K, overwrite_a=True, lower=False), False)
self._alpha = cho_solve(factor, y, overwrite_b=False)
y_predict = np.dot(HT, self._alpha.reshape((len(self._alpha), 1))).T[0]
if return_cov:
fact = cholesky(
K, lower=True
Expand Down Expand Up @@ -215,6 +216,9 @@ def initialize(self, X, y, y_err=None):
self._mean = np.mean(y - self._spatial_average)
else:
self._mean = 0.0
# Initialize alpha to None so that we know to recompute it if we change the
# input data.
self._alpha = None

def _build_average_meanify(self, X):
"""Compute spatial average from meanify output for a given coordinate using KN interpolation.
Expand Down

0 comments on commit 3ed365d

Please sign in to comment.