Created
January 23, 2021 21:12
-
-
Save ShuaiGuo16/aa89e50595449658b6afb629292a21f2 to your computer and use it in GitHub Desktop.
GP model Predict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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