From a9e65c965b3c2a6124d17abef4f959d6924fd473 Mon Sep 17 00:00:00 2001 From: Martin Bubel Date: Tue, 10 Oct 2023 20:00:34 +0200 Subject: [PATCH] format on save --- GPy/testing/svgp_tests.py | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/GPy/testing/svgp_tests.py b/GPy/testing/svgp_tests.py index beb9c00d..3729d3f0 100644 --- a/GPy/testing/svgp_tests.py +++ b/GPy/testing/svgp_tests.py @@ -1,54 +1,60 @@ 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 + 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) + k = GPy.kern.RBF(1, lengthscale=5.0) + 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) + 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) + k = GPy.kern.RBF(1, lengthscale=5.0) + 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_Poisson_with_meanfunction(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) - 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) - mf = GPy.mappings.Linear(1,1) + 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) + Y = np.array([np.random.poisson(f) for f in latent_f.flatten()]).reshape(-1, 1) + + mf = GPy.mappings.Linear(1, 1) lik = GPy.likelihoods.Poisson() - k = GPy.kern.RBF(1, lengthscale=5.) + GPy.kern.White(1, 1e-6) + k = GPy.kern.RBF(1, lengthscale=5.0) + GPy.kern.White(1, 1e-6) self.m = GPy.core.SVGP(X, Y, Z=Z, likelihood=lik, kernel=k, mean_function=mf) + def test_grad(self): assert self.m.checkgrad(step=1e-4) - -