Skip to content

Instantly share code, notes, and snippets.

@ShuaiGuo16
Created January 23, 2021 21:12
Show Gist options
  • Save ShuaiGuo16/aa89e50595449658b6afb629292a21f2 to your computer and use it in GitHub Desktop.
Save ShuaiGuo16/aa89e50595449658b6afb629292a21f2 to your computer and use it in GitHub Desktop.
GP model Predict
def predict(self, X_test):
"""GP model predicting
Input
-----
X_test: test set, array of shape (n_samples, n_features)
Output
------
f: GP predictions
SSqr: Prediction variances"""
n = self.X.shape[0]
one = np.ones((n,1))
# Construct correlation matrix between test and train data
k = self.Corr(self.X, X_test, 10**self.theta)
# Mean prediction
f = self.mu + k.T @ self.inv_K @ (self.y-self.mu*one)
# Variance prediction
SSqr = self.SigmaSqr*(1 - np.diag(k.T @ self.inv_K @ k))
return f.flatten(), SSqr.flatten()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment