示例#1
0
def test_random_stochastic_matrix_k_1():
    n, k = 3, 1
    P_dense = random_stochastic_matrix(n, k, sparse=False)
    P_sparse = random_stochastic_matrix(n, k, sparse=True)
    assert_array_equal(P_dense[P_dense != 0], np.ones(n))
    assert_array_equal(P_sparse.data, np.ones(n))
    for P in [P_dense, P_sparse]:
        assert_array_almost_equal_nulp(P.sum(axis=1), np.ones(n))
示例#2
0
def test_random_stochastic_matrix_sparse():
    sparse = True
    n, k = 5, 3
    Ps = [random_stochastic_matrix(n, sparse=sparse),
          random_stochastic_matrix(n, k, sparse=sparse)]
    for P in Ps:
        ok_(np.all(P.data >= 0))
        assert_array_almost_equal_nulp(P.sum(axis=1), np.ones(n))
示例#3
0
def test_random_stochastic_matrix_k_1():
    n, k = 3, 1
    P_dense = random_stochastic_matrix(n, k, sparse=False)
    P_sparse = random_stochastic_matrix(n, k, sparse=True)
    assert_array_equal(P_dense[P_dense != 0], np.ones(n))
    assert_array_equal(P_sparse.data, np.ones(n))
    for P in [P_dense, P_sparse]:
        assert_array_almost_equal_nulp(P.sum(axis=1), np.ones(n))
示例#4
0
def test_random_stochastic_matrix_sparse():
    sparse = True
    n, k = 5, 3
    Ps = [random_stochastic_matrix(n, sparse=sparse),
          random_stochastic_matrix(n, k, sparse=sparse)]
    for P in Ps:
        ok_(np.all(P.data >= 0))
        assert_array_almost_equal_nulp(P.sum(axis=1), np.ones(n))
示例#5
0
def test_random_stochastic_matrix_dense_vs_sparse():
    n, k = 10, 5
    seed = 1234
    P_dense = random_stochastic_matrix(n, sparse=False, random_state=seed)
    P_sparse = random_stochastic_matrix(n, sparse=True, random_state=seed)
    assert_array_equal(P_dense, P_sparse.toarray())

    P_dense = random_stochastic_matrix(n, k, sparse=False, random_state=seed)
    P_sparse = random_stochastic_matrix(n, k, sparse=True, random_state=seed)
    assert_array_equal(P_dense, P_sparse.toarray())
示例#6
0
def test_random_stochastic_matrix_dense_vs_sparse():
    n, k = 10, 5
    seed = 1234
    P_dense = random_stochastic_matrix(n, sparse=False, random_state=seed)
    P_sparse = random_stochastic_matrix(n, sparse=True, random_state=seed)
    assert_array_equal(P_dense, P_sparse.toarray())

    P_dense = random_stochastic_matrix(n, k, sparse=False, random_state=seed)
    P_sparse = random_stochastic_matrix(n, k, sparse=True, random_state=seed)
    assert_array_equal(P_dense, P_sparse.toarray())