def _pre_test_mean_function(): def f(x): return 2 * x + 3 + 5 * torch.sin(7 * x) X = torch.arange(100) y = f(X) Xnew = torch.arange(100, 150) ynew = f(Xnew) kernel = Cosine(input_dim=1) def trend(x): a = pyro.param("a", torch.tensor(0.)) b = pyro.param("b", torch.tensor(1.)) return a * x + b return X, y, Xnew, ynew, kernel, trend
def _pre_test_mean_function(): def f(x): return 2 * x + 3 + 5 * torch.sin(7 * x) X = torch.arange(100, dtype=torch.Tensor().dtype) y = f(X) Xnew = torch.arange(100, 150, dtype=torch.Tensor().dtype) ynew = f(Xnew) kernel = Cosine(input_dim=1) class Trend(torch.nn.Module): def __init__(self): super(Trend, self).__init__() self.a = torch.nn.Parameter(torch.tensor(0.)) self.b = torch.nn.Parameter(torch.tensor(1.)) def forward(self, x): return self.a * x + self.b trend = Trend() return X, y, Xnew, ynew, kernel, trend
T = namedtuple("TestGPKernel", ["kernel", "X", "Z", "K_sum"]) variance = torch.tensor([3.0]) lengthscale = torch.tensor([2.0, 1.0, 2.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),
lengthscale = torch.tensor([2.0, 1.0, 2.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(