def test_fd_derivative(): x = B.linspace(0, 10, 50) y = np.sin(x) p = GP(0.7 * EQ().stretch(1.0)) dp = (p.shift(-1e-3) - p.shift(1e-3)) / 2e-3 post = p.measure | (p(x), y) approx(post(dp)(x).mean, np.cos(x)[:, None], atol=1e-4)
def test_shifting(): # Test construction: p = GP(lambda x: x**2, Linear()) assert str(p.shift(1)) == "GP(<lambda> shift 1, Linear() shift 1)" # Test case: p_shifted = p.shift(5) x = B.linspace(0, 5, 10) y = p_shifted(x).sample() post = p.measure | (p_shifted(x, B.epsilon), y) assert_equal_normals(post(p(x - 5)), post(p_shifted(x))) assert_equal_normals(post(p(x)), post(p_shifted(x + 5)))