Exemplo n.º 1
0
def test_obs(x):
    prior = Measure()
    f = GP(EQ(), measure=prior)
    noise = 0.1

    # Generate some data.
    w = B.rand(B.shape(x)[0]) + 1e-2
    y = f(x, 0.1).sample()

    # Set some observations to be missing.
    y_missing = y.copy()
    y_missing[::2] = np.nan

    # Check dense case.
    gpar = GPAR()
    obs = gpar._obs(x, None, y_missing, w, f, noise)
    assert isinstance(obs, Obs)
    approx(
        prior.logpdf(obs),
        f(x[1::2], noise / w[1::2]).logpdf(y[1::2]),
        atol=1e-6,
    )

    # Check sparse case.
    gpar = GPAR(x_ind=x)
    obs = gpar._obs(x, x, y_missing, w, f, noise)
    assert isinstance(obs, SparseObs)
    approx(
        prior.logpdf(obs),
        f(x[1::2], noise / w[1::2]).logpdf(y[1::2]),
        atol=1e-6,
    )
Exemplo n.º 2
0
def test_obs():
    graph = Graph()
    f = GP(EQ(), graph=graph)
    e = GP(1e-8 * Delta(), graph=graph)

    # Check that it produces the correct observations.
    x = B.linspace(0, 0.1, 10, dtype=torch.float64)
    y = f(x).sample()

    # Set some observations to be missing.
    y_missing = y.clone()
    y_missing[::2] = np.nan

    # Check dense case.
    gpar = GPAR()
    obs = gpar._obs(x, None, y_missing, f, e)
    yield eq, type(obs), Obs
    yield approx, y, (f | obs).mean(x)

    # Check sparse case.
    gpar = GPAR(x_ind=x)
    obs = gpar._obs(x, x, y_missing, f, e)
    yield eq, type(obs), SparseObs
    yield approx, y, (f | obs).mean(x)