mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-07-11 16:22:13 +02:00
fix normalizer
This commit is contained in:
parent
5a907bd013
commit
7550b1e5ef
2 changed files with 100 additions and 4 deletions
|
|
@ -1168,7 +1168,7 @@ class GradientTests(np.testing.TestCase):
|
|||
Y = np.array([[1], [2]])
|
||||
m = GPy.models.GPRegression(X1, Y, kernel=k)
|
||||
|
||||
result = m.posterior_covariance_between_points(X1, X2)
|
||||
result = m._raw_posterior_covariance_between_points(X1, X2)
|
||||
expected = np.array([[0.4, 2.2], [1.0, 1.0]]) / 3.0
|
||||
|
||||
self.assertTrue(np.allclose(result, expected))
|
||||
|
|
@ -1179,7 +1179,7 @@ class GradientTests(np.testing.TestCase):
|
|||
m = _create_missing_data_model(k, Q)
|
||||
|
||||
with self.assertRaises(RuntimeError):
|
||||
m.posterior_covariance_between_points(np.array([[1], [2]]), np.array([[3], [4]]))
|
||||
m._raw_posterior_covariance_between_points(np.array([[1], [2]]), np.array([[3], [4]]))
|
||||
|
||||
def test_multioutput_model_with_derivative_observations(self):
|
||||
f = lambda x: np.sin(x)+0.1*(x-2.)**2-0.005*x**3
|
||||
|
|
@ -1242,6 +1242,45 @@ class GradientTests(np.testing.TestCase):
|
|||
|
||||
self.assertTrue(m.checkgrad())
|
||||
|
||||
|
||||
def test_predictive_gradients_with_normalizer(self):
|
||||
"""
|
||||
Check that model.predictive_gradients returns the gradients of
|
||||
model.predict when normalizer=True
|
||||
"""
|
||||
N, M, Q = 10, 15, 3
|
||||
X = np.random.rand(M,Q)
|
||||
Y = np.random.rand(M,1)
|
||||
x = np.random.rand(N, Q)
|
||||
model = GPy.models.GPRegression(X=X, Y=Y, normalizer=True)
|
||||
from GPy.models import GradientChecker
|
||||
gm = GradientChecker(lambda x: model.predict(x)[0],
|
||||
lambda x: model.predictive_gradients(x)[0],
|
||||
x, 'x')
|
||||
gc = GradientChecker(lambda x: model.predict(x)[1],
|
||||
lambda x: model.predictive_gradients(x)[1],
|
||||
x, 'x')
|
||||
assert(gm.checkgrad())
|
||||
assert(gc.checkgrad())
|
||||
|
||||
|
||||
def test_posterior_covariance_between_points_with_normalizer(self):
|
||||
"""
|
||||
Check that model.posterior_covariance_between_points returns
|
||||
the covariance from model.predict when normalizer=True
|
||||
"""
|
||||
np.random.seed(3)
|
||||
N, M, Q = 10, 15, 3
|
||||
X = np.random.rand(M,Q)
|
||||
Y = np.random.rand(M,1)
|
||||
x = np.random.rand(2, Q)
|
||||
model = GPy.models.GPRegression(X=X, Y=Y, normalizer=True)
|
||||
|
||||
c1 = model.posterior_covariance_between_points(x,x)
|
||||
c2 = model.predict(x, full_cov=True)[1]
|
||||
np.testing.assert_allclose(c1,c2)
|
||||
|
||||
|
||||
def _create_missing_data_model(kernel, Q):
|
||||
D1, D2, D3, N, num_inducing = 13, 5, 8, 400, 3
|
||||
_, _, Ylist = GPy.examples.dimensionality_reduction._simulate_matern(D1, D2, D3, N, num_inducing, False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue