def test_mean_cov(self):
with self.test_context():
self.m.compile()
num_samples = 1000
samples = self.hmc.sample(self.m, num_samples=num_samples,
lmin=10, lmax=21, epsilon=0.05)
self.assertEqual(samples.shape, (num_samples, 2))
xs = np.array(samples[self.m.x.full_name].tolist(), dtype=np.float32)
mean = xs.mean(0)
cov = np.cov(xs.T)
cov_standard = np.eye(cov.shape[0])
# TODO(@awav): inspite of the fact that we set up graph's random seed,
# the operation seed is still assigned by tensorflow automatically
# and hence sample output numbers are not deterministic.
#
# self.assertTrue(np.sum(np.abs(mean) < 0.1) >= mean.size/2)
# assert_allclose(cov, cov_standard, rtol=1e-1, atol=1e-1)
评论列表
文章目录