Beispiel #1
0
 def _build_conditional(self, Xnew):
     Xs, f = self.Xs, self.f
     X = cartesian(*Xs)
     delta = f - self.mean_func(X)
     covs = [stabilize(cov(Xi)) for cov, Xi in zip(self.cov_funcs, Xs)]
     chols = [cholesky(cov) for cov in covs]
     cholTs = [at.transpose(chol) for chol in chols]
     Kss = self.cov_func(Xnew)
     Kxs = self.cov_func(X, Xnew)
     Ksx = at.transpose(Kxs)
     alpha = kron_solve_lower(chols, delta)
     alpha = kron_solve_upper(cholTs, alpha)
     mu = at.dot(Ksx, alpha).ravel() + self.mean_func(Xnew)
     A = kron_solve_lower(chols, Kxs)
     cov = stabilize(Kss - at.dot(at.transpose(A), A))
     return mu, cov
Beispiel #2
0
def test_kron_solve_lower():
    np.random.seed(1)
    # Create random matrices
    Ls = [np.tril(np.random.rand(3, 3)) for i in range(3)]
    # Create random vector with correct shape
    tot_size = np.prod([L.shape[1] for L in Ls])
    x = np.random.rand(tot_size).reshape((tot_size, 1))
    # Construct entire kronecker product then solve
    big = kronecker(*Ls)
    slow_ans = at.slinalg.solve_lower_triangular(big, x)
    # Use tricks to avoid construction of entire kronecker product
    fast_ans = kron_solve_lower(Ls, x)
    np.testing.assert_array_almost_equal(slow_ans.eval(), fast_ans.eval())
Beispiel #3
0
def test_kron_solve_lower():
    np.random.seed(1)
    # Create random matrices
    Ls = [np.tril(np.random.rand(3, 3)) for i in range(3)]
    # Create random vector with correct shape
    tot_size = np.prod([L.shape[1] for L in Ls])
    x = np.random.rand(tot_size).reshape((tot_size, 1))
    # Construct entire kronecker product then solve
    big = kronecker(*Ls)
    slow_ans = tt.slinalg.solve_lower_triangular(big, x)
    # Use tricks to avoid construction of entire kronecker product
    fast_ans = kron_solve_lower(Ls, x)
    np.testing.assert_array_almost_equal(slow_ans.eval(), fast_ans.eval())