Beispiel #1
0
def grad_post_mean(idx_train, w_train, idx_test, w_test, u, gp_params,
                   indep_noise, y, grad_u, gz):
    # grad_u.shape: (#u, #gp_params)
    n_gp_params = len(gp_params)
    len_u = len(u)

    v1 = Kinv_y(idx_train, w_train, u, len_u, indep_noise, y)
    v2_1 = interp_to_u(idx_train, w_train, len_u, v1)

    grad_gp_params = np.empty_like(gp_params)
    for p in xrange(n_gp_params):
        v2 = toeplitz_matvec(grad_u[:, p], v2_1, len_u)
        v3_1 = interp_from_u(idx_train, w_train, v2)
        v3_2 = Kinv_y(idx_train, w_train, u, len_u, indep_noise, v3_1)
        v3_3 = interp_to_u(idx_train, w_train, len_u, v3_2)
        v3 = toeplitz_matvec(u, v3_3, len_u)
        g = interp_from_u(idx_test, w_test, v2 - v3)
        grad_gp_params[p] = g.dot(gz)

    h1 = Kinv_y(idx_train, w_train, u, len_u, indep_noise, v1)
    h2 = interp_to_u(idx_train, w_train, len_u, h1)
    h3 = toeplitz_matvec(u, h2, len_u)
    h = -interp_from_u(idx_test, w_test, h3)
    grad_noise = h.dot(gz)

    return grad_gp_params, np.asarray(grad_noise)
Beispiel #2
0
def post_cov_y(idx_train, w_train, idx_test, w_test, u, len_u, indep_noise, y):
    v1 = interp_to_u(idx_test, w_test, len_u, y[0])
    v2 = toeplitz_matvec(u, v1, len_u)
    v3 = interp_from_u(idx_train, w_train, v2)
    v4 = Kinv_y(idx_train, w_train, u, len_u, indep_noise, v3)
    v5 = interp_to_u(idx_train, w_train, len_u, v4)
    v6 = toeplitz_matvec(u, v5, len_u)
    f = interp_from_u(idx_test, w_test, v2 - v6)
    #f = f + regularizer * y
    return f[np.newaxis]
Beispiel #3
0
def post_mean(idx_train, w_train, idx_test, w_test, u, len_u, indep_noise, y):
    #print 'condition number', cond(idx_train, w_train, u, len_u, indep_noise)
    v1 = Kinv_y(idx_train, w_train, u, len_u, indep_noise, y)
    v2 = interp_to_u(idx_train, w_train, len_u, v1)
    v3 = toeplitz_matvec(u, v2, len_u)
    f = interp_from_u(idx_test, w_test, v3)
    return f
Beispiel #4
0
def Ky(idx, w, u, len_u, indep_noise, y):
    """
    compute K(idx, w, u, sigma2) y
    """
    v1 = interp_to_u(idx, w, len_u, y)
    v2 = toeplitz_matvec(u, v1, len_u)
    v3 = interp_from_u(idx, w, v2)
    return v3 + indep_noise * y
Beispiel #5
0
def grad_cov_ys(idx_train, w_train, idx_test, w_test, u, gp_params,
                indep_noise, ys, grad_u, gz):
    """
    ys.shape: (#z, #test)
    grad_u.shape: (#u, #params)
    gz.shape: (#z, #test)
    """
    ny = ys.shape[0]
    n_params = grad_u.shape[1]
    len_u = len(u)

    grad_gp_params = np.zeros_like(gp_params)
    grad_noise = 0

    for i in xrange(ny):

        v1 = interp_to_u(idx_test, w_test, len_u, ys[i])
        v3 = toeplitz_matvec(u, v1, len_u)
        v4_1 = interp_from_u(idx_train, w_train, v3)
        v4 = Kinv_y(idx_train, w_train, u, len_u, indep_noise, v4_1)
        v5_1 = interp_to_u(idx_train, w_train, len_u, v4)

        for p in xrange(n_params):
            grad_up = grad_u[:, p]

            v2 = toeplitz_matvec(grad_up, v1, len_u)
            v5 = toeplitz_matvec(grad_up, v5_1, len_u)
            v6_1 = interp_from_u(idx_train, w_train, v5 - v2)
            v6_2 = Kinv_y(idx_train, w_train, u, len_u, indep_noise, v6_1)
            v6_3 = interp_to_u(idx_train, w_train, len_u, v6_2)
            v6 = toeplitz_matvec(u, v6_3, len_u)
            g = interp_from_u(idx_test, w_test, v2 - v5 + v6)
            grad_gp_params[p] += g.dot(gz[i])

        h1 = Kinv_y(idx_train, w_train, u, len_u, indep_noise, v4)
        h2 = interp_to_u(idx_train, w_train, len_u, h1)
        h3 = toeplitz_matvec(u, h2, len_u)
        h = interp_from_u(idx_test, w_test, h3)
        grad_noise += h.dot(gz[i])

    grad_ys = post_cov_ys(idx_train, w_train, idx_test, w_test, u, len_u,
                          indep_noise, gz)

    return grad_gp_params, np.asarray(grad_noise), grad_ys