Exemple #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 = deeptime.data.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
Exemple #2
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 = deeptime.data.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)
Exemple #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 = deeptime.data.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
Exemple #4
0
    def test_rdl_decomposition_rev(self):
        P = self.bdc.transition_matrix_sparse
        mu = self.bdc.stationary_distribution
        """Non-reversible"""
        """k=None"""
        with self.assertRaises(ValueError):
            Rn, Dn, Ln = rdl_decomposition(P, reversible=True)
        """norm='standard'"""
        Rn, Dn, Ln = rdl_decomposition(P,
                                       k=self.k,
                                       reversible=True,
                                       norm='standard')
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                        np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.k))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)
        """Standard l2-normalization of right eigenvectors except dominant one"""
        Yn = np.dot(Rn.T, Rn)
        assert_allclose(np.diag(Yn)[1:], 1.0)
        """ncv is not None"""
        Rn, Dn, Ln = rdl_decomposition(P,
                                       k=self.k,
                                       reversible=True,
                                       norm='standard',
                                       ncv=self.ncv)
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                        np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.k))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)
        """Standard l2-normalization of right eigenvectors except dominant one"""
        Yn = np.dot(Rn.T, Rn)
        assert_allclose(np.diag(Yn)[1:], 1.0)
        """norm='reversible'"""
        Rn, Dn, Ln = rdl_decomposition(P,
                                       reversible=True,
                                       norm='reversible',
                                       k=self.k)
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                        np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.k))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)
        """Reversibility"""
        assert_allclose(Ln.transpose(), mu[:, np.newaxis] * Rn)

        Rn, Dn, Ln = rdl_decomposition(P,
                                       reversible=True,
                                       norm='reversible',
                                       k=self.k,
                                       ncv=self.ncv)
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                        np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.k))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)
        """Reversibility"""
        assert_allclose(Ln.transpose(), mu[:, np.newaxis] * Rn)
        """mu is not None"""
        """norm='standard'"""
        Rn, Dn, Ln = rdl_decomposition(P,
                                       k=self.k,
                                       reversible=True,
                                       norm='standard',
                                       mu=mu)
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                        np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.k))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)
        """Standard l2-normalization of right eigenvectors except dominant one"""
        Yn = np.dot(Rn.T, Rn)
        assert_allclose(np.diag(Yn)[1:], 1.0)
        """ncv is not None"""
        Rn, Dn, Ln = rdl_decomposition(P,
                                       k=self.k,
                                       reversible=True,
                                       norm='standard',
                                       ncv=self.ncv,
                                       mu=mu)
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                        np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.k))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)
        """Standard l2-normalization of right eigenvectors except dominant one"""
        Yn = np.dot(Rn.T, Rn)
        assert_allclose(np.diag(Yn)[1:], 1.0)
        """norm='reversible'"""
        Rn, Dn, Ln = rdl_decomposition(P,
                                       reversible=True,
                                       norm='reversible',
                                       k=self.k,
                                       mu=mu)
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                        np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.k))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)
        """Reversibility"""
        assert_allclose(Ln.transpose(), mu[:, np.newaxis] * Rn)

        Rn, Dn, Ln = rdl_decomposition(P,
                                       reversible=True,
                                       norm='reversible',
                                       k=self.k,
                                       ncv=self.ncv,
                                       mu=mu)
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                        np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.k))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)
        """Reversibility"""
        assert_allclose(Ln.transpose(), mu[:, np.newaxis] * Rn)
Exemple #5
0
 def test_rdl_decomposition(self):
     P = self.bdc.transition_matrix_sparse
     mu = self.bdc.stationary_distribution
     """Non-reversible"""
     """k=None"""
     with self.assertRaises(ValueError):
         Rn, Dn, Ln = rdl_decomposition(P)
     """k is not None"""
     Rn, Dn, Ln = rdl_decomposition(P, k=self.k)
     Xn = np.dot(Ln, Rn)
     """Right-eigenvectors"""
     assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
     """Left-eigenvectors"""
     assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                     np.dot(Dn, Ln))
     """Orthonormality"""
     assert_allclose(Xn, np.eye(self.k))
     """Probability vector"""
     assert_allclose(np.sum(Ln[0, :]), 1.0)
     """k is not None, ncv is not None"""
     Rn, Dn, Ln = rdl_decomposition(P, k=self.k, ncv=self.ncv)
     Xn = np.dot(Ln, Rn)
     """Right-eigenvectors"""
     assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
     """Left-eigenvectors"""
     assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                     np.dot(Dn, Ln))
     """Orthonormality"""
     assert_allclose(Xn, np.eye(self.k))
     """Probability vector"""
     assert_allclose(np.sum(Ln[0, :]), 1.0)
     """Reversible"""
     """k=None"""
     with self.assertRaises(ValueError):
         Rn, Dn, Ln = rdl_decomposition(P, norm='reversible')
     """k is not None"""
     Rn, Dn, Ln = rdl_decomposition(P, k=self.k, norm='reversible')
     Xn = np.dot(Ln, Rn)
     """Right-eigenvectors"""
     assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
     """Left-eigenvectors"""
     assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                     np.dot(Dn, Ln))
     """Orthonormality"""
     assert_allclose(Xn, np.eye(self.k))
     """Probability vector"""
     assert_allclose(np.sum(Ln[0, :]), 1.0)
     """Reversibility"""
     assert_allclose(Ln.transpose(), mu[:, np.newaxis] * Rn)
     """k is not None ncv is not None"""
     Rn, Dn, Ln = rdl_decomposition(P,
                                    k=self.k,
                                    norm='reversible',
                                    ncv=self.ncv)
     Xn = np.dot(Ln, Rn)
     """Right-eigenvectors"""
     assert_allclose(P.dot(Rn), np.dot(Rn, Dn))
     """Left-eigenvectors"""
     assert_allclose(P.transpose().dot(Ln.transpose()).transpose(),
                     np.dot(Dn, Ln))
     """Orthonormality"""
     assert_allclose(Xn, np.eye(self.k))
     """Probability vector"""
     assert_allclose(np.sum(Ln[0, :]), 1.0)
     """Reversibility"""
     assert_allclose(Ln.transpose(), mu[:, np.newaxis] * Rn)