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)
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)
def testBijectiveAndFiniteWithPositiveHingeSoftness32Bit(self): with self.cached_session(): bijector = Softplus(hinge_softness=1.23) 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, event_ndims=0, rtol=1e-2, atol=1e-2)
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)
def testBijectiveAndFinite(self): with self.cached_session(): x = np.linspace(-7., 7., 100).astype(np.float32) eps = 1e-3 y = np.linspace(eps, 1. - eps, 100).astype(np.float32) assert_bijective_and_finite( Sigmoid(), x, y, event_ndims=0, atol=0., rtol=1e-4)
def testBijectiveAndFinite(self): permutation = np.int32([2, 0, 1]) x = np.random.randn(4, 2, 3) y = x[..., permutation] with self.test_session(): bijector = Permute(permutation=permutation, validate_args=True) assert_bijective_and_finite(bijector, x, y, rtol=1e-6, atol=0)
def testBijectiveAndFiniteSkewness1Tailweight3(self): with self.test_session(): bijector = tfb.SinhArcsinh(skewness=1., tailweight=3., validate_args=True) x = np.concatenate((-np.logspace(-2, 5, 1000), [0], np.logspace( -2, 5, 1000))).astype(np.float32) assert_bijective_and_finite( bijector, x, x, event_ndims=0, rtol=1e-3)
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)
def testBijectiveAndFiniteSkewness1Tailweight3(self): with self.test_session(): bijector = tfb.SinhArcsinh(skewness=1., tailweight=3., validate_args=True) x = np.concatenate((-np.logspace(-2, 5, 1000), [0], np.logspace( -2, 5, 1000))).astype(np.float32) assert_bijective_and_finite( bijector, x, x, event_ndims=0, rtol=1e-3)
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) assert_bijective_and_finite( tfb.Sigmoid(), x, y, event_ndims=0, atol=0., rtol=1e-4)
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)
def testBijectiveAndFinite(self): x = np.random.randn(4, 2, 3) y = np.reshape(x, [4, 1, 2, 3]) with self.test_session(): bijector = tfb.Reshape( event_shape_in=[2, 3], event_shape_out=[1, 2, 3], validate_args=True) assert_bijective_and_finite( bijector, x, y, event_ndims=2, rtol=1e-6, atol=0)
def testBijectiveAndFinite(self): x = np.random.randn(4, 2, 3) y = np.reshape(x, [4, 1, 2, 3]) with self.test_session(): bijector = Reshape(event_shape_in=[2, 3], event_shape_out=[1, 2, 3], validate_args=True) assert_bijective_and_finite(bijector, x, y, rtol=1e-6, atol=0)
def testBijectiveAndFiniteSkewnessNeg1Tailweight0p5(self): with self.test_session(): bijector = SinhArcsinh(skewness=-1., tailweight=0.5, validate_args=True) # Increasing upper logspace limit to 10 results in Inf due to y**2 being # Inf. x = np.concatenate((-np.logspace(-2, 9, 1000), [0], np.logspace( -2, 9, 1000))).astype(np.float32) assert_bijective_and_finite(bijector, x, x, rtol=1e-3)
def testBijectiveAndFinite(self): with self.test_session(): bijector = tfb.Weibull(scale=20., concentration=2., validate_args=True) x = np.linspace(1., 8., num=10).astype(np.float32) y = np.linspace( -np.expm1(-1 / 400.), -np.expm1(-16), num=10).astype(np.float32) assert_bijective_and_finite(bijector, x, y, event_ndims=0, rtol=1e-3)
def testBijectiveAndFiniteSkewnessNeg1Tailweight0p5(self): with self.test_session(): bijector = SinhArcsinh(skewness=-1., tailweight=0.5, validate_args=True) x = np.concatenate((-np.logspace(-2, 10, 1000), [0], np.logspace(-2, 10, 1000))).astype(np.float32) assert_bijective_and_finite(bijector, x, x, rtol=1e-3)
def testBijectiveAndFinite(self): permutation = np.int32([2, 0, 1]) x = np.random.randn(4, 2, 3) y = x[..., permutation] with self.test_session(): bijector = Permute(permutation=permutation, validate_args=True) assert_bijective_and_finite( bijector, x, y, event_ndims=1, rtol=1e-6, atol=0)
def testBijectiveAndFinite(self): with self.test_session(): bijector = Gumbel(loc=0., scale=3.0, event_ndims=0, validate_args=True) x = np.linspace(-10., 10., num=10).astype(np.float32) y = np.linspace(0.01, 0.99, num=10).astype(np.float32) assert_bijective_and_finite(bijector, x, y, rtol=1e-3)
def testBijectiveAndFinite(self): with self.cached_session(): bijector = Weibull( scale=20., concentration=2., validate_args=True) x = np.linspace(1., 8., num=10).astype(np.float32) y = np.linspace( -np.expm1(-1 / 400.), -np.expm1(-16), num=10).astype(np.float32) assert_bijective_and_finite(bijector, x, y, event_ndims=0, rtol=1e-3)
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 testBijectorEndpoints(self): with self.test_session(): for dtype in (np.float32, np.float64): bijector = SinhArcsinh( skewness=dtype(0.), tailweight=dtype(1.), validate_args=True) bounds = np.array( [np.finfo(dtype).min, np.finfo(dtype).max], dtype=dtype) # Note that the above bijector is the identity bijector. Hence, the # log_det_jacobian will be 0. Because of this we use atol. assert_bijective_and_finite(bijector, bounds, bounds, atol=2e-6)
def testBijectiveAndFiniteSkewnessNeg1Tailweight0p5(self): with self.test_session(): bijector = SinhArcsinh(skewness=-1., tailweight=0.5, validate_args=True) # Increasing upper logspace limit to 10 results in Inf due to y**2 being # Inf. x = np.concatenate((-np.logspace(-2, 9, 1000), [0], np.logspace(-2, 9, 1000))).astype(np.float32) assert_bijective_and_finite(bijector, x, x, rtol=1e-3)
def testBijectiveAndFiniteWithPositiveHingeSoftness32Bit(self): with self.cached_session(): bijector = Softplus(hinge_softness=1.23) 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, event_ndims=0, rtol=1e-2, atol=1e-2)
def testBijectiveAndFiniteAxis(self): permutation = np.int32([1, 0]) x = np.random.randn(4, 2, 3) y = x[..., permutation, :] with self.test_session(): bijector = tfb.Permute( permutation=permutation, axis=-2, validate_args=True) assert_bijective_and_finite( bijector, x, y, event_ndims=2, rtol=1e-6, atol=0)
def testBijectiveAndFiniteWithNegativeHingeSoftness32Bit(self): with self.test_session(): bijector = tfb.Softplus(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, event_ndims=0, rtol=1e-2, atol=1e-2)
def testBijectiveAndFinite32bit(self): with self.test_session(): bijector = tfb.Softplus() 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, event_ndims=0, rtol=1e-2, atol=1e-2)
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 = tfb.SoftmaxCentered() 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] assert_bijective_and_finite(softmax, x, y, event_ndims=1)
def testBijectiveAndFinite(self): with self.test_session(): concentration1 = 1.2 concentration0 = 2. bijector = Kumaraswamy(concentration1=concentration1, concentration0=concentration0, validate_args=True) # Omitting the endpoints 0 and 1, since idlj will be infinity at these # endpoints. y = np.linspace(.01, 0.99, num=10).astype(np.float32) x = 1 - (1 - y**concentration1)**concentration0 assert_bijective_and_finite(bijector, x, y, rtol=1e-3)
def testBijectiveAndFinite(self): with self.test_session(): softmax = 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] assert_bijective_and_finite(softmax, x, y)
def testBijectiveAndFinite(self): with self.test_session(): concentration1 = 1.2 concentration0 = 2. bijector = Kumaraswamy( concentration1=concentration1, concentration0=concentration0, validate_args=True) # Omitting the endpoints 0 and 1, since idlj will be infinity at these # endpoints. y = np.linspace(.01, 0.99, num=10).astype(np.float32) x = 1 - (1 - y ** concentration1) ** concentration0 assert_bijective_and_finite(bijector, x, y, rtol=1e-3)
def testBijectiveAndFiniteSkewnessNeg1Tailweight0p5(self): with self.test_session(): bijector = SinhArcsinh(skewness=-1., tailweight=0.5, validate_args=True) x = np.concatenate((-np.logspace(-2, 10, 1000), [0], np.logspace( -2, 10, 1000))).astype(np.float32) assert_bijective_and_finite(bijector, x, x, rtol=1e-3)
def testBijectiveAndFinite(self): with self.test_session(): bijector = Gumbel(loc=0., scale=3.0, validate_args=True) x = np.linspace(-10., 10., num=10).astype(np.float32) y = np.linspace(0.01, 0.99, num=10).astype(np.float32) assert_bijective_and_finite(bijector, x, y, event_ndims=0, rtol=1e-3)
def testBijectiveAndFinite(self): with self.test_session(): bijector = tfb.Exp() 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, event_ndims=0)
def testBijectiveAndFinite(self): with self.test_session(): bijector = tfb.Exp() 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, event_ndims=0)
def testBijectiveAndFinite(self): with self.test_session(): ordered = Ordered() x = np.sort(self._rng.randn(3, 10), axis=-1).astype(np.float32) y = (self._rng.randn(3, 10)).astype(np.float32) assert_bijective_and_finite(ordered, x, y, event_ndims=1)