Esempio n. 1
0
    def _run_mc_step():
        """Run one mini-batch step of the Monte-Carlo method."""
        feed_dict.update({key_placeholder: num_steps})
        batch_mean_est, batch_mean_sq_est = tf_session.run(
            (mean_est, mean_sq_est), feed_dict=feed_dict)

        new_mean_est_eval = util.running_mean_estimate(mean_est_eval,
                                                       batch_mean_est,
                                                       num_samples, batch_size)
        new_mean_sq_est_eval = util.running_mean_estimate(
            mean_sq_est_eval, batch_mean_sq_est, num_samples, batch_size)
        std_est_eval = util.stddev_est(new_mean_est_eval, new_mean_sq_est_eval)

        half_conf_interval = util.half_clt_conf_interval(
            confidence, num_samples + batch_size, std_est_eval)

        return new_mean_est_eval, new_mean_sq_est_eval, half_conf_interval
Esempio n. 2
0
  def test_running_mean_estimate_is_correct(self):
    np.random.seed(0)
    num_dims = 8
    mean_est = np.random.normal(size=[num_dims])
    batch_est = np.random.normal(size=[num_dims])

    num_samples = 128
    batch_size = 16

    updated_mean_est = util.running_mean_estimate(
        mean_est, batch_est, num_samples, batch_size)

    mean_est_fraction = float(num_samples) / float(num_samples + batch_size)
    batch_est_fraction = float(batch_size) / float(num_samples + batch_size)

    self.assertAllAlmostEqual(
        updated_mean_est,
        mean_est_fraction * mean_est +  batch_est_fraction * batch_est)