Ejemplo n.º 1
0
def test_stoch_matrix():
    """Test with stochastic matrices"""
    print(__name__ + '.' + test_stoch_matrix.__name__)
    matrices = Matrices()
    for matrix_dict in matrices.stoch_matrix_dicts:
        x = gth_solve(matrix_dict['A'])
        yield StationaryDistSumOne(), x
        yield StationaryDistNonnegative(), x
        yield StationaryDistEqualToKnown(), matrix_dict['stationary_dist'], x
Ejemplo n.º 2
0
def test_stoch_matrix():
    """Test with stochastic matrices"""
    print(__name__ + '.' + test_stoch_matrix.__name__)
    matrices = Matrices()
    for matrix_dict in matrices.stoch_matrix_dicts:
        x = gth_solve(matrix_dict['A'])
        yield StationaryDistSumOne(), x
        yield StationaryDistNonnegative(), x
        yield StationaryDistEqualToKnown(), matrix_dict['stationary_dist'], x
Ejemplo n.º 3
0
def test_kmr_matrix():
    """Test with KMR matrices"""
    print(__name__ + '.' + test_kmr_matrix.__name__)
    matrices = Matrices()
    for matrix_dict in matrices.kmr_matrix_dicts:
        x = gth_solve(matrix_dict['A'])
        yield StationaryDistSumOne(), x
        yield StationaryDistNonnegative(), x
        yield StationaryDistLeftEigenVec(), matrix_dict['A'], x
Ejemplo n.º 4
0
def test_kmr_matrix():
    """Test with KMR matrices"""
    print(__name__ + '.' + test_kmr_matrix.__name__)
    matrices = Matrices()
    for matrix_dict in matrices.kmr_matrix_dicts:
        x = gth_solve(matrix_dict['A'])
        yield StationaryDistSumOne(), x
        yield StationaryDistNonnegative(), x
        yield StationaryDistLeftEigenVec(), matrix_dict['A'], x
Ejemplo n.º 5
0
def test_matrices_with_C_F_orders():
    """
    Test matrices with C- and F-contiguous orders
    See the issue and fix on Numba:
    github.com/numba/numba/issues/1103
    github.com/numba/numba/issues/1104

    Fix in gth_solve(A):
    added `order='C'` when `A1` copies the input `A`
    """
    P_C = np.array([[0.5, 0.5], [0, 1]], order='C')
    P_F = np.array([[0.5, 0.5], [0, 1]], order='F')
    stationary_dist = [0., 1.]

    computed_C_and_F = gth_solve(np.array([[1]]))
    assert_array_equal(computed_C_and_F, [1])

    computed_C = gth_solve(P_C)
    computed_F = gth_solve(P_F)
    assert_array_equal(computed_C, stationary_dist)
    assert_array_equal(computed_F, stationary_dist)
Ejemplo n.º 6
0
def test_matrices_with_C_F_orders():
    """
    Test matrices with C- and F-contiguous orders
    See the issue and fix on Numba:
    github.com/numba/numba/issues/1103
    github.com/numba/numba/issues/1104

    Fix in gth_solve(A):
    added `order='C'` when `A1` copies the input `A`
    """
    P_C = np.array([[0.5, 0.5], [0, 1]], order='C')
    P_F = np.array([[0.5, 0.5], [0, 1]], order='F')
    stationary_dist = [0., 1.]

    computed_C_and_F = gth_solve(np.array([[1]]))
    assert_array_equal(computed_C_and_F, [1])

    computed_C = gth_solve(P_C)
    computed_F = gth_solve(P_F)
    assert_array_equal(computed_C, stationary_dist)
    assert_array_equal(computed_F, stationary_dist)
Ejemplo n.º 7
0
def test_raises_value_error_non_square():
    """Test with non square input"""
    gth_solve(np.array([[0.4, 0.6]]))
Ejemplo n.º 8
0
def test_raises_value_error_non_2dim():
    """Test with non 2dim input"""
    gth_solve(np.array([0.4, 0.6]))
Ejemplo n.º 9
0
def test_raises_value_error_non_square():
    """Test with non square input"""
    gth_solve(np.array([[0.4, 0.6]]))
Ejemplo n.º 10
0
def test_raises_value_error_non_2dim():
    """Test with non 2dim input"""
    gth_solve(np.array([0.4, 0.6]))
Ejemplo n.º 11
0
def test_raises_value_error_non_sym():
    """Test with non symmetric input"""
    gth_solve(np.array([[0.4, 0.6]]))