示例#1
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)
 def test_hitting2(self):
     P = np.array([[1.0, 0.0, 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]])
     sol = np.array([0., 0.5, 1., 1.])
     assert_allclose(hitting_probability(P, [2, 3]), sol)
示例#3
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)
示例#4
0
    def test_count_matrix(self):
        """Small test cases"""
        C = count_matrix([self.S1, self.S2], 1, sliding=True).toarray()
        assert_allclose(C, self.B1_sliding)

        C = count_matrix([self.S1, self.S2], 2, sliding=True).toarray()
        assert_allclose(C, self.B2_sliding)
示例#5
0
    def test_count_matrix(self):
        """Small test cases"""
        C = count_matrix([self.S1, self.S2], 1, sliding=True).toarray()
        assert_allclose(C, self.B1_sliding)

        C = count_matrix([self.S1, self.S2], 2, sliding=True).toarray()
        assert_allclose(C, self.B2_sliding)
示例#6
0
 def test_hitting2(self):
     P = np.array([[1.0, 0.0, 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]])
     sol = np.array([ 0. ,  0.5,  1. ,  1. ])
     assert_allclose(hitting_probability(P, [2,3]), sol)
示例#7
0
 def test_hitting1(self):
     P = np.array([[ 0.,  1.,  0.],
                   [ 0.,  1.,  0.],
                   [ 0.,  0.,  1.]])
     sol = np.array([1,0,0])
     assert_allclose(hitting_probability(P, 1), sol)
     assert_allclose(hitting_probability(P, [1,2]), sol)
示例#8
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)
 def test_hitting1(self):
     P = np.array([[0., 1., 0.],
                   [0., 1., 0.],
                   [0., 0., 1.]])
     sol = np.array([1, 0, 0])
     assert_allclose(hitting_probability(P, 1), sol)
     assert_allclose(hitting_probability(P, [1, 2]), sol)
示例#10
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)
示例#11
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)
示例#12
0
    def test_pathways_sparse(self):
        paths, capacities = pathways(self.F_sparse, 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])
示例#13
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)
示例#14
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)
示例#15
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)
示例#16
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)
示例#17
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)
示例#18
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)
示例#19
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)
示例#20
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)
示例#21
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)
示例#22
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)
示例#23
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)
示例#24
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)
示例#25
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)
示例#26
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)
示例#27
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)
示例#28
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)
示例#29
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)
 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)
示例#31
0
 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)
示例#32
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)
示例#33
0
 def test_cktest_njobs_3(self):
     # introduce a (fake) third set in order to model incomplete partition.
     memberships = np.array([[1, 0, 0], [1, 0, 0], [1, 0, 0], [0, 1, 0],
                             [0, 0, 1], [0, 0, 1], [0, 0, 1]])
     ck = self.MSM.cktest(3, memberships=memberships, n_jobs=3)
     p_MSM = np.vstack([ck.predictions[:, 0, 0], ck.predictions[:, 2, 2]]).T
     assert_allclose(p_MSM, self.p_MSM)
     p_MD = np.vstack([ck.estimates[:, 0, 0], ck.estimates[:, 2, 2]]).T
     assert_allclose(p_MD, self.p_MD)
示例#34
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)
示例#35
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)
示例#36
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)
示例#37
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)
示例#38
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)
示例#39
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())
示例#40
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)
示例#41
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)
示例#42
0
def test_cktest(n_jobs, cktest_resource):
    # introduce a (fake) third set in order to model incomplete partition.
    memberships = np.array([[1, 0, 0], [1, 0, 0], [1, 0, 0], [0, 1, 0],
                            [0, 0, 1], [0, 0, 1], [0, 0, 1]])
    MSM, p_MSM, p_MD = cktest_resource
    ck = MSM.cktest(3, memberships=memberships, n_jobs=n_jobs)
    p_MSM = np.vstack([ck.predictions[:, 0, 0], ck.predictions[:, 2, 2]]).T
    assert_allclose(p_MSM, p_MSM)
    p_MD = np.vstack([ck.estimates[:, 0, 0], ck.estimates[:, 2, 2]]).T
    assert_allclose(p_MD, p_MD)
示例#43
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)

        with warnings.catch_warnings(record=True) as w:
            Xn = error_perturbation(Csparse, self.S2)
            assert_allclose(Xn, self.X)
示例#44
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)
示例#45
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)
示例#46
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)
示例#47
0
 def test_AMM(self):
     """ self-consistency, explicit class instantiation/estimation and convienence function """
     amm = estimate_augmented_markov_model([self.dtraj], [self.ftraj], self.tau, self.m, self.sigmas)
     assert_allclose(self.dtraj, amm.discrete_trajectories_full[0])
     self.assertEqual(self.tau, amm.lagtime)
     self.assertTrue(np.allclose(self.E, amm.E))
     self.assertTrue(np.allclose(self.m, amm.m))
     self.assertTrue(np.allclose(self.w, amm.w))
     self.assertTrue(np.allclose(self.AMM.P, amm.P))
     self.assertTrue(np.allclose(self.AMM.pi, amm.pi))
     self.assertTrue(np.allclose(self.AMM.lagrange, amm.lagrange))
示例#48
0
 def test_cktest_njobs_2(self):
     # introduce a (fake) third set in order to model incomplete partition.
     memberships = np.array([[1, 0, 0], [1, 0, 0], [1, 0, 0], [0, 1, 0],
                             [0, 0, 1], [0, 0, 1], [0, 0, 1]])
     ck = self.MSM.cktest(3, memberships=memberships, n_jobs=2)
     p_MSM = np.vstack([ck.predictions[:, 0, 0], ck.predictions[:, 2, 2]]).T
     assert_allclose(p_MSM, self.p_MSM)
     p_MD = np.vstack([ck.estimates[:, 0, 0], ck.estimates[:, 2, 2]]).T
     assert_allclose(
         p_MD, self.p_MD, rtol=1e-4, atol=1e-6
     )  # decreased tolerance due to otherwise spurious failures
示例#49
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)
示例#50
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)
示例#51
0
    def test_geometric_series(self):
        x = expectations.geometric_series(self.q, self.n)
        assert_allclose(x, self.s)

        x = expectations.geometric_series(self.q_array, self.n)
        assert_allclose(x, self.s_array)
        """Assert ValueError for negative n"""
        with self.assertRaises(ValueError):
            expectations.geometric_series(self.q, -2)

        with self.assertRaises(ValueError):
            expectations.geometric_series(self.q_array, -2)
示例#52
0
    def test_correlation(self):
        """Auto-correlation"""
        acorr_amp = np.dot(self.mu * self.obs1, self.R) * np.dot(self.L, self.obs1)
        acorr = np.dot(self.ev_t, acorr_amp)
        acorrn = correlation(self.T, self.obs1, k=self.k, times=self.times)
        assert_allclose(acorrn, acorr)

        """Cross-correlation"""
        corr_amp = np.dot(self.mu * self.obs1, self.R) * np.dot(self.L, self.obs2)
        corr = np.dot(self.ev_t, corr_amp)
        corrn = correlation(self.T, self.obs1, obs2=self.obs2, k=self.k, times=self.times)
        assert_allclose(corrn, corr)
示例#53
0
    def test_expected_counts_stationary(self):
        T = self.T
        N = 20

        """Compute mu on the fly"""
        EC_n = expectations.expected_counts_stationary(T, N)
        EC_true = N * self.mu[:, np.newaxis] * T
        assert_allclose(EC_true, EC_n)

        """Use precomputed mu"""
        EC_n = expectations.expected_counts_stationary(T, N, mu=self.mu)
        EC_true = N * self.mu[:, np.newaxis] * T
        assert_allclose(EC_true, EC_n)
示例#54
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)
示例#55
0
    def test_geometric_series(self):
        x = expectations.geometric_series(self.q, self.n)
        assert_allclose(x, self.s)

        x = expectations.geometric_series(self.q_array, self.n)
        assert_allclose(x, self.s_array)

        """Assert ValueError for negative n"""
        with self.assertRaises(ValueError):
            expectations.geometric_series(self.q, -2)

        with self.assertRaises(ValueError):
            expectations.geometric_series(self.q_array, -2)
示例#56
0
    def test_time_relaxations(self):
        obs = np.zeros(10)
        obs[9] = 1

        p0 = np.zeros(10) * 1. / 10
        times = [1, 100, 1000]
        expected = []
        for t in times:
            expected.append(correlations.time_relaxation_direct_by_mtx_vec_prod(self.T, p0, obs, t))

        result = correlations.time_relaxations_direct(self.T, p0, obs, times)

        assert_allclose(expected, result)
示例#57
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)
示例#58
0
    def test_eigenvectors(self):
        P_dense = self.bdc.transition_matrix()
        P = self.bdc.transition_matrix_sparse()
        ev, L, R = eig(P_dense, left=True, right=True)
        ind = np.argsort(np.abs(ev))[::-1]
        ev = ev[ind]
        R = R[:, ind]
        L = L[:, ind]
        vals = ev[0:self.k]

        """k=None"""
        with self.assertRaises(ValueError):
            Rn = eigenvectors(P)

        with self.assertRaises(ValueError):
            Ln = eigenvectors(P, right=False)

        """k is not None"""
        Rn = eigenvectors(P, k=self.k)
        assert_allclose(vals[np.newaxis, :] * Rn, P.dot(Rn))

        Ln = eigenvectors(P, right=False, k=self.k)
        assert_allclose(P.transpose().dot(Ln), vals[np.newaxis, :] * Ln)

        """k is not None and ncv is not None"""
        Rn = eigenvectors(P, k=self.k, ncv=self.ncv)
        assert_allclose(vals[np.newaxis, :] * Rn, P.dot(Rn))

        Ln = eigenvectors(P, right=False, k=self.k, ncv=self.ncv)
        assert_allclose(P.transpose().dot(Ln), vals[np.newaxis, :] * Ln)