def predict(self, Xstar, return_std=False):
"""
Returns mean and covariances for the posterior Gaussian Process.
Parameters
----------
Xstar: np.ndarray, shape=((nsamples, nfeatures))
Testing instances to predict.
return_std: bool
Whether to return the standard deviation of the posterior process. Otherwise,
it returns the whole covariance matrix of the posterior process.
Returns
-------
np.ndarray
Mean of the posterior process for testing instances.
np.ndarray
Covariance of the posterior process for testing instances.
"""
Xstar = np.atleast_2d(Xstar)
kstar = self.covfunc.K(self.X, Xstar).T
fmean = self.mprior + np.dot(kstar, self.alpha)
v = solve(self.L, kstar.T)
fcov = self.covfunc.K(Xstar, Xstar) - np.dot(v.T, v)
if return_std:
fcov = np.diag(fcov)
return fmean, fcov
评论列表
文章目录