예제 #1
0
    def validate(self, input_mat):
        x = aesara.tensor.matrix()
        f = aesara.function([x], self.op(x))
        out = f(input_mat)
        svd_diag = np.linalg.svd(input_mat, compute_uv=False)
        numpy_out = np.sum(np.log(np.abs(svd_diag)))

        # Compare the result computed to the expected value.
        np.allclose(numpy_out, out)

        # Test gradient:
        verify_grad(self.op, [input_mat])
예제 #2
0
    def test_grad(self):
        np.random.seed(42)

        def func(chol_vec, delta):
            chol = at.stack([
                at.stack([at.exp(0.1 * chol_vec[0]), 0]),
                at.stack([chol_vec[1], 2 * at.exp(chol_vec[2])]),
            ])
            cov = at.dot(chol, chol.T)
            return MvNormalLogp()(cov, delta)

        chol_vec_val = floatX(np.array([0.5, 1.0, -0.1]))

        delta_val = floatX(np.random.randn(1, 2))
        verify_grad(func, [chol_vec_val, delta_val])

        delta_val = floatX(np.random.randn(5, 2))
        verify_grad(func, [chol_vec_val, delta_val])
예제 #3
0
 def test_grad(self):
     verify_grad(i0e, [0.5])
     verify_grad(i0e, [-2.0])
     verify_grad(i0e, [[0.5, -2.0]])
     verify_grad(i0e, [[[0.5, -2.0]]])
예제 #4
0
 def test_grad(self):
     x = np.linspace(0, 1, 100)
     y = x * x
     spline = SplineWrapper(
         interpolate.InterpolatedUnivariateSpline(x, y, k=1))
     verify_grad(spline, [0.5])