mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-11 15:15:15 +02:00
Added LOO interface for core.gp
This commit is contained in:
parent
52fb928dff
commit
949320fb64
3 changed files with 24 additions and 1 deletions
|
|
@ -604,3 +604,10 @@ class GP(Model):
|
|||
mu_star, var_star = self._raw_predict(x_test)
|
||||
return self.likelihood.log_predictive_density_sampling(y_test, mu_star, var_star, Y_metadata=Y_metadata, num_samples=num_samples)
|
||||
|
||||
def LOO(self):
|
||||
"""
|
||||
Evaluate the approximate leave one out error using the current state of the inference method
|
||||
"""
|
||||
return self.inference_method.LOO(self.kern, self.X, self.Y, self.likelihood, self.posterior, Y_metadata=self.Y_metadata)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,13 @@ class LatentFunctionInference(object):
|
|||
"""
|
||||
pass
|
||||
|
||||
def LOO(self, kern, X, Y, likelihood, posterior, *args, **kwargs):
|
||||
"""
|
||||
Leave one out error for the inference algorithm
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class InferenceMethodList(LatentFunctionInference, list):
|
||||
|
||||
def on_optimization_start(self):
|
||||
|
|
|
|||
|
|
@ -406,7 +406,16 @@ class MiscTests(unittest.TestCase):
|
|||
warp_f.plot(X.min()-10, X.max()+10)
|
||||
plt.show()
|
||||
|
||||
|
||||
def test_LOO_laplace(self):
|
||||
import GPy
|
||||
gauss = GPy.likelihoods.Gaussian()
|
||||
kern = GPy.kern.RBF(self.X.shape[1]) + GPy.kern.White(self.X.shape[1])
|
||||
exact = GPy.inference.latent_function_inference.ExactGaussianInference()
|
||||
m_exact = GPy.core.GP(X=self.X, Y=self.Y, kernel=kern.copy(), likelihood=gauss.copy(), inference_method=exact)
|
||||
laplace = GPy.inference.latent_function_inference.Laplace()
|
||||
m_laplace = GPy.core.GP(X=self.X, Y=self.Y, kernel=kern.copy(), likelihood=gauss.copy(), inference_method=laplace)
|
||||
m_laplace[:] = m_exact[:]
|
||||
np.testing.assert_almost_equal(m_exact.LOO(), m_laplace.LOO())
|
||||
|
||||
class GradientTests(np.testing.TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue