Exemple #1
0
 def test_noninteger_counts_dense(self):
     C = np.loadtxt(testpath + 'C_1_lag.dat')
     T_dense_reference = impl_dense(C)
     T_dense_scaled_1 = impl_dense(C*10.0)
     T_dense_scaled_2 = impl_dense(C*0.1)
     assert_allclose(T_dense_reference, T_dense_scaled_1)
     assert_allclose(T_dense_reference, T_dense_scaled_2)
Exemple #2
0
    def test_warnings(self):
        C = np.loadtxt(testpath + 'C_1_lag.dat')
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('ignore')
            warnings.simplefilter('always', category=NotConvergedWarning)
            impl_sparse(scipy.sparse.csr_matrix(C), maxiter=1)
            assert issubclass(w[-1].category, NotConvergedWarning)

            impl_dense(C, maxiter=1)
            assert len(w) == 2
            assert issubclass(w[-1].category, NotConvergedWarning)
Exemple #3
0
    def test_mle_trev(self):
        C = np.loadtxt(testpath + 'C_1_lag.dat')

        T_impl_algo_sparse_type_sparse = impl_sparse(scipy.sparse.csr_matrix(C)).toarray()
        T_impl_algo_dense_type_dense = impl_dense(C)

        T_api_algo_dense_type_dense = apicall(C, reversible=True, method='dense')
        T_api_algo_sparse_type_dense = apicall(C, reversible=True, method='sparse')
        T_api_algo_dense_type_sparse = apicall(scipy.sparse.csr_matrix(C), reversible=True, method='dense').toarray()
        T_api_algo_sparse_type_sparse = apicall(scipy.sparse.csr_matrix(C), reversible=True, method='sparse').toarray()
        T_api_algo_auto_type_dense = apicall(C, reversible=True, method='auto')
        T_api_algo_auto_type_sparse = apicall(scipy.sparse.csr_matrix(C), reversible=True, method='auto').toarray()

        assert_allclose(T_impl_algo_sparse_type_sparse, T_impl_algo_dense_type_dense)
        assert_allclose(T_api_algo_dense_type_dense, T_impl_algo_dense_type_dense)
        assert_allclose(T_api_algo_sparse_type_dense, T_impl_algo_dense_type_dense)
        assert_allclose(T_api_algo_dense_type_sparse, T_impl_algo_dense_type_dense)
        assert_allclose(T_api_algo_sparse_type_sparse, T_impl_algo_dense_type_dense)
        assert_allclose(T_api_algo_auto_type_dense, T_impl_algo_dense_type_dense)
        assert_allclose(T_api_algo_auto_type_sparse, T_impl_algo_dense_type_dense)
Exemple #4
0
    def test_mle_trev_given_pi(self):
        C = np.loadtxt(testpath + 'C_1_lag.dat')
        pi = np.loadtxt(testpath + 'pi.dat')

        T_impl_algo_dense_type_dense = impl_dense(C, pi)
        T_impl_algo_sparse_type_sparse = impl_sparse(
            scipy.sparse.csr_matrix(C), pi).toarray()
        T_Frank = impl_dense_Frank(C, pi)
        T_api_algo_dense_type_dense = apicall(C,
                                              reversible=True,
                                              mu=pi,
                                              method='dense')
        T_api_algo_sparse_type_dense = apicall(C,
                                               reversible=True,
                                               mu=pi,
                                               method='sparse')
        T_api_algo_dense_type_sparse = apicall(scipy.sparse.csr_matrix(C),
                                               reversible=True,
                                               mu=pi,
                                               method='dense').toarray()
        T_api_algo_sparse_type_sparse = apicall(scipy.sparse.csr_matrix(C),
                                                reversible=True,
                                                mu=pi,
                                                method='sparse').toarray()
        T_api_algo_auto_type_dense = apicall(C,
                                             reversible=True,
                                             mu=pi,
                                             method='auto')
        T_api_algo_auto_type_sparse = apicall(scipy.sparse.csr_matrix(C),
                                              reversible=True,
                                              mu=pi,
                                              method='auto').toarray()

        assert_allclose(T_impl_algo_dense_type_dense, T_Frank)
        assert_allclose(T_impl_algo_sparse_type_sparse, T_Frank)
        assert_allclose(T_api_algo_dense_type_dense, T_Frank)
        assert_allclose(T_api_algo_sparse_type_dense, T_Frank)
        assert_allclose(T_api_algo_dense_type_sparse, T_Frank)
        assert_allclose(T_api_algo_sparse_type_sparse, T_Frank)
        assert_allclose(T_api_algo_auto_type_dense, T_Frank)
        assert_allclose(T_api_algo_auto_type_sparse, T_Frank)

        assert is_transition_matrix(T_Frank)
        assert is_transition_matrix(T_impl_algo_dense_type_dense)
        assert is_transition_matrix(T_impl_algo_sparse_type_sparse)
        assert is_transition_matrix(T_api_algo_dense_type_dense)
        assert is_transition_matrix(T_api_algo_sparse_type_dense)
        assert is_transition_matrix(T_api_algo_dense_type_sparse)
        assert is_transition_matrix(T_api_algo_sparse_type_sparse)
        assert is_transition_matrix(T_api_algo_auto_type_dense)
        assert is_transition_matrix(T_api_algo_auto_type_sparse)

        assert_allclose(stationary_distribution(T_Frank), pi)
        assert_allclose(stationary_distribution(T_impl_algo_dense_type_dense),
                        pi)
        assert_allclose(
            stationary_distribution(T_impl_algo_sparse_type_sparse), pi)
        assert_allclose(stationary_distribution(T_api_algo_dense_type_dense),
                        pi)
        assert_allclose(stationary_distribution(T_api_algo_sparse_type_dense),
                        pi)
        assert_allclose(stationary_distribution(T_api_algo_dense_type_sparse),
                        pi)
        assert_allclose(stationary_distribution(T_api_algo_sparse_type_sparse),
                        pi)
        assert_allclose(stationary_distribution(T_api_algo_auto_type_dense),
                        pi)
        assert_allclose(stationary_distribution(T_api_algo_auto_type_sparse),
                        pi)