Esempio n. 1
0
 def test_return_statdist(self):
     C = np.loadtxt(testpath + 'C_1_lag.dat')
     # dense
     T, mu = apicall(C,
                     reversible=True,
                     method='dense',
                     return_statdist=True)
     mu_manual = msmtools.analysis.stationary_distribution(T)
     np.testing.assert_allclose(mu, mu_manual)
     # sparse
     T, mu = apicall(C,
                     reversible=True,
                     method='sparse',
                     return_statdist=True)
     mu_manual = msmtools.analysis.stationary_distribution(T)
     np.testing.assert_allclose(mu, mu_manual)
Esempio n. 2
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)
    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(statdist(T_Frank), pi)
        assert_allclose(statdist(T_impl_algo_dense_type_dense), pi)
        assert_allclose(statdist(T_impl_algo_sparse_type_sparse), pi)
        assert_allclose(statdist(T_api_algo_dense_type_dense), pi)
        assert_allclose(statdist(T_api_algo_sparse_type_dense), pi)
        assert_allclose(statdist(T_api_algo_dense_type_sparse), pi)
        assert_allclose(statdist(T_api_algo_sparse_type_sparse), pi)
        assert_allclose(statdist(T_api_algo_auto_type_dense), pi)
        assert_allclose(statdist(T_api_algo_auto_type_sparse), pi)