Exemplo n.º 1
0
def test_mult_Lbeta(n):

    p = 20

    for i in range(n):
        A, Afull = gen_adj(p)
        regreg._check_adj(A)
        nadj = regreg._create_nadj(A)
        beta = np.random.normal(0, 1, p)
        s1 = regreg._mult_Lbeta(A, nadj, beta)
        s2 = 2 * np.dot(beta, np.dot(Afull, beta))
        assert np.allclose(s1, s2)
Exemplo n.º 2
0
def test_mult_Lbeta(n):

    p = 20

    for i in range(n):
        A, Afull = gen_adj(p)
        regreg._check_adj(A)
        nadj = regreg._create_nadj(A)
        beta = np.random.normal(0, 1, p)
        s1 = regreg._mult_Lbeta(A, nadj, beta)
        s2 = 2 * np.dot(beta, np.dot(Afull, beta))
        assert (np.allclose(s1, s2))
Exemplo n.º 3
0
def test_gen_adj(n):

    for i in range(n):
        p = np.random.randint(100) + 2
        A, Afull = gen_adj(p)

        regreg._check_adj(A)
        v1 = np.diag(Afull)
        v2 = np.array([np.sum(r >= 0) for r in A], dtype=int)

        assert np.sum((v1 - v2) ** 2) == 0
        v = np.unique(np.triu(Afull, 1) + np.tril(Afull, -1))
        if len(v) == 1:
            assert np.product(np.unique(np.triu(Afull, 1)) in [-1, 0])
        else:
            assert np.product(np.unique(np.triu(Afull, 1)) == [-1, 0])
        assert np.unique([np.sum(r) for r in Afull]) == [0]
        assert np.sum(np.fabs(Afull - Afull.T)) == 0.0
        for j in range(A.shape[0]):
            for k in range(A.shape[1]):
                if A[j, k] > -1:
                    assert Afull[j, A[j, k]] == -1
Exemplo n.º 4
0
def test_gen_adj(n):

    for i in range(n):
        p = np.random.randint(100) + 2
        A, Afull = gen_adj(p)

        regreg._check_adj(A)
        v1 = np.diag(Afull)
        v2 = np.array([np.sum(r >= 0) for r in A], dtype=int)

        assert (np.sum((v1 - v2)**2) == 0)
        v = np.unique(np.triu(Afull, 1) + np.tril(Afull, -1))
        if len(v) == 1:
            assert (np.product(np.unique(np.triu(Afull, 1)) in [-1, 0]))
        else:
            assert (np.product(np.unique(np.triu(Afull, 1)) == [-1, 0]))
        assert (np.unique([np.sum(r) for r in Afull]) == [0])
        assert (np.sum(np.fabs(Afull - Afull.T)) == 0.)
        for j in range(A.shape[0]):
            for k in range(A.shape[1]):
                if A[j, k] > -1:
                    assert (Afull[j, A[j, k]] == -1)