From 534e0df6066c50893991f94ebc8f71b8e7fe81de Mon Sep 17 00:00:00 2001 From: James Hensman Date: Tue, 24 Mar 2015 14:11:50 +0000 Subject: [PATCH] some tests for the svgp, and some changes to the likelihoods --- GPy/likelihoods/bernoulli.py | 2 +- GPy/likelihoods/student_t.py | 4 ++-- GPy/testing/svgp_tests.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 GPy/testing/svgp_tests.py diff --git a/GPy/likelihoods/bernoulli.py b/GPy/likelihoods/bernoulli.py index 26de274b..f5690aa4 100644 --- a/GPy/likelihoods/bernoulli.py +++ b/GPy/likelihoods/bernoulli.py @@ -77,7 +77,7 @@ class Bernoulli(Likelihood): return Z_hat, mu_hat, sigma2_hat - def variational_expectations(self, Y, m, v, gh_points=None): + def variational_expectations(self, Y, m, v, gh_points=None, Y_metadata=None): if isinstance(self.gp_link, link_functions.Probit): if gh_points is None: diff --git a/GPy/likelihoods/student_t.py b/GPy/likelihoods/student_t.py index c805d1dd..97c2286e 100644 --- a/GPy/likelihoods/student_t.py +++ b/GPy/likelihoods/student_t.py @@ -35,8 +35,8 @@ class StudentT(Likelihood): self.log_concave = False - def parameters_changed(self): - self.variance = (self.v / float(self.v - 2)) * self.sigma2 + #def parameters_changed(self): + #self.variance = (self.v / float(self.v - 2)) * self.sigma2 def update_gradients(self, grads): """ diff --git a/GPy/testing/svgp_tests.py b/GPy/testing/svgp_tests.py new file mode 100644 index 00000000..6dc0fa56 --- /dev/null +++ b/GPy/testing/svgp_tests.py @@ -0,0 +1,34 @@ +import numpy as np +import scipy as sp +import GPy + +class SVGP_nonconvex(np.testing.TestCase): + """ + Inference in the SVGP with a student-T likelihood + """ + def setUp(self): + X = np.linspace(0,10,100).reshape(-1,1) + Z = np.linspace(0,10,10).reshape(-1,1) + Y = np.sin(X) + np.random.randn(*X.shape)*0.1 + Y[50] += 3 + + lik = GPy.likelihoods.StudentT(deg_free=2) + k = GPy.kern.RBF(1, lengthscale=5.) + GPy.kern.White(1, 1e-6) + self.m = GPy.core.SVGP(X, Y, Z=Z, likelihood=lik, kernel=k) + def test_grad(self): + assert self.m.checkgrad(step=1e-4) + +class SVGP_classification(np.testing.TestCase): + """ + Inference in the SVGP with a Bernoulli likelihood + """ + def setUp(self): + X = np.linspace(0,10,100).reshape(-1,1) + Z = np.linspace(0,10,10).reshape(-1,1) + Y = np.where((np.sin(X) + np.random.randn(*X.shape)*0.1)>0, 1,0) + + lik = GPy.likelihoods.Bernoulli() + k = GPy.kern.RBF(1, lengthscale=5.) + GPy.kern.White(1, 1e-6) + self.m = GPy.core.SVGP(X, Y, Z=Z, likelihood=lik, kernel=k) + def test_grad(self): + assert self.m.checkgrad(step=1e-4)