Exemple #1
0
def gp_matrix(x0, x1, a, K):
    """Constructs GP covariance matrix between two point tuples x0 and x1"""
    n0 = len(x0)
    n1 = len(x1)
    for k0 in range(n0):
        for k1 in range(n1):
            K[k0, k1] = a[1]*kern_sqexp(x0[k0, :], x1[k1, :], a[0])
Exemple #2
0
    def predict(self, x):
        if not self.trained:
            raise RuntimeError('Need to train() before predict()')

        Kstar = self.hyparms[1]*np.fromiter(
            (kern_sqexp(xi, xj, self.hyparms[0])
             for xi in self.xtrain for xj in x),
            float).reshape(self.xtrain.shape[0], x.shape[0])

        return Kstar.T.dot(self.Kyinv_y)
Exemple #3
0
def test_kern_sqexp():
    points = np.array([[0.0, 0.0], [0.0, 1.5], [1.3, 1.3]])
    h0 = 1.2
    for x in points:
        for x0 in points:
            k1 = kernels.kern_sqexp(x, x0, h0)
            k1a = kernels.kern_sqexp_multiscale(x, x0, np.array([h0, h0]))
            k2 = np.exp(-0.5 * np.sum((x - x0)**2) / h0**2)

            print(k1)
            print(",,,,")
            print(k1a)
            assert np.array_equal(k1, k2)
            assert np.array_equal(k1a, k2)
Exemple #4
0
def build_K(xa, xb, hyp, K):
    for i in np.arange(len(xa)):
        for j in np.arange(len(xb)):
            K[i, j] = kern_sqexp(xa[i], xb[j], hyp[0])