Example #1
0
 def test_seed_reproducibility(self):
     first_fake_kernel = test_fixtures.RandomTransitionKernel()
     second_fake_kernel = test_fixtures.RandomTransitionKernel()
     seed = samplers.sanitize_seed(test_util.test_seed())
     last_state_t = step_kernel(
         num_steps=1,
         current_state=0,
         kernel=test_fixtures.RandomTransitionKernel(),
         seed=seed,
     )
     for num_steps in range(2, 5):
         first_final_state_t = step_kernel(
             num_steps=num_steps,
             current_state=0.,
             kernel=first_fake_kernel,
             seed=seed,
         )
         second_final_state_t = step_kernel(
             num_steps=num_steps,
             current_state=1.,  # difference should be irrelevant
             kernel=second_fake_kernel,
             seed=seed,
         )
         last_state, first_final_state, second_final_state = self.evaluate(
             [last_state_t, first_final_state_t, second_final_state_t])
         self.assertEqual(first_final_state, second_final_state)
         self.assertNotEqual(first_final_state, last_state)
         last_state_t = first_final_state_t
Example #2
0
 def test_seed_reproducibility(self):
     first_fake_kernel = test_fixtures.RandomTransitionKernel()
     second_fake_kernel = test_fixtures.RandomTransitionKernel()
     seed = test_util.test_seed(sampler_type='stateless')
     first_trace = tfp.experimental.mcmc.sample_chain_with_burnin(
         num_results=5,
         current_state=0.,
         kernel=first_fake_kernel,
         seed=seed).trace
     second_trace = tfp.experimental.mcmc.sample_chain_with_burnin(
         num_results=5,
         current_state=1.,  # difference should be irrelevant
         kernel=second_fake_kernel,
         seed=seed).trace
     first_trace, second_trace = self.evaluate([first_trace, second_trace])
     self.assertAllCloseNested(first_trace, second_trace, rtol=1e-6)
 def test_seed_reproducibility(self):
     first_fake_kernel = test_fixtures.RandomTransitionKernel()
     second_fake_kernel = test_fixtures.RandomTransitionKernel()
     seed = samplers.sanitize_seed(test_util.test_seed())
     first_final_state = tfp.experimental.mcmc.sample_chain(
         num_results=5,
         current_state=0.,
         kernel=first_fake_kernel,
         seed=seed,
     )
     second_final_state = tfp.experimental.mcmc.sample_chain(
         num_results=5,
         current_state=1.,  # difference should be irrelevant
         kernel=second_fake_kernel,
         seed=seed,
     )
     first_final_state, second_final_state = self.evaluate(
         [first_final_state, second_final_state])
     self.assertAllCloseNested(first_final_state,
                               second_final_state,
                               rtol=1e-6)
 def test_seed_reproducibility(self):
     seed = samplers.sanitize_seed(test_util.test_seed())
     fake_kernel = test_fixtures.RandomTransitionKernel()
     fake_reducer = test_fixtures.NaiveMeanReducer()
     first_reduction_rslt, _, _ = tfp.experimental.mcmc.sample_fold(
         num_steps=3,
         current_state=0.,
         kernel=fake_kernel,
         reducer=fake_reducer,
         seed=seed)
     second_reduction_rslt, _, _ = tfp.experimental.mcmc.sample_fold(
         num_steps=3,
         current_state=0.,
         kernel=fake_kernel,
         reducer=fake_reducer,
         seed=seed)
     first_reduction_rslt, second_reduction_rslt = self.evaluate(
         [first_reduction_rslt, second_reduction_rslt])
     self.assertEqual(first_reduction_rslt, second_reduction_rslt)