Update self.num_data in GP when X is updated

This commit is contained in:
Masha Naslidnyk 🦉 2019-09-05 14:39:13 +01:00
parent 40137cc8f7
commit 1e06c6ce2f
2 changed files with 16 additions and 3 deletions

View file

@ -235,6 +235,8 @@ class GP(Model):
self.link_parameter(self.X, index=index)
else:
self.X = ObsAr(X)
self.num_data, self.input_dim = self.X.shape
self.update_model(True)
def set_X(self,X):
@ -587,9 +589,9 @@ class GP(Model):
:param size: the number of a posteriori samples.
:type size: int.
:returns: set of simulations
:rtype: np.ndarray (Nnew x D x samples)
:rtype: np.ndarray (Nnew x D x samples)
"""
predict_kwargs["full_cov"] = True # Always use the full covariance for posterior samples.
predict_kwargs["full_cov"] = True # Always use the full covariance for posterior samples.
m, v = self._raw_predict(X, **predict_kwargs)
if self.normalizer is not None:
m, v = self.normalizer.inverse_mean(m), self.normalizer.inverse_variance(v)

View file

@ -28,11 +28,14 @@ class Test(unittest.TestCase):
Xnew = NormalPosterior(m.X.mean[:10].copy(), m.X.variance[:10].copy())
m.set_XY(Xnew, m.Y[:10].copy())
assert(m.checkgrad())
assert(m.num_data == m.X.shape[0])
assert(m.input_dim == m.X.shape[1])
m.set_XY(X, self.Y)
mu2, var2 = m.predict(m.X)
np.testing.assert_allclose(mu, mu2)
np.testing.assert_allclose(var, var2)
def test_setxy_gplvm(self):
k = GPy.kern.RBF(1)
@ -42,6 +45,10 @@ class Test(unittest.TestCase):
Xnew = X[:10].copy()
m.set_XY(Xnew, m.Y[:10].copy())
assert(m.checkgrad())
assert(m.num_data == m.X.shape[0])
assert(m.input_dim == m.X.shape[1])
m.set_XY(X, self.Y)
mu2, var2 = m.predict(m.X)
np.testing.assert_allclose(mu, mu2)
@ -54,6 +61,10 @@ class Test(unittest.TestCase):
X = m.X.copy()
m.set_XY(m.X[:10], m.Y[:10])
assert(m.checkgrad())
assert(m.num_data == m.X.shape[0])
assert(m.input_dim == m.X.shape[1])
m.set_XY(X, self.Y)
mu2, var2 = m.predict(m.X)
np.testing.assert_allclose(mu, mu2)