Example #1
0
    def setUp(self):
        p = np.zeros(10)
        q = np.zeros(10)
        p[0:-1] = 0.5
        q[1:] = 0.5
        p[4] = 0.01
        q[6] = 0.1

        self.A = [0, 1]
        self.B = [8, 9]
        self.a = 1
        self.b = 8

        self.bdc = BirthDeathChain(q, p)
        T_dense = self.bdc.transition_matrix()
        T_sparse = csr_matrix(T_dense)
        self.T = T_sparse
        """Compute mu, qminus, qplus in constructor"""
        self.tpt = flux.tpt(self.T, self.A, self.B)
        """Use precomputed mu, qminus, qplus"""
        self.mu = self.bdc.stationary_distribution()
        self.qminus = self.bdc.committor_backward(self.a, self.b)
        self.qplus = self.bdc.committor_forward(self.a, self.b)
        self.tpt_fast = flux.tpt(self.T,
                                 self.A,
                                 self.B,
                                 mu=self.mu,
                                 qminus=self.qminus,
                                 qplus=self.qplus)
Example #2
0
    def setUp(self):
        p = np.zeros(10)
        q = np.zeros(10)
        p[0:-1] = 0.5
        q[1:] = 0.5
        p[4] = 0.01
        q[6] = 0.1

        self.A = [0, 1]
        self.B = [8, 9]
        self.a = 1
        self.b = 8

        import msmtools.analysis.dense.birth_death_chain

        self.bdc = msmtools.analysis.dense.birth_death_chain.BirthDeathChain(
            q, p)
        self.T = self.bdc.transition_matrix()
        """Compute mu, qminus, qplus in constructor"""
        self.tpt = flux.tpt(self.T, self.A, self.B)
        """Use precomputed mu, qminus, qplus"""
        self.mu = self.bdc.stationary_distribution()
        self.qminus = self.bdc.committor_backward(self.a, self.b)
        self.qplus = self.bdc.committor_forward(self.a, self.b)
        self.tpt_fast = flux.tpt(self.T,
                                 self.A,
                                 self.B,
                                 mu=self.mu,
                                 qminus=self.qminus,
                                 qplus=self.qplus)
Example #3
0
 def test_flux(self):
     r = tpt(self.P, self.A, self.B)
     fig, pos = plot_flux(r)
     assert type(fig) is matplotlib.figure.Figure
     #        matplotlib.pyplot.show(fig)
     # x values should be close to committor
     np.testing.assert_allclose(pos[:, 0], r.committor)
Example #4
0
    def __init__(self, EvoMSM, source, target):
        self.msm = EvoMSM
        self.source = source
        self.target = target

        self.ReactiveFlux = tpt(self.msm.transition_matrix, self.source, self.target)
        self.net_flux = self.ReactiveFlux.net_flux
        self.total_flux = self.ReactiveFlux.total_flux
        self.forward_committor = self.ReactiveFlux.forward_committor
        self.backward_committor = self.ReactiveFlux.backward_committor
Example #5
0
    def test_with_almost_converged_stat_dist(self):
        """ test for #106 """
        from msmtools.analysis import committor, is_reversible
        from msmtools.flux import tpt, flux_matrix, to_netflux, ReactiveFlux

        T = np.array([[
            0.2576419223095193, 0.2254214623509954, 0.248270708174756,
            0.2686659071647294
        ],
                      [
                          0.2233847186210225, 0.2130434781715344,
                          0.2793477268264001, 0.284224076381043
                      ],
                      [
                          0.2118717275169231, 0.2405661227681972,
                          0.2943396213976011, 0.2532225283172787
                      ],
                      [
                          0.2328617711043517, 0.2485926610067547,
                          0.2571819311236834, 0.2613636367652102
                      ]])
        mu = np.array([
            0.2306979668517676, 0.2328013892993006, 0.2703312416016573,
            0.2661694022472743
        ])
        assert is_reversible(T)
        np.testing.assert_allclose(mu.dot(T), mu)
        np.testing.assert_equal(mu.dot(T), T.T.dot(mu))
        A = [0]
        B = [1]

        # forward committor
        qplus = committor(T, A, B, forward=True, mu=mu)
        # backward committor
        if is_reversible(T, mu=mu):
            qminus = 1.0 - qplus
        else:
            qminus = committor(T, A, B, forward=False, mu=mu)

        tpt_obj = tpt(T, A, B)
        tpt_obj.major_flux(1.0)
        # gross flux
        grossflux = flux_matrix(T, mu, qminus, qplus, netflux=False)
        # net flux
        netflux = to_netflux(grossflux)
        F = ReactiveFlux(A,
                         B,
                         netflux,
                         mu=mu,
                         qminus=qminus,
                         qplus=qplus,
                         gross_flux=grossflux)
        F.pathways(1.0)
Example #6
0
    if len(transition) > 1:
        transitions.extend(transition)

topic_list = data.topic.unique().tolist()
topic_list = sorted(topic_list)

transition_matrix = np.zeros([len(topic_list), len(topic_list)]).astype(int)

for element in transitions:
    state1 = element[0]
    state2 = element[1]
    state1_index = topic_list.index(state1)
    state2_index = topic_list.index(state2)
    transition_matrix[state1_index,
                      state2_index] = transition_matrix[state1_index,
                                                        state2_index] + 1

transition_matrix_scaled = (transition_matrix.T /
                            transition_matrix.sum(axis=1)).T

mm = msm.markov_model(transition_matrix_scaled)

for element in mm.eigenvalues().argsort()[::-1]:
    print(topic_list[element])
transition_matrix_scaled = sparse.csr_matrix(transition_matrix_scaled)
flux = tpt(transition_matrix_scaled, [1], [2])

pdb.set_trace()
chain = MarkovChain(transition_matrix=transition_matrix, states=topic_list)
pdb.set_trace()
Example #7
0
 def test_random(self):
     C = np.random.randint(0, 1000, size=(10, 10))
     P = msmtools.estimation.transition_matrix(C, reversible=True)
     r = tpt(P, [0], [len(C) - 1])
     fig, pos = plot_flux(r)