2015-03-24 14:11:50 +00:00
|
|
|
import numpy as np
|
|
|
|
|
import GPy
|
|
|
|
|
|
2023-10-10 20:00:34 +02:00
|
|
|
|
2023-10-10 20:01:25 +02:00
|
|
|
class TestSVGP_nonconvex:
|
2015-03-24 14:11:50 +00:00
|
|
|
"""
|
|
|
|
|
Inference in the SVGP with a student-T likelihood
|
|
|
|
|
"""
|
2023-10-10 20:00:34 +02:00
|
|
|
|
2023-10-10 20:01:25 +02:00
|
|
|
def setup(self):
|
2023-10-10 20:00:34 +02:00
|
|
|
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
|
2015-03-24 14:11:50 +00:00
|
|
|
Y[50] += 3
|
|
|
|
|
|
|
|
|
|
lik = GPy.likelihoods.StudentT(deg_free=2)
|
2023-10-10 20:00:34 +02:00
|
|
|
k = GPy.kern.RBF(1, lengthscale=5.0) + GPy.kern.White(1, 1e-6)
|
2015-03-24 14:11:50 +00:00
|
|
|
self.m = GPy.core.SVGP(X, Y, Z=Z, likelihood=lik, kernel=k)
|
2023-10-10 20:00:34 +02:00
|
|
|
|
2015-03-24 14:11:50 +00:00
|
|
|
def test_grad(self):
|
2023-10-10 20:01:25 +02:00
|
|
|
self.setup()
|
2015-03-24 14:11:50 +00:00
|
|
|
assert self.m.checkgrad(step=1e-4)
|
|
|
|
|
|
2023-10-10 20:00:34 +02:00
|
|
|
|
2023-10-10 20:01:25 +02:00
|
|
|
class TestSVGP_classification:
|
2015-03-24 14:11:50 +00:00
|
|
|
"""
|
|
|
|
|
Inference in the SVGP with a Bernoulli likelihood
|
|
|
|
|
"""
|
2023-10-10 20:00:34 +02:00
|
|
|
|
2023-10-10 20:01:25 +02:00
|
|
|
def setup(self):
|
2023-10-10 20:00:34 +02:00
|
|
|
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)
|
2015-03-24 14:11:50 +00:00
|
|
|
|
|
|
|
|
lik = GPy.likelihoods.Bernoulli()
|
2023-10-10 20:00:34 +02:00
|
|
|
k = GPy.kern.RBF(1, lengthscale=5.0) + GPy.kern.White(1, 1e-6)
|
2015-03-24 14:11:50 +00:00
|
|
|
self.m = GPy.core.SVGP(X, Y, Z=Z, likelihood=lik, kernel=k)
|
2023-10-10 20:00:34 +02:00
|
|
|
|
2015-03-24 14:11:50 +00:00
|
|
|
def test_grad(self):
|
2023-10-10 20:01:25 +02:00
|
|
|
self.setup()
|
2015-03-24 14:11:50 +00:00
|
|
|
assert self.m.checkgrad(step=1e-4)
|
2015-03-26 16:20:17 +00:00
|
|
|
|
2023-10-10 20:00:34 +02:00
|
|
|
|
2023-10-10 20:01:25 +02:00
|
|
|
class TestSVGP_Poisson_with_meanfunction:
|
2015-03-26 16:20:17 +00:00
|
|
|
"""
|
|
|
|
|
Inference in the SVGP with a Bernoulli likelihood
|
|
|
|
|
"""
|
2023-10-10 20:00:34 +02:00
|
|
|
|
2023-10-10 20:01:25 +02:00
|
|
|
def setup(self):
|
2023-10-10 20:00:34 +02:00
|
|
|
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)
|
|
|
|
|
Y = np.array([np.random.poisson(f) for f in latent_f.flatten()]).reshape(-1, 1)
|
2015-03-26 16:20:17 +00:00
|
|
|
|
2023-10-10 20:00:34 +02:00
|
|
|
mf = GPy.mappings.Linear(1, 1)
|
2015-03-26 16:20:17 +00:00
|
|
|
|
|
|
|
|
lik = GPy.likelihoods.Poisson()
|
2023-10-10 20:00:34 +02:00
|
|
|
k = GPy.kern.RBF(1, lengthscale=5.0) + GPy.kern.White(1, 1e-6)
|
2015-03-26 16:20:17 +00:00
|
|
|
self.m = GPy.core.SVGP(X, Y, Z=Z, likelihood=lik, kernel=k, mean_function=mf)
|
2023-10-10 20:00:34 +02:00
|
|
|
|
2015-03-26 16:20:17 +00:00
|
|
|
def test_grad(self):
|
2023-10-10 20:01:25 +02:00
|
|
|
self.setup()
|
2015-03-26 16:20:17 +00:00
|
|
|
assert self.m.checkgrad(step=1e-4)
|