Example #1
0
 def testBijectorForwardInverseEventDimsOne(self):
   bijector = Softsign(validate_args=True)
   self.assertEqual("softsign", bijector.name)
   x = 2. * self._rng.randn(2, 10)
   y = self._softsign(x)
   self.assertAllClose(y, self.evaluate(bijector.forward(x)))
   self.assertAllClose(x, self.evaluate(bijector.inverse(y)))
 def testBijectorForwardInverseEventDimsOne(self):
   bijector = Softsign(validate_args=True)
   self.assertEqual("softsign", bijector.name)
   x = 2. * self._rng.randn(2, 10)
   y = self._softsign(x)
   self.assertAllClose(y, self.evaluate(bijector.forward(x)))
   self.assertAllClose(x, self.evaluate(bijector.inverse(y)))
 def testBijectorLogDetJacobianEventDimsOne(self):
   bijector = Softsign(validate_args=True)
   y = self._rng.rand(2, 10)
   ildj_before = self._softsign_ildj_before_reduction(y)
   ildj = np.sum(ildj_before, axis=1)
   self.assertAllClose(
       ildj, self.evaluate(
           bijector.inverse_log_det_jacobian(y, event_ndims=1)))
  def testBijectorLogDetJacobianEventDimsZero(self):
    bijector = Softsign(validate_args=True)
    y = self._rng.rand(2, 10)
    # No reduction needed if event_dims = 0.
    ildj = self._softsign_ildj_before_reduction(y)

    self.assertAllClose(ildj, self.evaluate(
        bijector.inverse_log_det_jacobian(y, event_ndims=0)))
Example #5
0
 def testBijectorLogDetJacobianEventDimsOne(self):
   bijector = Softsign(validate_args=True)
   y = self._rng.rand(2, 10)
   ildj_before = self._softsign_ildj_before_reduction(y)
   ildj = np.sum(ildj_before, axis=1)
   self.assertAllClose(
       ildj, self.evaluate(
           bijector.inverse_log_det_jacobian(y, event_ndims=1)))
Example #6
0
  def testBijectorLogDetJacobianEventDimsZero(self):
    bijector = Softsign(validate_args=True)
    y = self._rng.rand(2, 10)
    # No reduction needed if event_dims = 0.
    ildj = self._softsign_ildj_before_reduction(y)

    self.assertAllClose(ildj, self.evaluate(
        bijector.inverse_log_det_jacobian(y, event_ndims=0)))
Example #7
0
  def testBijectorBounds(self):
    bijector = Softsign(validate_args=True)
    with self.assertRaisesOpError("greater than -1"):
      self.evaluate(bijector.inverse(-3.))
    with self.assertRaisesOpError("greater than -1"):
      self.evaluate(bijector.inverse_log_det_jacobian(-3., event_ndims=0))

    with self.assertRaisesOpError("less than 1"):
      self.evaluate(bijector.inverse(3.))
    with self.assertRaisesOpError("less than 1"):
      self.evaluate(bijector.inverse_log_det_jacobian(3., event_ndims=0))
    def testBijectorBounds(self):
        bijector = Softsign(validate_args=True)
        with self.test_session():
            with self.assertRaisesOpError("greater than -1"):
                bijector.inverse(-3.).eval()
            with self.assertRaisesOpError("greater than -1"):
                bijector.inverse_log_det_jacobian(-3., event_ndims=0).eval()

            with self.assertRaisesOpError("less than 1"):
                bijector.inverse(3.).eval()
            with self.assertRaisesOpError("less than 1"):
                bijector.inverse_log_det_jacobian(3., event_ndims=0).eval()
Example #9
0
 def testBijectiveAndFinite(self):
   with self.cached_session():
     bijector = Softsign(validate_args=True)
     x = np.linspace(-20., 20., 100).astype(np.float32)
     y = np.linspace(-0.99, 0.99, 100).astype(np.float32)
     assert_bijective_and_finite(
         bijector, x, y, event_ndims=0, rtol=1e-3, atol=1e-3)
Example #10
0
 def testScalarCongruency(self):
   with self.cached_session():
     bijector = Softsign(validate_args=True)
     assert_scalar_congruency(bijector, lower_x=-20., upper_x=20.)