def test_posterior(self): """Check the posterior over weights function returns mean and covar.""" clf = RVR() x = np.array([[1, 2], [3, 4]]) y = np.array([[5, 6], [7, 8]]) clf.phi = clf._apply_kernel(x, y) clf.alpha_ = np.ones(3) clf.m_ = np.ones(3) clf.beta_ = 1 clf.y = np.array([1, 1]) clf._posterior() m_target = np.array([6.103885e-03, 3.750334e-08, 6.666294e-01]) sigma_target = np.array([ [9.997764e-01, -1.373791e-09, -6.103885e-03], [-1.373791e-09, 1.000000e+00, -3.750334e-08], [-6.103885e-03, -3.750334e-08, 3.333706e-01] ]) np.testing.assert_allclose(clf.m_, m_target) np.testing.assert_allclose(clf.sigma_, sigma_target)
def test_predict(self): """Check the predict function works with pre-set values.""" clf = RVR(kernel='linear', bias_used=False) clf.relevance_ = np.array([[1, 1]]) clf.m_ = np.array([1]) y = clf.predict(np.array([1, 1])) self.assertEqual(y, 2)