def test_random_normal(self, mock_stateless_random_normal):
     _ = dynamics.random_normal(shape=[3, 1], i=41 / 5, key=9)
     _, call_args = mock_stateless_random_normal.call_args
     assert_ops = [
         tf.assert_equal(tf.stack([9, 8]), call_args['seed']),
         tf.assert_equal([3, 1], call_args['shape'])
     ]
     with self.session() as sess:
         sess.run(assert_ops)
  def test_antithetic_normal_lowers_variance(self):
    shape = [512]
    num_trials = 128

    key_ph = tf.placeholder(shape=(), dtype=tf.int32)
    normal_samples = dynamics.random_normal(shape, key=key_ph)
    antithetic_normal_samples = dynamics.random_antithetic_normal(
        shape, key=key_ph)

    mean_estimator = tf.reduce_mean(normal_samples)
    antithetic_mean_estimator = tf.reduce_mean(antithetic_normal_samples)

    mean_estimates = []
    antithetic_mean_estimates = []
    with self.session() as session:
      for i in range(num_trials):
        mean_estimates.append(
            session.run(mean_estimator, feed_dict={key_ph: i}))
        antithetic_mean_estimates.append(
            session.run(antithetic_mean_estimator, feed_dict={key_ph: i}))

    self.assertLessEqual(
        np.std(antithetic_mean_estimates), np.std(mean_estimates))
Example #3
0
 def _dynamics_op(unused_s, t, dt):
     return dynamics.random_normal([num_samples], t, dt)
Example #4
0
 def test_random_normal(self, mock_stateless_random_normal):
     _ = dynamics.random_normal(shape=[3, 1], i=41 / 5, key=9)
     _, call_args = mock_stateless_random_normal.call_args
     tf.assert_equal(tf.stack([9, 8]), call_args['seed']).mark_used()
     tf.assert_equal([3, 1], call_args['shape']).mark_used()