def test_antithetic_normal_is_symmetrical(self):
        shape = [512]

        antithetic_normal_samples = dynamics.random_antithetic_normal(shape)

        with self.session() as session:
            [samples,
             sym_samples] = session.run(tf.split(antithetic_normal_samples, 2))

        self.assertAllEqual(samples, -sym_samples)
  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))