Exemple #1
0
def test_mean_function_VSGP():
    X, y, Xnew, ynew, kernel, mean_fn = _pre_test_mean_function()
    Xu = X[::20].clone()
    likelihood = Gaussian()
    model = VariationalSparseGP(X, y, kernel, Xu, likelihood, mean_function=mean_fn)
    model.optimize(optim.Adam({"lr": 0.02}))
    _post_test_mean_function(model, Xnew, ynew)
Exemple #2
0
def test_mean_function_VSGP():
    X, y, Xnew, ynew, kernel, mean_fn = _pre_test_mean_function()
    Xu = X[::20].clone()
    likelihood = Gaussian()
    model = VariationalSparseGP(X,
                                y,
                                kernel,
                                Xu,
                                likelihood,
                                mean_function=mean_fn)
    model.optimize(optim.Adam({"lr": 0.02}))
    _post_test_mean_function(model, Xnew, ynew)
Exemple #3
0
def test_inference_whiten_vsgp():
    N = 1000
    X = dist.Uniform(torch.zeros(N), torch.ones(N)*5).sample()
    y = 0.5 * torch.sin(3*X) + dist.Normal(torch.zeros(N), torch.ones(N)*0.5).sample()
    kernel = RBF(input_dim=1)
    Xu = torch.arange(0, 5.5, 0.5)

    vsgp = VariationalSparseGP(X, y, kernel, Xu, Gaussian(), whiten=True)
    vsgp.optimize(optim.Adam({"lr": 0.01}), num_steps=1000)

    Xnew = torch.arange(0, 5.05, 0.05)
    loc, var = vsgp(Xnew, full_cov=False)
    target = 0.5 * torch.sin(3*Xnew)

    assert_equal((loc - target).abs().mean().item(), 0, prec=0.07)
Exemple #4
0
def test_inference_whiten_vsgp():
    N = 1000
    X = dist.Uniform(torch.zeros(N), torch.ones(N) * 5).sample()
    y = 0.5 * torch.sin(3 * X) + dist.Normal(torch.zeros(N),
                                             torch.ones(N) * 0.5).sample()
    kernel = RBF(input_dim=1)
    Xu = torch.arange(0, 5.5, 0.5)

    vsgp = VariationalSparseGP(X, y, kernel, Xu, Gaussian(), whiten=True)
    vsgp.optimize(optim.Adam({"lr": 0.01}), num_steps=1000)

    Xnew = torch.arange(0, 5.05, 0.05)
    loc, var = vsgp(Xnew, full_cov=False)
    target = 0.5 * torch.sin(3 * Xnew)

    assert_equal((loc - target).abs().mean().item(), 0, prec=0.07)