def test_iid_normal_passes(self): n_samples = 500 # five scalar chains taken from iid Normal(0, 1) rng = test_util.test_np_rng() iid_normal_samples = rng.randn(n_samples, 5) rhat_reducer = tfp.experimental.mcmc.PotentialScaleReductionReducer( independent_chain_ndims=1) rhat = self.evaluate(test_fixtures.reduce(rhat_reducer, iid_normal_samples)) self.assertAllEqual((), rhat.shape) self.assertAllClose(1., rhat, rtol=0.02)
def test_offset_normal_fails(self): n_samples = 500 # three 4-variate chains taken from Normal(0, 1) that have been # shifted. Since every chain is shifted, they are not the same, and the # test should fail. offset = np.array([1., -1., 2.]).reshape(3, 1) rng = test_util.test_np_rng() offset_samples = rng.randn(n_samples, 3, 4) + offset rhat_reducer = tfp.experimental.mcmc.PotentialScaleReductionReducer( independent_chain_ndims=1) rhat = self.evaluate(test_fixtures.reduce(rhat_reducer, offset_samples)) self.assertAllEqual((4,), rhat.shape) self.assertAllGreater(rhat, 1.2)
def test_random_sanity_check(self): rng = test_util.test_np_rng() x = rng.rand(100) cov_reducer = tfp.experimental.mcmc.CovarianceReducer() final_cov = self.evaluate(test_fixtures.reduce(cov_reducer, x)) self.assertNear(np.var(x, ddof=0), final_cov, err=1e-6)