예제 #1
0
def test_deepgp_can_compute_kl_regularization():
    dgp = deepgp.DeepGP(
        layers=(deepgp.Layer(kernels.RBFKernel()),
                deepgp.Layer(kernels.RBFKernel())),
        likelihood=deepgp.ExpPoisson(),
    )
    dgp(torch.randn(10, 1))
    assert torch.is_tensor(dgp.kl_regularization)
    assert dgp.kl_regularization > 0.0
예제 #2
0
def test_deepgp_can_backward_with_more_than_one_dim():
    dgp = deepgp.DeepGP(
        layers=(deepgp.Layer(kernels.RBFKernel(),
                             input_dim=2,
                             output_dim=1,
                             grid_num=4), ),
        likelihood=deepgp.ExpPoisson(),
    )
    dgp.forward(torch.randn(10, 2)).mean.sum().backward()
예제 #3
0
def test_deepgp_can_compute_outputs():
    dgp = deepgp.DeepGP(
        layers=(deepgp.Layer(kernels.RBFKernel()),
                deepgp.Layer(kernels.RBFKernel())),
        likelihood=deepgp.ExpPoisson(),
    )
    loss = dgp(torch.randn(10, 1)).log_prob(torch.ones(10, 1)).sum()
    loss.backward()
    loss = dgp(torch.randn(10, 1)).log_prob(torch.ones(10, 1)).sum()
    loss.backward()
    dgp.eval()
    dgp(torch.randn(10, 1))
예제 #4
0
def test_deepgp_can_compute_negative_elbo_loss():
    dgp = deepgp.DeepGP(
        layers=(deepgp.Layer(kernels.RBFKernel()),
                deepgp.Layer(kernels.RBFKernel())),
        likelihood=deepgp.ExpPoisson(),
    )
    elbo = dgp.negative_elbo(torch.randn(10, 1),
                             torch.ones((10, 1)),
                             num_data=10)
    elbo.backward()
    elbo = dgp.negative_elbo(torch.randn(10, 1),
                             torch.ones((10, 1)),
                             num_data=10)
    elbo.backward()
    assert torch.is_tensor(elbo)
예제 #5
0
    with pytest.raises(ValueError):
        deepgp.Layer(kernels.RBFKernel(), grid_bound=0)
    with pytest.raises(ValueError):
        deepgp.Layer(kernels.RBFKernel(), grid_num=0)


def test_deepgplayer_checks_input_dims():
    dgp = deepgp.Layer(kernels.RBFKernel(),
                       input_dim=2,
                       output_dim=3,
                       grid_num=4)
    with pytest.raises(ValueError):
        dgp(torch.rand(10, 10))


likelihoods = (deepgp.ExpPoisson(), deepgp.Gaussian(),
               deepgp.LogisticBernoulli())


@pytest.mark.parametrize("likelihood", likelihoods)
def test_likelihoods_check_inputs(likelihood):
    with pytest.raises(ValueError):
        likelihood(torch.randn(5, 3))
    with pytest.raises(ValueError):
        likelihood(torch.randn(1, 1, 1))
    likelihood(torch.randn(10, 1))


def test_deepgp_can_compute_outputs():
    dgp = deepgp.DeepGP(
        layers=(deepgp.Layer(kernels.RBFKernel()),