예제 #1
0
def test_general_matmul_upper():
    x, c, a, U, V, Y, t, U2, V2 = get_matrices(conditional=True)
    Z = driver.general_matmul_upper(t, x, c, U2, V, Y,
                                    np.zeros((len(t), Y.shape[1])))
    check_op(ops.general_matmul_upper, [t, x, c, U2, V, Y], [Z], grad=False)
    check_op(jit(ops.general_matmul_upper), [t, x, c, U2, V, Y], [Z],
             grad=False)
예제 #2
0
def test_factor():
    x, c, a, U, V, K, Y = get_matrices(include_dense=True)
    d, W = driver.factor(x, c, a, U, V, a, V)

    # Make sure that no copy is made if possible
    assert np.allclose(a, d)
    assert np.allclose(V, W)
예제 #3
0
def test_matmul_fwd(vector):
    a, U, V, P, Y = get_matrices(vector=vector)
    check_basic(
        backprop.matmul_fwd,
        ops.matmul,
        [a, U, V, P, Y],
    )
예제 #4
0
def test_factor_fwd():
    x, c, a, U, V, Y = get_matrices()
    check_basic(
        backprop.factor_fwd,
        ops.factor,
        [x, c, a, U, V],
    )
예제 #5
0
def test_matmul_rev(vector):
    a, U, V, P, Y = get_matrices(vector=vector)
    check_grad(
        ops.matmul,
        [a, U, V, P, Y],
        1,
    )
예제 #6
0
def test_matmul_upper_rev():
    x, c, a, U, V, Y = get_matrices()
    check_grad(
        ops.matmul_upper,
        [x, c, U, V, Y],
        1,
    )
예제 #7
0
def test_general_matmul_upper_fwd():
    x, c, a, U, V, Y, t, U2, V2 = get_matrices(conditional=True)
    check_basic(
        backprop.general_matmul_upper_fwd,
        ops.general_matmul_upper,
        [t, x, c, U2, V, Y],
    )
예제 #8
0
def test_factor_rev():
    x, c, a, U, V, Y = get_matrices()
    check_grad(
        ops.factor,
        [x, c, a, U, V],
        2,
    )
예제 #9
0
def test_matmul_upper_fwd():
    x, c, a, U, V, Y = get_matrices()
    check_basic(
        backprop.matmul_upper_fwd,
        ops.matmul_upper,
        [x, c, U, V, Y],
    )
예제 #10
0
def test_factor_fwd():
    a, U, V, P, Y = get_matrices()
    check_basic(
        backprop.factor_fwd,
        ops.factor,
        [a, U, V, P],
    )
예제 #11
0
def test_factor_rev():
    a, U, V, P, Y = get_matrices()
    check_grad(
        ops.factor,
        [a, U, V, P],
        2,
    )
예제 #12
0
def test_solve_upper_rev():
    x, c, a, U, V, Y = get_matrices()
    d, W = driver.factor(x, c, a, U, V, a, V)
    check_grad(
        ops.solve_upper,
        [x, c, U, W, Y],
        1,
    )
예제 #13
0
def test_solve_upper_fwd():
    x, c, a, U, V, Y = get_matrices()
    d, W = driver.factor(x, c, a, U, V, a, V)
    check_basic(
        backprop.solve_upper_fwd,
        ops.solve_upper,
        [x, c, U, W, Y],
    )
예제 #14
0
def test_solve_fwd(vector):
    a, U, V, P, Y = get_matrices(vector=vector)
    d, W = driver.factor(U, P, a, V)
    check_basic(
        backprop.solve_fwd,
        ops.solve,
        [U, P, d, W, Y],
    )
예제 #15
0
def test_solve_rev(vector):
    a, U, V, P, Y = get_matrices(vector=vector)
    d, W = driver.factor(U, P, a, V)
    check_grad(
        ops.solve,
        [U, P, d, W, Y],
        1,
    )
예제 #16
0
def test_dot_tril_rev(vector):
    a, U, V, P, Y = get_matrices(vector=vector)
    d, W = driver.factor(U, P, a, V)
    check_grad(
        ops.dot_tril,
        [U, P, d, W, Y],
        1,
    )
예제 #17
0
def test_dot_tril_fwd(vector):
    a, U, V, P, Y = get_matrices(vector=vector)
    d, W = driver.factor(U, P, a, V)
    check_basic(
        backprop.dot_tril_fwd,
        ops.dot_tril,
        [U, P, d, W, Y],
    )
예제 #18
0
def test_norm_rev():
    a, U, V, P, Y = get_matrices(vector=True)
    d, W = driver.factor(U, P, a, V)
    check_grad(
        ops.norm,
        [U, P, d, W, Y],
        1,
    )
예제 #19
0
def test_norm_fwd():
    a, U, V, P, Y = get_matrices(vector=True)
    d, W = driver.factor(U, P, a, V)
    check_basic(
        backprop.norm_fwd,
        ops.norm,
        [U, P, d, W, Y],
    )
예제 #20
0
def test_factor_rev():
    a, U, V, P, Y = get_matrices()

    d = np.empty_like(a)
    W = np.empty_like(V)
    S = np.empty((len(a), U.shape[1]**2))
    d, W, S = backprop.factor_fwd(a, U, V, P, d, W, S)

    check_grad(backprop.factor_fwd, backprop.factor_rev, [a, U, V, P], [d, W],
               [S])
예제 #21
0
def test_conditional_mean_fwd():
    a, U, V, P, Y, U_star, V_star, inds = get_matrices(vector=True,
                                                       conditional=True)
    d, W = driver.factor(U, P, a, np.copy(V))
    z = driver.solve(U, P, d, W, Y)
    check_basic(
        driver.conditional_mean,
        ops.conditional_mean,
        [U, V, P, z, U_star, V_star, inds],
    )
예제 #22
0
def test_factor_rev():
    x, c, a, U, V, Y = get_matrices()

    d = np.empty_like(a)
    W = np.empty_like(V)
    S = np.empty((len(a), U.shape[1], U.shape[1]))
    d, W, S = backprop.factor_fwd(x, c, a, U, V, d, W, S)

    check_grad(backprop.factor_fwd, backprop.factor_rev, [x, c, a, U, V],
               [d, W], [S])
예제 #23
0
def test_matmul_lower_fwd(vector):
    x, c, a, U, V, Y = get_matrices(vector=vector)
    if vector:
        Y = Y[:, None]

    Z0 = driver.matmul_lower(x, c, U, V, Y, np.zeros_like(Y))

    Z = np.empty_like(Y)
    F = np.empty((U.shape[0], U.shape[1], Y.shape[1]))
    Z, F = backprop.matmul_lower_fwd(x, c, U, V, Y, Z, F)
    assert np.allclose(Z0, Z)
예제 #24
0
def test_solve_lower_fwd(vector):
    x, c, a, U, V, Y = get_matrices(vector=vector)
    if vector:
        Y = Y[:, None]

    d, W = driver.factor(x, c, a, U, V, a, V)
    Z0 = driver.solve_lower(x, c, U, W, Y, np.copy(Y))

    Z = np.empty_like(Y)
    F = np.empty((U.shape[0], U.shape[1], Y.shape[1]))
    Z, F = backprop.solve_lower_fwd(x, c, U, W, Y, Z, F)
    assert np.allclose(Z0, Z)
예제 #25
0
def test_factor_fwd():
    x, c, a, U, V, Y = get_matrices()

    d = np.empty_like(a)
    W = np.empty_like(V)
    S = np.empty((len(a), U.shape[1], U.shape[1]))

    d0, W0 = driver.factor(x, c, a, U, V, np.copy(a), np.copy(V))
    d, W, S = backprop.factor_fwd(x, c, a, U, V, d, W, S)

    assert np.allclose(d, d0)
    assert np.allclose(W, W0)
예제 #26
0
def test_norm():
    a, U, V, P, K, Y = get_matrices(vector=True, include_dense=True)

    # First compute the expected value
    expect = np.dot(Y, np.linalg.solve(K, Y))

    # Then solve using celerite
    d, W = driver.factor(U, P, a, V)
    value = driver.norm(U, P, d, W, Y)

    # Check that the solution is correct
    assert np.allclose(value, expect)
예제 #27
0
def test_norm_rev():
    a, U, V, P, Y = get_matrices(vector=True)
    d, W = driver.factor(U, P, a, V)

    X = np.empty((1, 1))
    Z = np.empty_like(Y)
    F = np.empty_like(U)

    X, Z, F = backprop.norm_fwd(U, P, d, W, Y, X, Z, F)

    check_grad(backprop.norm_fwd, backprop.norm_rev, [U, P, d, W, Y], [X],
               [Z, F])
예제 #28
0
def test_norm_fwd():
    a, U, V, P, Y = get_matrices(vector=True)
    d, W = driver.factor(U, P, a, V)

    X0 = driver.norm(U, P, d, W, np.copy(Y))

    X = np.empty((1, 1))
    Z = np.empty_like(Y)
    F = np.empty_like(U)

    X, Z, F = backprop.norm_fwd(U, P, d, W, Y, X, Z, F)
    assert np.allclose(X0, X)
예제 #29
0
def test_matmul_upper(vector):
    x, c, a, U, V, K, Y = get_matrices(vector=vector, include_dense=True)

    if vector:
        Y = Y[:, None]

    # First compute the expected value
    expect = np.dot(np.triu(K, 1), Y)

    # Then solve using celerite
    value = driver.matmul_upper(x, c, U, V, Y, np.zeros_like(Y))

    # Check that the solution is correct
    assert np.allclose(value, expect)
예제 #30
0
def test_conditional_mean():
    a, U, V, P, K, Y, U_star, V_star, inds, K_star = get_matrices(
        vector=True, conditional=True, include_dense=True)

    # First compute the expected value
    alpha = np.linalg.solve(K, Y)
    expect = np.dot(K_star, alpha)

    # Then solve using celerite
    mu = np.empty(len(U_star))
    value = driver.conditional_mean(U, V, P, alpha, U_star, V_star, inds, mu)

    # Check that the solution is correct
    assert np.allclose(value, expect)