Ejemplo n.º 1
0
def test_active_dims_disjoint_ok():
    k1 = Matern52(2, variance, lengthscale[0], active_dims=[0, 1])
    k2 = Matern32(1, variance, lengthscale[0], active_dims=[2])
    Sum(k1, k2)
Ejemplo n.º 2
0
def test_active_dims_overlap_ok():
    k1 = Matern52(2, variance, lengthscale[0], active_dims=[0, 1])
    k2 = Matern32(2, variance, lengthscale[0], active_dims=[1, 2])
    Sum(k1, k2)
Ejemplo n.º 3
0
from collections import namedtuple

import pytest
import torch

import pyro
from pyro.contrib.gp.kernels import Matern52, WhiteNoise
from pyro.contrib.gp.util import conditional
from tests.common import assert_equal

T = namedtuple("TestConditional",
               ["Xnew", "X", "kernel", "f_loc", "f_scale_tril", "loc", "cov"])

Xnew = torch.tensor([[2., 3.], [4., 6.]])
X = torch.tensor([[1., 5.], [2., 1.], [3., 2.]])
kernel = Matern52(input_dim=2)
Kff = kernel(X) + torch.eye(3) * 1e-6
Lff = Kff.potrf(upper=False)
pyro.set_rng_seed(123)
f_loc = torch.rand(3)
f_scale_tril = torch.rand(3, 3).tril(-1) + torch.rand(3).exp().diag()
f_cov = f_scale_tril.matmul(f_scale_tril.t())

TEST_CASES = [
    T(Xnew, X, kernel, torch.zeros(3), Lff, torch.zeros(2), None),
    T(Xnew, X, kernel, torch.zeros(3), None, torch.zeros(2), None),
    T(Xnew, X, kernel, f_loc, Lff, None, kernel(Xnew)),
    T(X, X, kernel, f_loc, f_scale_tril, f_loc, f_cov),
    T(X, X, kernel, f_loc, None, f_loc, torch.zeros(3, 3)),
    T(Xnew, X, WhiteNoise(input_dim=2), f_loc, f_scale_tril, torch.zeros(2),
      torch.eye(2)),
Ejemplo n.º 4
0
X = torch.tensor([[1.0, 0.0, 1.0], [2.0, 1.0, 3.0]])
Z = torch.tensor([[4.0, 5.0, 6.0], [3.0, 1.0, 7.0], [3.0, 1.0, 2.0]])

TEST_CASES = [
    T(Constant(3, variance), X=X, Z=Z, K_sum=18),
    T(
        Brownian(1, variance),
        # only work on 1D input
        X=X[:, 0],
        Z=Z[:, 0],
        K_sum=27),
    T(Cosine(3, variance, lengthscale), X=X, Z=Z, K_sum=-0.193233),
    T(Linear(3, variance), X=X, Z=Z, K_sum=291),
    T(Exponential(3, variance, lengthscale), X=X, Z=Z, K_sum=2.685679),
    T(Matern32(3, variance, lengthscale), X=X, Z=Z, K_sum=3.229314),
    T(Matern52(3, variance, lengthscale), X=X, Z=Z, K_sum=3.391847),
    T(Periodic(3, variance, lengthscale, period=torch.ones(1)),
      X=X,
      Z=Z,
      K_sum=18),
    T(Polynomial(3, variance, degree=2), X=X, Z=Z, K_sum=7017),
    T(RationalQuadratic(3, variance, lengthscale, scale_mixture=torch.ones(1)),
      X=X,
      Z=Z,
      K_sum=5.684670),
    T(RBF(3, variance, lengthscale), X=X, Z=Z, K_sum=3.681117),
    T(WhiteNoise(3, variance, lengthscale), X=X, Z=Z, K_sum=0),
    T(WhiteNoise(3, variance, lengthscale), X=X, Z=None, K_sum=6),
    T(
        Coregionalize(3, components=torch.eye(3, 3)),
        X=torch.tensor([[1., 0., 0.], [0.5, 0., 0.5]]),
Ejemplo n.º 5
0
     X=X, Z=Z, K_sum=-0.193233
 ),
 T(
     Linear(3, variance),
     X=X, Z=Z, K_sum=291
 ),
 T(
     Exponential(3, variance, lengthscale),
     X=X, Z=Z, K_sum=2.685679
 ),
 T(
     Matern32(3, variance, lengthscale),
     X=X, Z=Z, K_sum=3.229314
 ),
 T(
     Matern52(3, variance, lengthscale),
     X=X, Z=Z, K_sum=3.391847
 ),
 T(
     Periodic(3, variance, lengthscale, period=torch.ones(1)),
     X=X, Z=Z, K_sum=18
 ),
 T(
     Polynomial(3, variance, degree=2),
     X=X, Z=Z, K_sum=7017
 ),
 T(
     RationalQuadratic(3, variance, lengthscale, scale_mixture=torch.ones(1)),
     X=X, Z=Z, K_sum=5.684670
 ),
 T(