def test_hitting3(self):
     P = np.array([[0.9, 0.1, 0.0, 0.0, 0.0], [0.1, 0.9, 0.0, 0.0, 0.0],
                   [0.0, 0.1, 0.4, 0.5, 0.0], [0.0, 0.0, 0.0, 0.8, 0.2],
                   [0.0, 0.0, 0.0, 0.2, 0.8]])
     sol = np.array([0.0, 0.0, 8.33333333e-01, 1.0, 1.0])
     assert_allclose(hitting_probability(P, 3), sol)
     assert_allclose(hitting_probability(P, [3, 4]), sol)
Esempio n. 2
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)
Esempio n. 3
0
 def test_pcca_1(self):
     P = np.array([[1, 0],
                   [0, 1]])
     chi = pcca(P, 2)
     sol = np.array([[1., 0.],
                     [0., 1.]])
     assert_allclose(chi, sol)
Esempio n. 4
0
 def test_timescales_rev(self):
     P_dense = self.bdc.transition_matrix()
     P = self.bdc.transition_matrix_sparse()
     mu = self.bdc.stationary_distribution()
     ev = eigvals(P_dense)
     """Sort with decreasing magnitude"""
     ev = ev[np.argsort(np.abs(ev))[::-1]]
     ts = -1.0 / np.log(np.abs(ev))
     """k=None"""
     with self.assertRaises(ValueError):
         tsn = timescales(P, reversible=True)
     """k is not None"""
     tsn = timescales(P, k=self.k, reversible=True)
     assert_allclose(ts[1:self.k], tsn[1:])
     """k is not None, ncv is not None"""
     tsn = timescales(P, k=self.k, ncv=self.ncv, reversible=True)
     assert_allclose(ts[1:self.k], tsn[1:])
     """k is not None, mu is not None"""
     tsn = timescales(P, k=self.k, reversible=True, mu=mu)
     assert_allclose(ts[1:self.k], tsn[1:])
     """k is not None, mu is not None, ncv is not None"""
     tsn = timescales(P, k=self.k, ncv=self.ncv, reversible=True, mu=mu)
     assert_allclose(ts[1:self.k], tsn[1:])
     """tau=7"""
     """k is not None"""
     tsn = timescales(P, k=self.k, tau=7, reversible=True)
     assert_allclose(7 * ts[1:self.k], tsn[1:])
Esempio n. 5
0
 def test_connected_count_matrix(self):
     """Directed"""
     C_cc = largest_connected_submatrix(self.C)
     assert_allclose(C_cc, self.C_cc_directed)
     """Undirected"""
     C_cc = largest_connected_submatrix(self.C, directed=False)
     assert_allclose(C_cc, self.C_cc_undirected)
Esempio n. 6
0
    def test_totalflux(self):
        F = self.bdc.totalflux(self.a, self.b)

        Fn = self.tpt.total_flux
        assert_allclose(Fn, F)

        Fn = self.tpt_fast.total_flux
        assert_allclose(Fn, F)
Esempio n. 7
0
    def test_netflux(self):
        netflux = self.bdc.netflux(self.a, self.b)

        netfluxn = self.tpt.net_flux
        assert_allclose(netfluxn, netflux)

        netfluxn = self.tpt_fast.net_flux
        assert_allclose(netfluxn, netflux)
Esempio n. 8
0
    def test_grossflux(self):
        flux = self.bdc.flux(self.a, self.b)

        fluxn = self.tpt.gross_flux
        assert_allclose(fluxn, flux)

        fluxn = self.tpt_fast.gross_flux
        assert_allclose(fluxn, flux)
Esempio n. 9
0
    def test_stationary_distribution(self):
        mu = self.mu

        mun = self.tpt.stationary_distribution
        assert_allclose(mun, mu)

        mun = self.tpt_fast.stationary_distribution
        assert_allclose(mun, mu)
Esempio n. 10
0
    def test_forward_committor(self):
        qplus = self.qplus

        qplusn = self.tpt.forward_committor
        assert_allclose(qplusn, qplus)

        qplusn = self.tpt_fast.forward_committor
        assert_allclose(qplusn, qplus)
Esempio n. 11
0
    def test_backward_committor(self):
        qminus = self.qminus

        qminusn = self.tpt.backward_committor
        assert_allclose(qminusn, qminus)

        qminusn = self.tpt_fast.backward_committor
        assert_allclose(qminusn, qminus)
Esempio n. 12
0
    def test_rate(self):
        k = self.bdc.rate(self.a, self.b)

        kn = self.tpt.rate
        assert_allclose(kn, k)

        kn = self.tpt_fast.rate
        assert_allclose(kn, k)
Esempio n. 13
0
    def test_pathways_dense(self):
        paths, capacities = pathways(self.F, self.A, self.B)
        self.assertTrue(len(paths) == len(self.paths))
        self.assertTrue(len(capacities) == len(self.capacities))

        for i in range(len(paths)):
            assert_allclose(paths[i], self.paths[i])
            assert_allclose(capacities[i], self.capacities[i])
Esempio n. 14
0
    def test_prior_rev(self):
        with warnings.catch_warnings(record=True) as w:
            Bn = prior_rev(self.C)
            assert_allclose(Bn, -1.0 * self.B_rev)

        with warnings.catch_warnings(record=True) as w:
            Bn = prior_rev(self.C, alpha=self.alpha)
            assert_allclose(Bn, self.alpha * self.B_rev)
Esempio n. 15
0
    def test_prior_const(self):
        with warnings.catch_warnings(record=True) as w:
            Bn = prior_const(self.C)
            assert_allclose(Bn, self.alpha_def * self.B_const)

        with warnings.catch_warnings(record=True) as w:
            Bn = prior_const(self.C, alpha=self.alpha)
            assert_allclose(Bn, self.alpha * self.B_const)
Esempio n. 16
0
 def test_relaxation_matvec(self):
     times = self.times
     P = self.T.toarray()
     relax = np.zeros(len(times))
     for i in range(len(times)):
         P_t = np.linalg.matrix_power(P, times[i])
         relax[i] = np.dot(self.p0, np.dot(P_t, self.obs))
     relaxn = relaxation_matvec(self.T, self.p0, self.obs, times=self.times)
     assert_allclose(relaxn, relax)
Esempio n. 17
0
 def test_pcca_2(self):
     P = np.array([[0.0, 1.0, 0.0],
                   [0.0, 0.999, 0.001],
                   [0.0, 0.001, 0.999]])
     chi = pcca(P, 2)
     sol = np.array([[1., 0.],
                     [1., 0.],
                     [0., 1.]])
     assert_allclose(chi, sol)
Esempio n. 18
0
    def test_error_perturbation_sparse(self):
        Csparse = scipy.sparse.csr_matrix(self.C)

        with warnings.catch_warnings(record=True) as w:
            xn = error_perturbation(Csparse, self.S1)
            assert_allclose(xn, self.x)

            Xn = error_perturbation(Csparse, self.S2)
            assert_allclose(Xn, self.X)
Esempio n. 19
0
    def test_timescales_2(self):
        """Eigenvalues with non-zero imaginary part"""
        ts = np.array([np.inf, 0.971044, 0.971044])

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            tsn = timescales(0.5 * self.T + 0.5 * self.P)
            assert_allclose(tsn, ts)
            assert issubclass(w[-1].category, ImaginaryEigenValueWarning)
Esempio n. 20
0
 def test_relaxation(self):
     relax_amp = np.dot(self.p0, self.R) * np.dot(self.L, self.obs)
     relax = np.dot(self.ev_t, relax_amp)
     relaxn = relaxation(self.T,
                         self.p0,
                         self.obs,
                         k=self.k,
                         times=self.times)
     assert_allclose(relaxn, relax)
Esempio n. 21
0
    def test_count_matrix(self):
        """Small test cases"""
        T = transition_matrix.transition_matrix_non_reversible(
            self.C1).toarray()
        assert_allclose(T, self.T1.toarray())

        T = transition_matrix.transition_matrix_non_reversible(
            self.C1).toarray()
        assert_allclose(T, self.T1.toarray())
Esempio n. 22
0
 def test_noninteger_counts_sparse(self):
     C = np.loadtxt(testpath + 'C_1_lag.dat')
     T_sparse_reference = impl_sparse(scipy.sparse.csr_matrix(C)).toarray()
     T_sparse_scaled_1 = impl_sparse(scipy.sparse.csr_matrix(
         C * 10.0)).toarray()
     T_sparse_scaled_2 = impl_sparse(scipy.sparse.csr_matrix(
         C * 0.1)).toarray()
     assert_allclose(T_sparse_reference, T_sparse_scaled_1)
     assert_allclose(T_sparse_reference, T_sparse_scaled_2)
Esempio n. 23
0
    def test_timescales_1(self):
        """Multiple eigenvalues of magnitude one,
        eigenvalues with non-zero imaginary part"""
        ts = np.array([np.inf, np.inf])

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            tsn = timescales(self.W)
            assert_allclose(tsn, ts)
            assert issubclass(w[-1].category, SpectralWarning)
Esempio n. 24
0
 def test_fingerprint(self):
     k = self.k
     amp = np.dot(self.p0 * self.obs1, self.R) * np.dot(self.L, self.obs2)
     tsn, ampn = fingerprint(self.T,
                             self.obs1,
                             obs2=self.obs2,
                             p0=self.p0,
                             k=k)
     assert_allclose(tsn, self.ts)
     assert_allclose(ampn, amp)
Esempio n. 25
0
    def test_fingerprint_relaxation(self):
        one_vec = np.ones(self.T.shape[0])

        relax_amp = np.dot(self.p0, self.R) * np.dot(self.L, self.obs1)
        tsn, relax_ampn = fingerprint_relaxation(self.T,
                                                 self.p0,
                                                 self.obs1,
                                                 k=self.k)
        assert_allclose(tsn, self.ts)
        assert_allclose(relax_ampn, relax_amp)
Esempio n. 26
0
 def test_pcca_4(self):
     P = np.array([[0.9, 0.1, 0.0, 0.0],
                   [0.1, 0.8, 0.1, 0.0],
                   [0.0, 0.0, 0.8, 0.2],
                   [0.0, 0.0, 0.2, 0.8]])
     chi = pcca(P, 2)
     sol = np.array([[1., 0.],
                     [1., 0.],
                     [1., 0.],
                     [0., 1.]])
     assert_allclose(chi, sol)
Esempio n. 27
0
 def test_expected_counts_stationary(self):
     T = self.T
     N = 20
     """Compute mu on the fly"""
     EC_n = expected_counts_stationary(T, N)
     EC_true = N * self.mu[:, np.newaxis] * T
     assert_allclose(EC_true, EC_n)
     """Use precomputed mu"""
     EC_n = expected_counts_stationary(T, N, mu=self.mu)
     EC_true = N * self.mu[:, np.newaxis] * T
     assert_allclose(EC_true, EC_n)
Esempio n. 28
0
 def test_eigenvalues(self):
     P = self.bdc.transition_matrix()
     ev = eigvals(P)
     """Sort with decreasing magnitude"""
     ev = ev[np.argsort(np.abs(ev))[::-1]]
     """k=None"""
     evn = eigenvalues(P)
     assert_allclose(ev, evn)
     """k is not None"""
     evn = eigenvalues(P, k=self.k)
     assert_allclose(ev[0:self.k], evn)
Esempio n. 29
0
 def test_eigenvalues_reversible(self):
     P = self.bdc.transition_matrix()
     ev = eigvals(P)
     """Sort with decreasing magnitude"""
     ev = ev[np.argsort(np.abs(ev))[::-1]]
     """reversible without given mu"""
     evn = eigenvalues(P, reversible=True)
     assert_allclose(ev, evn)
     """reversible with given mu"""
     evn = eigenvalues(P,
                       reversible=True,
                       mu=self.bdc.stationary_distribution())
     assert_allclose(ev, evn)
Esempio n. 30
0
 def test_relaxation(self):
     """k=None"""
     relax_amp = np.dot(self.p0, self.R) * np.dot(self.L, self.obs)
     relax = np.dot(self.ev_t, relax_amp)
     relaxn = relaxation(self.T, self.p0, self.obs, times=self.times)
     assert_allclose(relaxn, relax)
     """k=4"""
     k = self.k
     relax_amp = np.dot(self.p0, self.R[:, 0:k]) * np.dot(
         self.L[0:k, :], self.obs)
     relax = np.dot(self.ev_t[:, 0:k], relax_amp)
     relaxn = relaxation(self.T, self.p0, self.obs, k=k, times=self.times)
     assert_allclose(relaxn, relax)