Exemplo n.º 1
0
    def setUp(self):
        self.k = 4

        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.bdc = birth_death_chain(q, p)

        self.mu = self.bdc.stationary_distribution
        self.T = self.bdc.transition_matrix_sparse
        R, D, L = rdl_decomposition(self.T, k=self.k)
        self.L = L
        self.R = R
        self.ts = timescales(self.T, k=self.k)
        self.times = np.array([1, 5, 10, 20, 100])

        ev = np.diagonal(D)
        self.ev_t = ev[np.newaxis, :]**self.times[:, np.newaxis]

        obs1 = np.zeros(10)
        obs1[0] = 1
        obs1[1] = 1
        obs2 = np.zeros(10)
        obs2[8] = 1
        obs2[9] = 1

        self.obs1 = obs1
        self.obs2 = obs2
        self.one_vec = np.ones(10)
Exemplo n.º 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

        self.bdc = birth_death_chain(q, p)
        T_dense = self.bdc.transition_matrix
        T_sparse = csr_matrix(T_dense)
        self.T = T_sparse

        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)

        # present results
        self.fluxn = flux.flux_matrix(self.T, self.mu, self.qminus, self.qplus, netflux=False)
        self.netfluxn = flux.flux_matrix(self.T, self.mu, self.qminus, self.qplus, netflux=True)
        self.totalfluxn = flux.total_flux(self.netfluxn, self.A)
        self.raten = flux.rate(self.totalfluxn, self.mu, self.qminus)
Exemplo n.º 3
0
    def setUp(self):
        self.k = 4

        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.bdc = birth_death_chain(q, p)

        self.mu = self.bdc.stationary_distribution
        self.T = self.bdc.transition_matrix_sparse
        """Test matrix-vector product against spectral decomposition"""
        R, D, L = rdl_decomposition(self.T, k=self.k)
        self.L = L
        self.R = R
        self.ts = timescales(self.T, k=self.k)
        self.times = np.array([1, 5, 10, 20, 100])

        ev = np.diagonal(D)
        self.ev_t = ev[np.newaxis, :]**self.times[:, np.newaxis]
        """Observable"""
        obs1 = np.zeros(10)
        obs1[0] = 1
        obs1[1] = 1
        self.obs = obs1
        """Initial distribution"""
        w0 = np.zeros(10)
        w0[0:4] = 0.25
        self.p0 = w0
Exemplo n.º 4
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 = birth_death_chain(q, p)
        self.T = self.bdc.transition_matrix

        """Compute mu, qminus, qplus in constructor"""
        self.tpt = compute_reactive_flux(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 = compute_reactive_flux(self.T, self.A, self.B, stationary_distribution=self.mu,
                                              qminus=self.qminus, qplus=self.qplus)
Exemplo n.º 5
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 = birth_death_chain(q, p)
        self.T = self.bdc.transition_matrix
        """Use precomputed mu, qminus, qplus"""
        self.mu = self.bdc.stationary_distribution
        self.qplus = self.bdc.committor_forward(self.a, self.b)
        self.qminus = self.bdc.committor_backward(self.a, self.b)
        # self.qminus = committor.backward_committor(self.T, self.A, self.B, mu=self.mu)
        # self.qplus = committor.forward_committor(self.T, self.A, self.B)
        self.fluxn = tpt.flux_matrix(self.T,
                                     self.mu,
                                     self.qminus,
                                     self.qplus,
                                     netflux=False)
        self.netfluxn = tpt.to_netflux(self.fluxn)
        self.Fn = tpt.total_flux(self.fluxn, self.A)
        self.kn = tpt.rate(self.Fn, self.mu, self.qminus)
Exemplo n.º 6
0
def fingerprints_data(sparse_mode):
    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
    return birth_death_chain(q, p, sparse=sparse_mode)
Exemplo n.º 7
0
def bdc(sparse_mode):
    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
    bdc = birth_death_chain(q, p, sparse=sparse_mode)
    yield bdc
Exemplo n.º 8
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.bdc = birth_death_chain(q, p)
Exemplo n.º 9
0
def tpt_scenario_bd(sparse_mode):
    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

    bdc = birth_death_chain(q, p, sparse=sparse_mode)
    tpt = bdc.msm.reactive_flux([0, 1], [8, 9])
    return tpt, bdc
Exemplo n.º 10
0
def test_is_reversible(sparse_mode):
    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
    bdc = birth_death_chain(q, p, sparse=sparse_mode)
    assert_equal(sparse_mode, bdc.sparse)
    assert_equal(issparse(bdc.transition_matrix), sparse_mode)
    assert_(is_reversible(bdc.transition_matrix, bdc.stationary_distribution))
Exemplo n.º 11
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.bdc = birth_death_chain(q, p)

        self.mu = self.bdc.stationary_distribution
        self.T = self.bdc.transition_matrix
Exemplo n.º 12
0
def stationary_vector_data(sparse_mode):
    dim = 100

    """Set up meta-stable birth-death chain"""
    p = np.zeros(dim)
    p[0:-1] = 0.5

    q = np.zeros(dim)
    q[1:] = 0.5

    p[dim // 2 - 1] = 0.001
    q[dim // 2 + 1] = 0.001

    return birth_death_chain(q, p, sparse=sparse_mode)
Exemplo n.º 13
0
    def setUp(self):
        self.dim = 100
        self.k = 10
        """Set up meta-stable birth-death chain"""
        p = np.zeros(self.dim)
        p[0:-1] = 0.5

        q = np.zeros(self.dim)
        q[1:] = 0.5

        p[self.dim // 2 - 1] = 0.001
        q[self.dim // 2 + 1] = 0.001

        self.bdc = birth_death_chain(q, p)
Exemplo n.º 14
0
def scenario(request, sparse_mode):
    dim = 100
    """Set up meta-stable birth-death chain"""
    p = np.zeros(dim)
    p[0:-1] = 0.5

    q = np.zeros(dim)
    q[1:] = 0.5

    p[dim // 2 - 1] = 0.001
    q[dim // 2 + 1] = 0.001

    bdc = birth_death_chain(q, p, sparse=sparse_mode)
    yield request.param, bdc
Exemplo n.º 15
0
def test_amm_sanity(fixed_seed):
    # Meta-stable birth-death chain
    b = 2
    q = np.zeros(7)
    p = np.zeros(7)
    q[1:] = 0.5
    p[0:-1] = 0.5
    q[2] = 1.0 - 10 ** (-b)
    q[4] = 10 ** (-b)
    p[2] = 10 ** (-b)
    p[4] = 1.0 - 10 ** (-b)

    bdc = birth_death_chain(q, p)
    P = bdc.transition_matrix
    dtraj = MarkovStateModel(P).simulate(n_steps=10000, start=0)
    tau = 1

    k = 3
    # Predictions and experimental data
    E = np.vstack((np.linspace(-0.1, 1., 7), np.linspace(1.5, -0.1, 7))).T
    m = np.array([0.0, 0.0])
    w = np.array([2.0, 2.5])
    sigmas = 1. / np.sqrt(2) / np.sqrt(w)

    """ Feature trajectory """
    ftraj = E[dtraj, :]

    amm_estimator = AugmentedMSMEstimator(expectations_by_state=E, experimental_measurements=m,
                                          experimental_measurement_weights=w)
    counts = TransitionCountEstimator(lagtime=tau, count_mode="sliding").fit(dtraj).fetch_model()

    amm = amm_estimator.fit(counts).fetch_model()
    amm_convenience_estimator = AugmentedMSMEstimator.estimator_from_feature_trajectories(
        dtraj, ftraj, n_states=counts.n_states_full, experimental_measurements=m, sigmas=sigmas)
    amm_convenience = amm_convenience_estimator.fit(counts).fetch_model()
    assert_equal(tau, amm.lagtime)
    assert_array_almost_equal(E, amm_estimator.expectations_by_state)
    assert_array_almost_equal(E, amm_convenience_estimator.expectations_by_state, decimal=4)
    assert_array_almost_equal(m, amm_estimator.experimental_measurements)
    assert_array_almost_equal(m, amm_convenience_estimator.experimental_measurements)
    assert_array_almost_equal(w, amm_estimator.experimental_measurement_weights)
    assert_array_almost_equal(w, amm_convenience_estimator.experimental_measurement_weights)
    assert_array_almost_equal(amm.transition_matrix, amm_convenience.transition_matrix, decimal=4)
    assert_array_almost_equal(amm.stationary_distribution, amm_convenience.stationary_distribution, decimal=4)
    assert_array_almost_equal(amm.optimizer_state.lagrange, amm_convenience.optimizer_state.lagrange, decimal=4)
Exemplo n.º 16
0
    def setUp(self):
        self.k = 4

        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.bdc = birth_death_chain(q, p)

        self.mu = self.bdc.stationary_distribution
        self.T = self.bdc.transition_matrix_sparse
        R, D, L = rdl_decomposition(self.T, k=self.k)
        self.L = L
        self.R = R
        self.ts = timescales(self.T, k=self.k)
        self.times = np.array([1, 5, 10, 20])

        ev = np.diagonal(D)
        self.ev_t = ev[np.newaxis, :]**self.times[:, np.newaxis]

        self.tau = 7.5
        """Observables"""
        obs1 = np.zeros(10)
        obs1[0] = 1
        obs1[1] = 1
        obs2 = np.zeros(10)
        obs2[8] = 1
        obs2[9] = 1

        self.obs1 = obs1
        self.obs2 = obs2
        """Initial vector for relaxation"""
        w0 = np.zeros(10)
        w0[0:4] = 0.25
        self.p0 = w0
Exemplo n.º 17
0
import matplotlib.pyplot as plt

from deeptime.data import birth_death_chain

n_states = 7
b = 2
q = np.zeros(n_states)
p = np.zeros(n_states)
q[1:] = 0.5
p[0:-1] = 0.5
q[2] = 1.0 - 10**(-b)
q[4] = 10**(-b)
p[2] = 10**(-b)
p[4] = 1.0 - 10**(-b)

bd = birth_death_chain(q, p)
dtraj = bd.msm.simulate(100000)

bins = np.arange(0, dtraj.max() + 1.5) - 0.5

fig, ax = plt.subplots()
ax.set_xticks(bins + 0.5)
ax.vlines(bins, ymin=0, ymax=.3, zorder=1, color='black', linestyles='dashed')
ax.hist(dtraj,
        bins,
        density=True,
        alpha=.5,
        color='C0',
        label='Empirical distribution')
ax.bar(np.arange(n_states),
       bd.stationary_distribution,