Ejemplo n.º 1
0
def visual_test_sample_gp_no_noise():
    n_in = 3
    x_in = np.array([3.5, 10.5, 12.5], dtype=np.float64)
    f_in = np.array([3.0, 10.0, 12.0], dtype=np.float64)

    n_out = 20
    ell = 10.0
    x_out = np.array(range(n_out), dtype=np.float64)

    mean_out, S_out = gp.squared_exponential_conditional(x_in, f_in, x_out, ell, 0.0)
    mean_out = np.array(mean_out)
    S_out = np.array(S_out)


    nsamples = 5
    eval, evec = npl.eigh(S_out)
    eval = np.sqrt(eval)
    L = evec.dot(diag(eval))
    C = npl.cholesky(S_out)

    figure()
    for i in range(nsamples):
        r = np.random.normal(size=n_out)
        s = L.dot(r)
        plot(s + mean_out)
        grid()

    figure()
    for i in range(nsamples):
        r = np.random.normal(size=n_out)
        s = C.dot(r)
        plot(s + mean_out)
        grid()
Ejemplo n.º 2
0
def visual_test_sample_gp_noise():
    x_in = np.array([3.5, 10.5, 12.5, 15.0, 20.0], dtype=np.float64)
    f_in = np.array([1.0, 10.0, 7.0, 0.0, 5.0], dtype=np.float64)
    n_in = x_in.shape[0]

    n_out = 20
    ell = .1
    sigma_noise = 0.1
    #x_out = np.array(range(n_out), dtype=np.float64)
    x_out = x_in.copy()
    n_out = x_out.shape[0]

    mean_out, S_out = gp.squared_exponential_conditional(x_in, f_in, x_out, ell, sigma_noise)
    mean_out = np.array(mean_out)
    S_out = np.array(S_out)

    nsamples = 1
    eval, evec = npl.eigh(S_out)
    eval = np.sqrt(eval)
    L = evec.dot(diag(eval))
    C = npl.cholesky(S_out)

    figure()
    plot(f_in)
    for i in range(nsamples):
        r = np.random.normal(size=n_out)
        r[:] = 0
        s = L.dot(r)
        plot(s + mean_out)
        grid()

    figure()
    plot(f_in)
    for i in range(nsamples):
        r = np.random.normal(size=n_out)
        r[:] = 0
        s = C.dot(r)
        plot(s + mean_out)
        grid()