예제 #1
0
    def test_exact_posterior_recovery_no_transition_noise(self):
        with self.test_session() as session:
            stub_model, data, true_params = self._get_single_model()
            input_fn = input_pipeline.WholeDatasetInputFn(
                input_pipeline.NumpyReader(data))
            features, _ = input_fn()
            model_outputs = stub_model.get_batch_loss(
                features=features,
                mode=None,
                state=math_utils.replicate_state(
                    start_state=stub_model.get_start_state(),
                    batch_size=array_ops.shape(
                        features[feature_keys.TrainEvalFeatures.TIMES])[0]))
            variables.global_variables_initializer().run()
            coordinator = coordinator_lib.Coordinator()
            queue_runner_impl.start_queue_runners(session, coord=coordinator)
            posterior_mean, posterior_var, posterior_times = session.run(
                # Feed the true model parameters so that this test doesn't depend on
                # the generated parameters being close to the variable initializations
                # (an alternative would be training steps to fit the noise values,
                # which would be slow).
                model_outputs.end_state,
                feed_dict=true_params)
            coordinator.request_stop()
            coordinator.join()

            self.assertAllClose(numpy.zeros([1, 4, 4]),
                                posterior_var,
                                atol=1e-2)
            self.assertAllClose(numpy.dot(
                numpy.linalg.matrix_power(
                    stub_model.transition,
                    data[feature_keys.TrainEvalFeatures.TIMES].shape[1]),
                true_params[stub_model.prior_state_mean]),
                                posterior_mean[0],
                                rtol=1e-1)
            self.assertAllClose(
                math_utils.batch_end_time(
                    features[feature_keys.TrainEvalFeatures.TIMES]).eval(),
                posterior_times)
  def test_exact_posterior_recovery_no_transition_noise(self):
    with self.cached_session() as session:
      stub_model, data, true_params = self._get_single_model()
      input_fn = input_pipeline.WholeDatasetInputFn(
          input_pipeline.NumpyReader(data))
      features, _ = input_fn()
      model_outputs = stub_model.get_batch_loss(
          features=features,
          mode=None,
          state=math_utils.replicate_state(
              start_state=stub_model.get_start_state(),
              batch_size=array_ops.shape(
                  features[feature_keys.TrainEvalFeatures.TIMES])[0]))
      variables.global_variables_initializer().run()
      coordinator = coordinator_lib.Coordinator()
      queue_runner_impl.start_queue_runners(session, coord=coordinator)
      posterior_mean, posterior_var, posterior_times = session.run(
          # Feed the true model parameters so that this test doesn't depend on
          # the generated parameters being close to the variable initializations
          # (an alternative would be training steps to fit the noise values,
          # which would be slow).
          model_outputs.end_state, feed_dict=true_params)
      coordinator.request_stop()
      coordinator.join()

      self.assertAllClose(numpy.zeros([1, 4, 4]), posterior_var,
                          atol=1e-2)
      self.assertAllClose(
          numpy.dot(
              numpy.linalg.matrix_power(
                  stub_model.transition,
                  data[feature_keys.TrainEvalFeatures.TIMES].shape[1]),
              true_params[stub_model.prior_state_mean]),
          posterior_mean[0],
          rtol=1e-1)
      self.assertAllClose(
          math_utils.batch_end_time(
              features[feature_keys.TrainEvalFeatures.TIMES]).eval(),
          posterior_times)