migrate svgp_tests to pytest

This commit is contained in:
Martin Bubel 2023-10-10 20:01:25 +02:00
parent a9e65c965b
commit 4b427de8fa

View file

@ -2,12 +2,12 @@ import numpy as np
import GPy
class SVGP_nonconvex(np.testing.TestCase):
class TestSVGP_nonconvex:
"""
Inference in the SVGP with a student-T likelihood
"""
def setUp(self):
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
@ -18,15 +18,16 @@ class SVGP_nonconvex(np.testing.TestCase):
self.m = GPy.core.SVGP(X, Y, Z=Z, likelihood=lik, kernel=k)
def test_grad(self):
self.setup()
assert self.m.checkgrad(step=1e-4)
class SVGP_classification(np.testing.TestCase):
class TestSVGP_classification:
"""
Inference in the SVGP with a Bernoulli likelihood
"""
def setUp(self):
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)
@ -36,15 +37,16 @@ class SVGP_classification(np.testing.TestCase):
self.m = GPy.core.SVGP(X, Y, Z=Z, likelihood=lik, kernel=k)
def test_grad(self):
self.setup()
assert self.m.checkgrad(step=1e-4)
class SVGP_Poisson_with_meanfunction(np.testing.TestCase):
class TestSVGP_Poisson_with_meanfunction:
"""
Inference in the SVGP with a Bernoulli likelihood
"""
def setUp(self):
def setup(self):
X = np.linspace(0, 10, 100).reshape(-1, 1)
Z = np.linspace(0, 10, 10).reshape(-1, 1)
latent_f = np.exp(0.1 * X * 0.05 * X**2)
@ -57,4 +59,5 @@ class SVGP_Poisson_with_meanfunction(np.testing.TestCase):
self.m = GPy.core.SVGP(X, Y, Z=Z, likelihood=lik, kernel=k, mean_function=mf)
def test_grad(self):
self.setup()
assert self.m.checkgrad(step=1e-4)