def test_posterior(self): """Check the posterior over weights function finds the minimum.""" clf = RVC() 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.t = np.array([1, 0]) clf.beta_ = None clf._posterior() m_target = np.array([-9.157e-03, -5.049e-08, 2.794e-05]) sigma_target = np.array([ [1, -4.294e-10, -3.052e-03], [-4.294e-10, 1, -1.875e-08], [-3.052e-03, -1.875e-08, 6.667e-01] ]) np.testing.assert_allclose(clf.m_, m_target, rtol=1e-3) np.testing.assert_allclose(clf.sigma_, sigma_target, rtol=1e-3)
def test_log_posterior(self): """Check _log_posterior returns the correct value and jacobian.""" clf = RVC() x = np.array([[1, 2], [3, 4]]) y = np.array([[5, 6], [7, 8]]) phi = clf._apply_kernel(x, y) alpha = np.ones(3) m = np.ones(3) t = np.array([1, 0]) log_p, jacobian = clf._log_posterior(m, alpha, phi, t) j_target = np.array([1.013, 1, 1.466]) self.assertAlmostEqual(log_p, 3.140, places=3) np.testing.assert_allclose(jacobian, j_target, rtol=1e-3)
def test_hessian(self): """Check the hessian function returns the correct values.""" clf = RVC() x = np.array([[1, 2], [3, 4]]) y = np.array([[5, 6], [7, 8]]) phi = clf._apply_kernel(x, y) alpha = np.ones(3) m = np.ones(3) t = np.array([1, 0]) hessian = clf._hessian(m, alpha, phi, t) h_target = np.array([[1, 4.018e-10, 3.571e-03], [4.018e-10, 1, 2.194e-08], [3.571e-03, 2.194e-08, 1.392]]) np.testing.assert_allclose(hessian, h_target, rtol=1e-3)