Пример #1
0
 def testBijectorForwardInverseEventDimsOne(self):
     bijector = tfb.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)))
Пример #2
0
 def testScalarCongruency(self):
     bijector = tfb.Softsign(validate_args=True)
     bijector_test_util.assert_scalar_congruency(bijector,
                                                 lower_x=-20.,
                                                 upper_x=20.,
                                                 eval_func=self.evaluate,
                                                 rtol=.05)
Пример #3
0
 def testBijectiveAndFinite(self):
   bijector = tfb.Softsign(validate_args=True)
   x = np.linspace(-20., 20., 100).astype(np.float32)
   y = np.linspace(-0.99, 0.99, 100).astype(np.float32)
   bijector_test_util.assert_bijective_and_finite(
       bijector, x, y, eval_func=self.evaluate, event_ndims=0, rtol=1e-3,
       atol=1e-3)
Пример #4
0
 def testBijectorForwardInverseEventDimsOne(self):
     bijector = tfb.Softsign(validate_args=True)
     self.assertStartsWith(bijector.name, "softsign")
     x = 2. * np.random.randn(2, 10)
     y = self._softsign(x)
     self.assertAllClose(y, self.evaluate(bijector.forward(x)))
     self.assertAllClose(x, self.evaluate(bijector.inverse(y)))
Пример #5
0
 def testBijectorLogDetJacobianEventDimsOne(self):
     bijector = tfb.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)))
Пример #6
0
  def testBijectorLogDetJacobianEventDimsZero(self):
    bijector = tfb.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)))
Пример #7
0
  def testBijectorBounds(self):
    bijector = tfb.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))
Пример #8
0
 def testBijectiveAndFinite(self):
     with self.test_session():
         bijector = tfb.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)
Пример #9
0
 def testScalarCongruency(self):
     with self.test_session():
         bijector = tfb.Softsign(validate_args=True)
         assert_scalar_congruency(bijector, lower_x=-20., upper_x=20.)