def testJacobianWithTensors(self):
     bijector = tfb.CholeskyToInvCholesky()
     x = np.array([[[3., 0.], [1., 4.]], [[2., 0.], [7., 1.]]],
                  dtype=np.float32)
     fldj = bijector.forward_log_det_jacobian(x, event_ndims=2)
     fldj0 = bijector.forward_log_det_jacobian(x[0], event_ndims=2)
     fldj1 = bijector.forward_log_det_jacobian(x[1], event_ndims=2)
     fldj_, fldj0_, fldj1_ = self.evaluate([fldj, fldj0, fldj1])
     self.assertAllClose(fldj_[0], fldj0_)
     self.assertAllClose(fldj_[1], fldj1_)
 def testBijector(self):
     bijector = tfb.CholeskyToInvCholesky()
     self.assertEqual("cholesky_to_inv_cholesky", bijector.name)
     x = np.array([[3., 0.], [2., 7.]], dtype=np.float32)
     m = x.dot(x.T)
     m_inv = np.linalg.inv(m)
     y = np.linalg.cholesky(m_inv)
     x_fwd = bijector.forward(x)
     y_inv = bijector.inverse(x_fwd)
     x_fwd_, y_inv_ = self.evaluate([x_fwd, y_inv])
     self.assertAllClose(y, x_fwd_, atol=1.e-5, rtol=1.e-5)
     self.assertAllClose(x, y_inv_, atol=1.e-5, rtol=1.e-5)
 def testBijectorWithTensors(self):
     bijector = tfb.CholeskyToInvCholesky()
     x = np.array([[[3., 0.], [1., 4.]], [[2., 0.], [7., 1.]]],
                  dtype=np.float32)
     y = bijector.forward(x)
     y0 = bijector.forward(x[0, :])
     y1 = bijector.forward(x[1, :])
     y_inv = bijector.inverse(y)
     y_inv0 = bijector.inverse(y[0, :])
     y_inv1 = bijector.inverse(y[1, :])
     y_, y0_, y1_, y_inv_, y_inv0_, y_inv1_ = self.evaluate(
         [y, y0, y1, y_inv, y_inv0, y_inv1])
     self.assertAllClose(y_[0, :], y0_, atol=1.e-5, rtol=1.e-5)
     self.assertAllClose(y_[1, :], y1_, atol=1.e-5, rtol=1.e-5)
     self.assertAllClose(y_inv_[0, :], y_inv0_, atol=1.e-5, rtol=1.e-5)
     self.assertAllClose(y_inv_[1, :], y_inv1_, atol=1.e-5, rtol=1.e-5)
     self.assertAllClose(y_inv_, x, atol=1.e-5, rtol=1.e-5)
Exemple #4
0
 def testJacobian(self):
     cholesky_to_vector = tfb.Invert(
         tfb.FillScaleTriL(diag_bijector=tfb.Exp(), diag_shift=None))
     bijector = tfb.CholeskyToInvCholesky()
     for x in [
             np.array([[2.]], dtype=np.float64),
             np.array([[2., 0.], [3., 4.]], dtype=np.float64),
             np.array([[2., 0., 0.], [3., 4., 0.], [5., 6., 7.]],
                      dtype=np.float64)
     ]:
         fldj = bijector.forward_log_det_jacobian(x, event_ndims=2)
         fldj_numerical = self._get_fldj_numerical(
             bijector,
             x,
             event_ndims=2,
             input_to_vector=cholesky_to_vector,
             output_to_vector=cholesky_to_vector)
         fldj_, fldj_numerical_ = self.evaluate([fldj, fldj_numerical])
         self.assertAllClose(fldj_, fldj_numerical_, rtol=1e-2)
Exemple #5
0
 def testJacobian(self):
   cholesky_to_vector = tfb.Chain([
       tfb.Invert(tfb.FillTriangular()),
       tfb.TransformDiagonal(tfb.Invert(tfb.Exp()))
   ])
   bijector = tfb.CholeskyToInvCholesky()
   for x in [np.array([[2.]],
                      dtype=np.float64),
             np.array([[2., 0.], [3., 4.]],
                      dtype=np.float64),
             np.array([[2., 0., 0.], [3., 4., 0.], [5., 6., 7.]],
                      dtype=np.float64)]:
     fldj = bijector.forward_log_det_jacobian(x, event_ndims=2)
     fldj_numerical = self._get_fldj_numerical(
         bijector, x, event_ndims=2, eps=1.e-6,
         input_to_vector=cholesky_to_vector,
         output_to_vector=cholesky_to_vector)
     fldj_, fldj_numerical_ = self.evaluate([fldj, fldj_numerical])
     self.assertAllClose(fldj_, fldj_numerical_)