def f(r, y): PD = r.dot(r.T) L = gpu_cholesky(PD) A = gpu_solve_lower_triangular(L, y) AAT = aesara.tensor.dot(A, A.T) B = AAT + aesara.tensor.eye(N) LB = gpu_cholesky(B) return aesara.tensor.sum(aesara.tensor.log(aesara.tensor.diag(LB)))
def test_cholesky_grad(): rng = np.random.RandomState(utt.fetch_seed()) r = rng.randn(5, 5).astype(config.floatX) # The dots are inside the graph since Cholesky needs separable matrices # Check the default. utt.verify_grad(lambda r: gpu_cholesky(r.dot(r.T)), [r], 3, rng) # Explicit lower-triangular. utt.verify_grad(lambda r: GpuCholesky(lower=True)(r.dot(r.T)), [r], 3, rng) # Explicit upper-triangular. utt.verify_grad(lambda r: GpuCholesky(lower=False)(r.dot(r.T)), [r], 3, rng)