mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-11 04:52:37 +02:00
add test case for hmc sampler
This commit is contained in:
parent
98daaba57e
commit
bfb0ecdcb4
1 changed files with 15 additions and 0 deletions
|
|
@ -51,5 +51,20 @@ class InferenceXTestCase(unittest.TestCase):
|
||||||
np.testing.assert_array_almost_equal(m.X, mi.X, decimal=2)
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue