From bfb0ecdcb4b232e3b389d82a9ecc63e739aa7184 Mon Sep 17 00:00:00 2001 From: Zhenwen Dai Date: Fri, 19 Feb 2016 17:59:50 +0000 Subject: [PATCH] add test case for hmc sampler --- GPy/testing/inference_tests.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/GPy/testing/inference_tests.py b/GPy/testing/inference_tests.py index 7a091589..267ce594 100644 --- a/GPy/testing/inference_tests.py +++ b/GPy/testing/inference_tests.py @@ -51,5 +51,20 @@ class InferenceXTestCase(unittest.TestCase): np.testing.assert_array_almost_equal(m.X, mi.X, decimal=2) +class HMCSamplerTest(unittest.TestCase): + + def test_sampling(self): + np.random.seed(1) + x = np.linspace(0.,2*np.pi,100)[:,None] + y = -np.cos(x)+np.random.randn(*x.shape)*0.3+1 + + m = GPy.models.GPRegression(x,y) + m.kern.lengthscale.set_prior(GPy.priors.Gamma.from_EV(1.,10.)) + m.kern.variance.set_prior(GPy.priors.Gamma.from_EV(1.,10.)) + m.likelihood.variance.set_prior(GPy.priors.Gamma.from_EV(1.,10.)) + + hmc = GPy.inference.mcmc.HMC(m,stepsize=1e-2) + s = hmc.sample(num_samples=3) + if __name__ == "__main__": unittest.main()