def test_tensor_product(): k = TensorProductKernel(lambda x: B.sum(x ** 2, axis=1)) assert not k.stationary with pytest.raises(RuntimeError): k.length_scale with pytest.raises(RuntimeError): k.var with pytest.raises(RuntimeError): k.period # Test equality. assert k == k assert k != TensorProductKernel(lambda x: x) assert k != EQ() # Standard tests: standard_kernel_tests(k) # Check computation of kernel. k = TensorProductKernel(lambda x: x) x1 = np.linspace(0, 1, 100)[:, None] x2 = np.linspace(0, 1, 50)[:, None] allclose(k(x1), x1 * x1.T) allclose(k(x1, x2), x1 * x2.T) k = TensorProductKernel(lambda x: x ** 2) allclose(k(x1), x1 ** 2 * (x1 ** 2).T) allclose(k(x1, x2), (x1 ** 2) * (x2 ** 2).T)
def test_tensor_product(): k = TensorProductKernel(lambda x: B.sum(x**2, axis=1)) # Verify that the kernel has the right properties. assert not k.stationary # Test equality. assert k == k assert k != TensorProductKernel(lambda x: x) assert k != EQ() # Standard tests: standard_kernel_tests(k) # Test computation of the kernel. k = TensorProductKernel(lambda x: x) x1 = np.linspace(0, 1, 100)[:, None] x2 = np.linspace(0, 1, 50)[:, None] approx(k(x1), x1 * x1.T) approx(k(x1, x2), x1 * x2.T) k = TensorProductKernel(lambda x: x**2) approx(k(x1), x1**2 * (x1**2).T) approx(k(x1, x2), (x1**2) * (x2**2).T)