示例#1
0
    def test_simple_ildj(self):
        def f(x):
            return np.exp(x)

        f_inv = ildj(f, 0.1)
        onp.testing.assert_allclose(f_inv(2.0), -np.log(2.))

        def f2(x):
            return np.exp(x)

        f2_inv = ildj(f2, np.zeros(3))
        onp.testing.assert_allclose(f2_inv(2 * np.ones(2)), -2 * np.log(2.))
示例#2
0
    def test_bad_inverse(self):
        def f(x):
            return np.exp(x), x + 1.

        f_ildj = ildj(f, 0.)
        with self.assertRaises(ValueError):
            f_ildj(2.0, 3.)
示例#3
0
 def wrapped(*args):
     mapped_args = mapping_fn(*args)
     ildjs = inverse.ildj(mapping_fn, *args)(mapped_args)
     return target_log_prob(mapped_args) - np.sum(
         np.array(tree_util.tree_leaves(ildjs)))