Example #1
0
def test_case_fd_derivative():
    x = np.linspace(0, 10, 50)[:, None]
    y = np.sin(x)

    model = Graph()
    p = GP(.7 * EQ().stretch(1.), graph=model)
    dp = (p.shift(-1e-3) - p.shift(1e-3)) / 2e-3

    yield le, abs_err(np.cos(x) - dp.condition(p(x), y)(x).mean), 1e-4
Example #2
0
def test_shifting():
    model = Graph()

    # Test construction:
    p = GP(Linear(), TensorProductMean(lambda x: x ** 2), graph=model)
    yield eq, str(p.shift(1)), 'GP(Linear() shift 1, <lambda> shift 1)'

    # Test case:
    p = GP(EQ(), graph=model)
    p2 = p.shift(5)

    n = 5
    x = np.linspace(0, 10, n)[:, None]
    y = p2(x).sample()

    post = p.condition(p2(x), y)
    yield assert_allclose, post(x - 5).mean, y
    yield le, abs_err(B.diag(post(x - 5).var)), 1e-10

    post = p2.condition(p(x), y)
    yield assert_allclose, post(x + 5).mean, y
    yield le, abs_err(B.diag(post(x + 5).var)), 1e-10