def test_computes_exponential_decay_function(self): a = torch.tensor([1.0, 2.0]).view(2, 1) b = torch.tensor([2.0, 4.0]).view(2, 1) lengthscale = 1 power = 1 offset = 1 kernel = ExpDecayKernel() kernel.initialize(lengthscale=lengthscale, power=power, offset=offset) kernel.eval() diff = torch.tensor([[4.0, 6.0], [5.0, 7.0]]) actual = offset + torch.tensor([1.0]).div(diff.pow(power)) res = kernel(a, b).evaluate() self.assertLess(torch.norm(res - actual), 1e-5)
def test_subset_active_compute_exponential_decay_function(self): a = torch.tensor([1.0, 2.0]).view(2, 1) a_p = torch.tensor([3.0, 4.0]).view(2, 1) a = torch.cat((a, a_p), 1) b = torch.tensor([2.0, 4.0]).view(2, 1) lengthscale = 1 power = 1 offset = 1 kernel = ExpDecayKernel(active_dims=[0]) kernel.initialize(lengthscale=lengthscale, power=power, offset=offset) kernel.eval() diff = torch.tensor([[4.0, 6.0], [5.0, 7.0]]) actual = offset + diff.pow(-power) res = kernel(a, b).evaluate() self.assertLess(torch.norm(res - actual), 1e-5)
def test_computes_exponential_decay_function_batch(self): a = torch.tensor([[1.0, 2.0], [3.0, 4.0]]).view(2, 2, 1) b = torch.tensor([[5.0, 6.0], [7.0, 8.0]]).view(2, 2, 1) lengthscale = 1 power = 1 offset = 1 kernel = ExpDecayKernel(batch_shape=torch.Size([2])) kernel.initialize(lengthscale=lengthscale, power=power, offset=offset) kernel.eval() actual = torch.zeros(2, 2, 2) diff = torch.tensor([[7.0, 8.0], [8.0, 9.0]]) actual[0, :, :] = offset + diff.pow(-power) diff = torch.tensor([[11.0, 12.0], [12.0, 13.0]]) actual[1, :, :] = offset + diff.pow(-power) res = kernel(a, b).evaluate() self.assertLess(torch.norm(res - actual), 1e-5)