Пример #1
0
 def testBijectiveAndFinite32bit(self):
   with self.test_session():
     bijector = Softplus(event_ndims=0)
     x = np.linspace(-20., 20., 100).astype(np.float32)
     y = np.logspace(-10, 10, 100).astype(np.float32)
     assert_bijective_and_finite(
         bijector, x, y, rtol=1e-2, atol=1e-2)
Пример #2
0
 def testBijectiveAndFinite(self):
   with self.test_session():
     x = np.linspace(-7., 7., 100).astype(np.float32)
     eps = 1e-3
     y = np.linspace(eps, 1. - eps, 100).astype(np.float32)
     bijector_test_util.assert_bijective_and_finite(
         sigmoid.Sigmoid(), x, y, atol=0., rtol=1e-4)
Пример #3
0
 def testBijectiveAndFinite(self):
   with self.test_session():
     bijector = power_transform_lib.PowerTransform(
         power=0.2, event_ndims=0, validate_args=True)
     x = np.linspace(-4.999, 10, num=10).astype(np.float32)
     y = np.logspace(0.001, 10, num=10).astype(np.float32)
     bijector_test_util.assert_bijective_and_finite(bijector, x, y, rtol=1e-3)
Пример #4
0
 def testBijectiveAndFinite(self):
   with self.test_session():
     bijector = PowerTransform(
         power=0.2, event_ndims=0, validate_args=True)
     x = np.linspace(-4.999, 10, num=10).astype(np.float32)
     y = np.logspace(0.001, 10, num=10).astype(np.float32)
     assert_bijective_and_finite(bijector, x, y, rtol=1e-3)
Пример #5
0
 def testBijectiveAndFiniteWithNegativeHingeSoftness32Bit(self):
   with self.test_session():
     bijector = Softplus(event_ndims=0, hinge_softness=-0.7)
     x = np.linspace(-20., 20., 100).astype(np.float32)
     y = -np.logspace(-10, 10, 100).astype(np.float32)
     assert_bijective_and_finite(
         bijector, x, y, rtol=1e-2, atol=1e-2)
Пример #6
0
 def testBijectiveAndFinite16bit(self):
     with self.test_session():
         bijector = Softplus(event_ndims=0)
         # softplus(-20) is zero, so we can't use such a large range as in 32bit.
         x = np.linspace(-10., 20., 100).astype(np.float16)
         # Note that float16 is only in the open set (0, inf) for a smaller
         # logspace range.  The actual range was (-7, 4), so use something smaller
         # for the test.
         y = np.logspace(-6, 3, 100).astype(np.float16)
         assert_bijective_and_finite(bijector, x, y, rtol=1e-1, atol=1e-3)
Пример #7
0
 def testBijectiveAndFinite32bit(self):
     with self.test_session():
         bijector = softplus_lib.Softplus(event_ndims=0)
         x = np.linspace(-20., 20., 100).astype(np.float32)
         y = np.logspace(-10, 10, 100).astype(np.float32)
         bijector_test_util.assert_bijective_and_finite(bijector,
                                                        x,
                                                        y,
                                                        rtol=1e-2,
                                                        atol=1e-2)
Пример #8
0
 def testBijectiveAndFinite(self):
     with self.test_session():
         x = np.linspace(-7., 7., 100).astype(np.float32)
         eps = 1e-3
         y = np.linspace(eps, 1. - eps, 100).astype(np.float32)
         bijector_test_util.assert_bijective_and_finite(sigmoid.Sigmoid(),
                                                        x,
                                                        y,
                                                        atol=0.,
                                                        rtol=1e-4)
Пример #9
0
 def testBijectiveAndFinite16bit(self):
   with self.test_session():
     bijector = Softplus(event_ndims=0)
     # softplus(-20) is zero, so we can't use such a large range as in 32bit.
     x = np.linspace(-10., 20., 100).astype(np.float16)
     # Note that float16 is only in the open set (0, inf) for a smaller
     # logspace range.  The actual range was (-7, 4), so use something smaller
     # for the test.
     y = np.logspace(-6, 3, 100).astype(np.float16)
     assert_bijective_and_finite(
         bijector, x, y, rtol=1e-1, atol=1e-3)
 def testBijectiveAndFinite(self):
     with self.test_session():
         softmax = softmax_centered_lib.SoftmaxCentered(event_ndims=1)
         x = np.linspace(-50, 50, num=10).reshape(5, 2).astype(np.float32)
         # Make y values on the simplex with a wide range.
         y_0 = np.ones(5).astype(np.float32)
         y_1 = (1e-5 * rng.rand(5)).astype(np.float32)
         y_2 = (1e1 * rng.rand(5)).astype(np.float32)
         y = np.array([y_0, y_1, y_2])
         y /= y.sum(axis=0)
         y = y.T  # y.shape = [5, 3]
         bijector_test_util.assert_bijective_and_finite(softmax, x, y)
Пример #11
0
 def testBijectiveAndFinite(self):
   with self.test_session():
     softmax = softmax_centered_lib.SoftmaxCentered(event_ndims=1)
     x = np.linspace(-50, 50, num=10).reshape(5, 2).astype(np.float32)
     # Make y values on the simplex with a wide range.
     y_0 = np.ones(5).astype(np.float32)
     y_1 = (1e-5 * rng.rand(5)).astype(np.float32)
     y_2 = (1e1 * rng.rand(5)).astype(np.float32)
     y = np.array([y_0, y_1, y_2])
     y /= y.sum(axis=0)
     y = y.T  # y.shape = [5, 3]
     bijector_test_util.assert_bijective_and_finite(softmax, x, y)
Пример #12
0
 def testBijectiveAndFinite(self):
   with self.test_session():
     bijector = Exp(event_ndims=0)
     x = np.linspace(-10, 10, num=10).astype(np.float32)
     y = np.logspace(-10, 10, num=10).astype(np.float32)
     assert_bijective_and_finite(bijector, x, y)
Пример #13
0
 def testBijectiveAndFinite(self):
   with self.test_session():
     bijector = exp_lib.Exp(event_ndims=0)
     x = np.linspace(-10, 10, num=10).astype(np.float32)
     y = np.logspace(-10, 10, num=10).astype(np.float32)
     bijector_test_util.assert_bijective_and_finite(bijector, x, y)
Пример #14
0
 def testBijectiveAndFiniteWithNegativeHingeSoftness32Bit(self):
     with self.test_session():
         bijector = Softplus(event_ndims=0, hinge_softness=-0.7)
         x = np.linspace(-20., 20., 100).astype(np.float32)
         y = -np.logspace(-10, 10, 100).astype(np.float32)
         assert_bijective_and_finite(bijector, x, y, rtol=1e-2, atol=1e-2)