Example #1
0
def check_smw_solver(p, q, r, s):
    # Helper to check that _smw_solver results do in fact solve the desired
    # SMW equation
    d = q - r

    A = np.random.normal(size=(p, q))
    AtA = np.dot(A.T, A)

    B = np.zeros((q, q))
    B[0:r, 0:r] = np.random.normal(size=(r, r))
    di = np.random.uniform(size=d)
    B[r:q, r:q] = np.diag(1 / di)
    Qi = np.linalg.inv(B[0:r, 0:r])
    s = 0.5

    x = np.random.normal(size=p)
    y2 = np.linalg.solve(s * np.eye(p, p) + np.dot(A, np.dot(B, A.T)), x)

    f = _smw_solver(s, A, AtA, Qi, di)
    y1 = f(x)
    assert_allclose(y1, y2)

    f = _smw_solver(s, sparse.csr_matrix(A), sparse.csr_matrix(AtA), Qi,
                    di)
    y1 = f(x)
    assert_allclose(y1, y2)
Example #2
0
    def tester(p, q, r, s):

        d = q - r

        A = np.random.normal(size=(p, q))
        AtA = np.dot(A.T, A)

        B = np.zeros((q, q))
        B[0:r, 0:r] = np.random.normal(size=(r, r))
        di = np.random.uniform(size=d)
        B[r:q, r:q] = np.diag(1 / di)
        Qi = np.linalg.inv(B[0:r, 0:r])
        s = 0.5

        x = np.random.normal(size=p)
        y2 = np.linalg.solve(s * np.eye(p, p) + np.dot(A, np.dot(B, A.T)), x)

        f = _smw_solver(s, A, AtA, Qi, di)
        y1 = f(x)
        assert_allclose(y1, y2)

        f = _smw_solver(s, sparse.csr_matrix(A), sparse.csr_matrix(AtA), Qi,
                        di)
        y1 = f(x)
        assert_allclose(y1, y2)
Example #3
0
def check_smw_solver(p, q, r, s):
    # Helper to check that _smw_solver results do in fact solve the desired
    # SMW equation
    d = q - r

    A = np.random.normal(size=(p, q))
    AtA = np.dot(A.T, A)

    B = np.zeros((q, q))
    B[0:r, 0:r] = np.random.normal(size=(r, r))
    di = np.random.uniform(size=d)
    B[r:q, r:q] = np.diag(1 / di)
    Qi = np.linalg.inv(B[0:r, 0:r])
    s = 0.5

    x = np.random.normal(size=p)
    y2 = np.linalg.solve(s * np.eye(p, p) + np.dot(A, np.dot(B, A.T)), x)

    f = _smw_solver(s, A, AtA, Qi, di)
    y1 = f(x)
    assert_allclose(y1, y2)

    f = _smw_solver(s, sparse.csr_matrix(A), sparse.csr_matrix(AtA), Qi, di)
    y1 = f(x)
    assert_allclose(y1, y2)
Example #4
0
def test_smw_solver():

    np.random.seed(23)
    p = 5
    q = 4
    r = 2
    s = 2

    A = np.random.normal(size=(p, q))
    AtA = np.dot(A.T, A)

    B = np.zeros((q, q))
    B[0:r, 0:r] = np.random.normal(size=(r, r))
    di = np.random.uniform(size=s)
    B[r:q, r:q] = np.diag(1/di)
    Qi = np.linalg.inv(B[0:r, 0:r])
    s = 0.5

    x = np.random.normal(size=p)
    y2 = np.linalg.solve(s*np.eye(p, p) + np.dot(A, np.dot(B, A.T)), x)

    f = _smw_solver(s, A, AtA, Qi, di)
    y1 = f(x)
    assert_allclose(y1, y2)

    f = _smw_solver(s, sparse.csr_matrix(A), sparse.csr_matrix(AtA), Qi, di)
    y1 = f(x)
    assert_allclose(y1, y2)