Example #1
0
def test_checkgrad():
    import nose
    import f_energy as en
    dim = 10
    x0 = np.zeros(dim)
    M = np.random.rand(dim,dim)
    M += M.T.copy()
    error = hmc(en.f_multivariate_normal, x0, en.g_multivariate_normal, args=(M,), checkgrad=True)
    nose.tools.assert_almost_equal(error,0,5)
Example #2
0
def test_hmc():
    import f_energy as en
    dim = 5
    x0 = np.zeros(dim)
    M = np.eye(dim)
    samples = hmc(en.f_multivariate_normal, x0, en.g_multivariate_normal, args=(M,),
                  nsamples=10**3,nomit=10**3,steps=100,stepadj=.05)
    C = np.cov(samples,rowvar=0,bias=1)
    np.testing.assert_array_almost_equal(M,np.linalg.inv(C),1)