def testBijector(self): with self.test_session(): for fwd in [ bijectors.Identity(), bijectors.Exp(event_ndims=1), bijectors.Affine(shift=[0., 1.], scale_diag=[2., 3.], event_ndims=1), bijectors.Softplus(event_ndims=1), bijectors.SoftmaxCentered(event_ndims=1), bijectors.SigmoidCentered(), ]: rev = bijectors.Invert(fwd) self.assertEqual("_".join(["invert", fwd.name]), rev.name) x = [[[1., 2.], [2., 3.]]] self.assertAllClose( fwd.inverse(x).eval(), rev.forward(x).eval()) self.assertAllClose( fwd.forward(x).eval(), rev.inverse(x).eval()) self.assertAllClose( fwd.forward_log_det_jacobian(x).eval(), rev.inverse_log_det_jacobian(x).eval()) self.assertAllClose( fwd.inverse_log_det_jacobian(x).eval(), rev.forward_log_det_jacobian(x).eval())
def testShapeGetters(self): with self.test_session(): bijector = bijectors.Invert(bijectors.SigmoidCentered(validate_args=True)) x = tensor_shape.TensorShape([2]) y = tensor_shape.TensorShape([]) self.assertAllEqual(y, bijector.forward_event_shape(x)) self.assertAllEqual( y.as_list(), bijector.forward_event_shape_tensor(x.as_list()).eval()) self.assertAllEqual(x, bijector.inverse_event_shape(y)) self.assertAllEqual( x.as_list(), bijector.inverse_event_shape_tensor(y.as_list()).eval())