diff --git a/GPy/testing/bgplvm_minibatch_tests.py b/GPy/testing/bgplvm_minibatch_tests.py index c5be8b0c..4a824368 100644 --- a/GPy/testing/bgplvm_minibatch_tests.py +++ b/GPy/testing/bgplvm_minibatch_tests.py @@ -28,6 +28,29 @@ class BGPLVMTest(unittest.TestCase): np.testing.assert_allclose(m.gradient, self.m_full.gradient) assert(m.checkgrad()) + def test_predict_missing_data(self): + m = GPy.models.bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch(self.Y, self.Q, missing_data=True, stochastic=True, batchsize=self.Y.shape[1]) + m[:] = self.m_full[:] + np.testing.assert_almost_equal(m.log_likelihood(), self.m_full.log_likelihood(), 7) + np.testing.assert_allclose(m.gradient, self.m_full.gradient) + + self.assertRaises(NotImplementedError, m.predict, m.X, full_cov=True) + + mu1, var1 = m.predict(m.X, full_cov=False) + mu2, var2 = self.m_full.predict(self.m_full.X, full_cov=False) + np.testing.assert_allclose(mu1, mu2) + np.testing.assert_allclose(var1, var2) + + mu1, var1 = m.predict(m.X.mean, full_cov=True) + mu2, var2 = self.m_full.predict(self.m_full.X.mean, full_cov=True) + np.testing.assert_allclose(mu1, mu2) + np.testing.assert_allclose(var1[:,:,0], var2) + + mu1, var1 = m.predict(m.X.mean, full_cov=False) + mu2, var2 = self.m_full.predict(self.m_full.X.mean, full_cov=False) + np.testing.assert_allclose(mu1, mu2) + np.testing.assert_allclose(var1[:,[0]], var2) + def test_lik_comparisons_m0_s0(self): # Test if the different implementations give the exact same likelihood as the full model. # All of the following settings should give the same likelihood and gradients as the full model: @@ -71,6 +94,16 @@ class BGPLVMTest(unittest.TestCase): m = GPy.models.bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch(self.Y, self.Q, missing_data=False, stochastic=True, batchsize=4) assert(m.checkgrad()) + def test_predict(self): + # Test if the different implementations give the exact same likelihood as the full model. + # All of the following settings should give the same likelihood and gradients as the full model: + m = GPy.models.bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch(self.Y, self.Q, missing_data=True, stochastic=True, batchsize=self.Y.shape[1]) + m[:] = self.m_full[:] + np.testing.assert_almost_equal(m.log_likelihood(), self.m_full.log_likelihood(), 7) + np.testing.assert_allclose(m.gradient, self.m_full.gradient) + assert(m.checkgrad()) + + if __name__ == "__main__": #import sys;sys.argv = ['', 'Test.testName'] unittest.main() \ No newline at end of file