def test_map_default(self):
        with self.test_session() as sess:
            x = Gamma(2.0, 0.5)

            inference = ed.MAP([x])
            inference.initialize(auto_transform=True, n_iter=500)
            tf.global_variables_initializer().run()
            for _ in range(inference.n_iter):
                info_dict = inference.update()

            # Check approximation on constrained space has same mode as
            # target distribution.
            qx = inference.latent_vars[x]
            stats = sess.run([x.mode(), qx])
            self.assertAllClose(stats[0], stats[1], rtol=1e-5, atol=1e-5)
  def test_map_default(self):
    with self.test_session() as sess:
      x = Gamma(2.0, 0.5)

      inference = ed.MAP([x])
      inference.initialize(auto_transform=True, n_iter=500)
      tf.global_variables_initializer().run()
      for _ in range(inference.n_iter):
        info_dict = inference.update()

      # Check approximation on constrained space has same mode as
      # target distribution.
      qx = inference.latent_vars[x]
      stats = sess.run([x.mode(), qx])
      self.assertAllClose(stats[0], stats[1], rtol=1e-5, atol=1e-5)
    def test_map_custom(self):
        with self.test_session() as sess:
            x = Gamma(2.0, 0.5)
            qx = PointMass(tf.nn.softplus(tf.Variable(0.5)))

            inference = ed.MAP({x: qx})
            inference.initialize(auto_transform=True, n_iter=500)
            tf.global_variables_initializer().run()
            for _ in range(inference.n_iter):
                info_dict = inference.update()

            # Check approximation on constrained space has same mode as
            # target distribution.
            stats = sess.run([x.mode(), qx])
            self.assertAllClose(stats[0], stats[1], rtol=1e-5, atol=1e-5)
  def test_map_custom(self):
    with self.test_session() as sess:
      x = Gamma(2.0, 0.5)
      qx = PointMass(tf.nn.softplus(tf.Variable(0.5)))

      inference = ed.MAP({x: qx})
      inference.initialize(auto_transform=True, n_iter=500)
      tf.global_variables_initializer().run()
      for _ in range(inference.n_iter):
        info_dict = inference.update()

      # Check approximation on constrained space has same mode as
      # target distribution.
      stats = sess.run([x.mode(), qx])
      self.assertAllClose(stats[0], stats[1], rtol=1e-5, atol=1e-5)