def test_matches_tanh_bijector_double(self): squash = SquashBijector() tanh = tfp.bijectors.Tanh() data = np.linspace(-10, 10, 100).astype(np.float64) squash_forward = squash.forward(data) tanh_forward = tanh.forward(data) np.testing.assert_equal(squash_forward.numpy(), tanh_forward.numpy()) squash_ildj = squash.inverse_log_det_jacobian(squash_forward, event_ndims=0) tanh_ildj = tanh.inverse_log_det_jacobian(tanh_forward, event_ndims=0) np.testing.assert_allclose(squash_ildj.numpy(), tanh_ildj.numpy())
def test_matches_tanh_bijector_double(self): squash = SquashBijector() tanh = tfp.bijectors.Tanh() data = np.linspace(-10, 10, 100).astype(np.float64) squash_forward = squash.forward(data) tanh_forward = tanh.forward(data) self.assertAllClose(self.evaluate(squash_forward), self.evaluate(tanh_forward)) squash_ildj = squash.inverse_log_det_jacobian(squash_forward, event_ndims=0) tanh_ildj = tanh.inverse_log_det_jacobian(tanh_forward, event_ndims=0) self.assertAllClose(self.evaluate(squash_ildj), self.evaluate(tanh_ildj))
def test_matches_tanh_bijector_single(self): squash = SquashBijector() tanh = tfp.bijectors.Tanh() data = np.linspace(-5, 5, 100).astype(np.float32) squash_forward = squash.forward(data) tanh_forward = tanh.forward(data) np.testing.assert_equal(squash_forward.numpy(), tanh_forward.numpy()) squash_ildj = squash.inverse_log_det_jacobian(squash_forward, event_ndims=0) tanh_ildj = tanh.inverse_log_det_jacobian(tanh_forward, event_ndims=0) tanh_isfinite_mask = np.where(np.isfinite(tanh_ildj)) np.testing.assert_allclose(tanh_ildj.numpy()[tanh_isfinite_mask], squash_ildj.numpy()[tanh_isfinite_mask], rtol=1e-3)
def test_matches_tanh_bijector_single(self): squash = SquashBijector() tanh = tfp.bijectors.Tanh() data = np.linspace(-5, 5, 100).astype(np.float32) squash_forward = squash.forward(data) tanh_forward = tanh.forward(data) self.assertAllClose(self.evaluate(squash_forward), self.evaluate(tanh_forward)) squash_ildj = squash.inverse_log_det_jacobian(squash_forward, event_ndims=0) tanh_ildj = tanh.inverse_log_det_jacobian(tanh_forward, event_ndims=0) tanh_finite_mask = tf.where(tf.is_finite(tanh_ildj)) self.assertAllClose( self.evaluate(tf.gather(tanh_ildj, tanh_finite_mask)), self.evaluate(tf.gather(squash_ildj, tanh_finite_mask)), rtol=1e-3)