當前位置: 首頁>>代碼示例>>Python>>正文


Python BirthDeathChain.stationary_distribution方法代碼示例

本文整理匯總了Python中birth_death_chain.BirthDeathChain.stationary_distribution方法的典型用法代碼示例。如果您正苦於以下問題:Python BirthDeathChain.stationary_distribution方法的具體用法?Python BirthDeathChain.stationary_distribution怎麽用?Python BirthDeathChain.stationary_distribution使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在birth_death_chain.BirthDeathChain的用法示例。


在下文中一共展示了BirthDeathChain.stationary_distribution方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestRelaxationDense

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestRelaxationDense(unittest.TestCase):
    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=BirthDeathChain(q, p)
        
        self.mu = self.bdc.stationary_distribution()
        self.T = self.bdc.transition_matrix()

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

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

        self.k=4

        """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     

    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)        
        self.assertTrue(np.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) 
        self.assertTrue(np.allclose(relaxn, relax))
開發者ID:greglever,項目名稱:PyEMMA,代碼行數:52,代碼來源:test_fingerprints.py

示例2: TestCorrelationSparse

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestCorrelationSparse(unittest.TestCase):
    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=BirthDeathChain(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)

    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)
        self.assertTrue(np.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)
        self.assertTrue(np.allclose(corrn, corr))    
開發者ID:greglever,項目名稱:PyEMMA,代碼行數:50,代碼來源:test_fingerprints.py

示例3: TestAssessmentDense

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestAssessmentDense(unittest.TestCase):
    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 = BirthDeathChain(q, p)
        self.T = self.bdc.transition_matrix()
        self.mu = self.bdc.stationary_distribution()

        self.A = create_rate_matrix()

    def test_IsRateMatrix(self):
        self.assert_(is_rate_matrix(self.A), 'A should be a rate matrix')

        # manipulate matrix so it isn't a rate matrix any more
        self.A[0][0] = 3
        self.assertFalse(is_rate_matrix(self.A), 'matrix is not a rate matrix')

    def test_IsReversible(self):
        # create a reversible matrix
        self.assertTrue(is_reversible(self.T, self.mu),
                        "T should be reversible")

    def test_is_transition_matrix(self):
        self.assertTrue(is_transition_matrix(self.T))

        """Larger test-case to prevent too restrictive tolerance settings"""
        X = np.random.random((2000, 2000))
        Tlarge = X / X.sum(axis=1)[:, np.newaxis]
        self.assertTrue(is_transition_matrix(Tlarge))

    def test_is_connected(self):
        self.assertTrue(is_connected(self.T))
        self.assertTrue(is_connected(self.T, directed=False))
開發者ID:ismaelresp,項目名稱:PyEMMA,代碼行數:40,代碼來源:test_assessment.py

示例4: TestExpectation

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestExpectation(unittest.TestCase):
    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=BirthDeathChain(q, p)
        
        self.mu = self.bdc.stationary_distribution()
        self.T = self.bdc.transition_matrix()

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

        self.obs1=obs1

    def test_expectation(self):
        exp=np.dot(self.mu, self.obs1)
        expn=expectation(self.T, self.obs1)
        self.assertTrue(np.allclose(exp, expn)) 
開發者ID:greglever,項目名稱:PyEMMA,代碼行數:26,代碼來源:test_fingerprints.py

示例5: TestAssessmentDense

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestAssessmentDense(unittest.TestCase):
    
    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 = BirthDeathChain(q, p)
        self.T = self.bdc.transition_matrix()
        self.mu = self.bdc.stationary_distribution()

        self.A = create_rate_matrix()

    def test_IsRateMatrix(self):
        self.assert_(is_rate_matrix(self.A), \
                     'A should be a rate matrix')
        
        # manipulate matrix so it isn't a rate matrix any more
        self.A[0][0] = 3
        self.assertFalse(is_rate_matrix(self.A), \
                        'matrix is not a rate matrix')
    
    def test_IsReversible(self):
        # create a reversible matrix
        self.assertTrue(is_reversible(self.T, self.mu),
                        "T should be reversible")

    def test_is_transition_matrix(self):
        self.assertTrue(is_transition_matrix(self.T))

    def test_is_connected(self):
        self.assertTrue(is_connected(self.T))
        self.assertTrue(is_connected(self.T, directed=False))
開發者ID:greglever,項目名稱:PyEMMA,代碼行數:38,代碼來源:test_assessment.py

示例6: TestDecomposition

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestDecomposition(unittest.TestCase):
    def setUp(self):
        self.dim=100
        self.k=10
        self.ncv=40
        
        """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=BirthDeathChain(q, p)

    def test_statdist_decomposition(self):
        P=self.bdc.transition_matrix_sparse()
        mu=self.bdc.stationary_distribution()
        mun=stationary_distribution_from_eigenvector(P, ncv=self.ncv)
        self.assertTrue(np.allclose(mu, mun))

    def test_statdist_iteration(self):
        P=self.bdc.transition_matrix_sparse()
        mu=self.bdc.stationary_distribution()
        mun=stationary_distribution_from_backward_iteration(P)
        self.assertTrue(np.allclose(mu, mun))

    def test_eigenvalues(self):
        P=self.bdc.transition_matrix()
        P_dense=self.bdc.transition_matrix()
        ev=eigvals(P_dense)
        """Sort with decreasing magnitude"""
        ev=ev[np.argsort(np.abs(ev))[::-1]]
        
        """k=None"""
        with self.assertRaises(ValueError):
            evn=eigenvalues(P)
        
        """k is not None"""
        evn=eigenvalues(P, k=self.k)
        self.assertTrue(np.allclose(ev[0:self.k], evn))

        """k is not None and ncv is not None"""
        evn=eigenvalues(P, k=self.k, ncv=self.ncv)
        self.assertTrue(np.allclose(ev[0:self.k], evn))

    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)        
        self.assertTrue(np.allclose(vals[np.newaxis,:]*Rn, P.dot(Rn)))

        Ln=eigenvectors(P, right=False, k=self.k)
        self.assertTrue(np.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)        
        self.assertTrue(np.allclose(vals[np.newaxis,:]*Rn, P.dot(Rn)))

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

    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"""
        self.assertTrue(np.allclose(P.dot(Rn), np.dot(Rn, Dn)))    
        """Left-eigenvectors"""
        self.assertTrue(np.allclose(P.transpose().dot(Ln.transpose()).transpose(), np.dot(Dn, Ln)))               
        """Orthonormality"""
        self.assertTrue(np.allclose(Xn, np.eye(self.k)))
        """Probability vector"""
#.........這裏部分代碼省略.........
開發者ID:greglever,項目名稱:PyEMMA,代碼行數:103,代碼來源:decomposition_test.py

示例7: TestFingerprintSparse

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestFingerprintSparse(unittest.TestCase):
    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=BirthDeathChain(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     

    def test_fingerprint_correlation(self):
        """Autocorrelation"""

        """k=4, tau=1"""
        k=self.k
        acorr_amp=np.dot(self.mu*self.obs1, self.R)*np.dot(self.L,self.obs1)
        tsn, acorr_ampn=fingerprint_correlation(self.T, self.obs1, k=k)
        self.assertTrue(np.allclose(tsn, self.ts))
        self.assertTrue(np.allclose(acorr_ampn, acorr_amp))

        """k=4, tau=7.5"""
        tau=self.tau
        tsn, acorr_ampn=fingerprint_correlation(self.T, self.obs1, k=k, tau=tau)
        self.assertTrue(np.allclose(tsn, tau*self.ts))
        self.assertTrue(np.allclose(acorr_ampn, acorr_amp))

        """Cross-correlation"""

        """k=4, tau=1"""
        k=self.k
        corr_amp=np.dot(self.mu*self.obs1, self.R)*np.dot(self.L,self.obs2)
        tsn, corr_ampn=fingerprint_correlation(self.T, self.obs1, obs2=self.obs2, k=k)
        self.assertTrue(np.allclose(tsn, self.ts))
        self.assertTrue(np.allclose(corr_ampn, corr_amp))

        """k=4, tau=7.5"""
        tau=self.tau
        tsn, corr_ampn=fingerprint_correlation(self.T, self.obs1, obs2=self.obs2, k=k, tau=tau)
        self.assertTrue(np.allclose(tsn, tau*self.ts))
        self.assertTrue(np.allclose(corr_ampn, corr_amp))

    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)        
        self.assertTrue(np.allclose(tsn, self.ts))
        self.assertTrue(np.allclose(relax_ampn, relax_amp))
開發者ID:greglever,項目名稱:PyEMMA,代碼行數:82,代碼來源:test_fingerprints.py

示例8: TestCorrelationDense

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestCorrelationDense(unittest.TestCase):
    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 = BirthDeathChain(q, p)

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

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

        self.k = 4

        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)

    def test_correlation(self):
        """Auto-correlation"""

        """k=None"""
        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, times=self.times)
        assert_allclose(acorrn, acorr)

        """k=4"""
        k = self.k
        acorr_amp = np.dot(self.mu * self.obs1, self.R[:, 0:k]) * np.dot(self.L[0:k, :], self.obs1)
        acorr = np.dot(self.ev_t[:, 0:k], acorr_amp)
        acorrn = correlation(self.T, self.obs1, times=self.times, k=k)
        assert_allclose(acorrn, acorr)

        """Cross-correlation"""

        """k=None"""
        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, times=self.times)
        assert_allclose(corrn, corr)

        """k=4"""
        k = self.k
        corr_amp = np.dot(self.mu * self.obs1, self.R[:, 0:k]) * np.dot(self.L[0:k, :], self.obs2)
        corr = np.dot(self.ev_t[:, 0:k], corr_amp)
        corrn = correlation(self.T, self.obs1, obs2=self.obs2, times=self.times, k=k)
        assert_allclose(corrn, corr)
開發者ID:ismaelresp,項目名稱:PyEMMA,代碼行數:67,代碼來源:test_fingerprints.py

示例9: TestDecompositionDense

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestDecompositionDense(unittest.TestCase):
    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 = BirthDeathChain(q, p)

    def test_statdist(self):
        P = self.bdc.transition_matrix()
        mu = self.bdc.stationary_distribution()
        mun = stationary_distribution(P)
        assert_allclose(mu, mun)

    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)

    def test_eigenvectors(self):
        P = self.bdc.transition_matrix()

        # k==None
        ev = eigvals(P)
        ev = ev[np.argsort(np.abs(ev))[::-1]]
        Dn = np.diag(ev)

        # right eigenvectors
        Rn = eigenvectors(P)
        assert_allclose(np.dot(P,Rn),np.dot(Rn,Dn))
        # left eigenvectors
        Ln = eigenvectors(P, right=False)
        assert_allclose(np.dot(Ln.T,P),np.dot(Dn,Ln.T))
        # orthogonality
        Xn = np.dot(Ln.T, Rn)
        di = np.diag_indices(Xn.shape[0])
        Xn[di] = 0.0
        assert_allclose(Xn,0)

        # k!=None
        Dnk = Dn[:,0:self.k][0:self.k,:]
        # right eigenvectors
        Rn = eigenvectors(P, k=self.k)
        assert_allclose(np.dot(P,Rn),np.dot(Rn,Dnk))
        # left eigenvectors
        Ln = eigenvectors(P, right=False, k=self.k)
        assert_allclose(np.dot(Ln.T,P),np.dot(Dnk,Ln.T))
        # orthogonality
        Xn = np.dot(Ln.T, Rn)
        di = np.diag_indices(self.k)
        Xn[di] = 0.0
        assert_allclose(Xn,0)

    def test_rdl_decomposition(self):
        P = self.bdc.transition_matrix()
        mu = self.bdc.stationary_distribution()

        """Non-reversible"""

        """k=None"""
        Rn, Dn, Ln = rdl_decomposition(P)
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(np.dot(P, Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(np.dot(Ln, P), np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.dim))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)

        """k is not None"""
        Rn, Dn, Ln = rdl_decomposition(P, k=self.k)
        Xn = np.dot(Ln, Rn)
        """Right-eigenvectors"""
        assert_allclose(np.dot(P, Rn), np.dot(Rn, Dn))
        """Left-eigenvectors"""
        assert_allclose(np.dot(Ln, P), np.dot(Dn, Ln))
        """Orthonormality"""
        assert_allclose(Xn, np.eye(self.k))
        """Probability vector"""
        assert_allclose(np.sum(Ln[0, :]), 1.0)
#.........這裏部分代碼省略.........
開發者ID:ismaelresp,項目名稱:PyEMMA,代碼行數:103,代碼來源:test_decomposition.py

示例10: TestDecompositionDense

# 需要導入模塊: from birth_death_chain import BirthDeathChain [as 別名]
# 或者: from birth_death_chain.BirthDeathChain import stationary_distribution [as 別名]
class TestDecompositionDense(unittest.TestCase):
    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=BirthDeathChain(q, p)

    def test_statdist(self):
        P=self.bdc.transition_matrix()
        mu=self.bdc.stationary_distribution()
        mun=stationary_distribution(P)
        self.assertTrue(np.allclose(mu, mun))

    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)
        self.assertTrue(np.allclose(ev, evn))
        
        """k is not None"""
        evn=eigenvalues(P, k=self.k)
        self.assertTrue(np.allclose(ev[0:self.k], evn))

    def test_eigenvectors(self):
        P=self.bdc.transition_matrix()
        ev, L, R=eig(P, left=True, right=True)
        ind=np.argsort(np.abs(ev))[::-1]
        R=R[:,ind]
        L=L[:,ind]        

        """k=None"""
        Rn=eigenvectors(P)
        self.assertTrue(np.allclose(R, Rn))

        Ln=eigenvectors(P, right=False)
        self.assertTrue(np.allclose(L, Ln))

        """k is not None"""
        Rn=eigenvectors(P, k=self.k)
        self.assertTrue(np.allclose(R[:,0:self.k], Rn))

        Ln=eigenvectors(P, right=False, k=self.k)
        self.assertTrue(np.allclose(L[:,0:self.k], Ln))

    def test_rdl_decomposition(self):
        P=self.bdc.transition_matrix()
        mu=self.bdc.stationary_distribution()

        """Non-reversible"""

        """k=None"""
        Rn, Dn, Ln=rdl_decomposition(P)        
        Xn=np.dot(Ln, Rn)
        """Right-eigenvectors"""
        self.assertTrue(np.allclose(np.dot(P, Rn), np.dot(Rn, Dn)))
        """Left-eigenvectors"""
        self.assertTrue(np.allclose(np.dot(Ln, P), np.dot(Dn, Ln)))
        """Orthonormality"""
        self.assertTrue(np.allclose(Xn, np.eye(self.dim)))
        """Probability vector"""
        self.assertTrue(np.allclose(np.sum(Ln[0,:]), 1.0))

        """k is not None"""
        Rn, Dn, Ln=rdl_decomposition(P, k=self.k)        
        Xn=np.dot(Ln, Rn)               
        """Right-eigenvectors"""
        self.assertTrue(np.allclose(np.dot(P, Rn), np.dot(Rn, Dn)))
        """Left-eigenvectors"""
        self.assertTrue(np.allclose(np.dot(Ln, P), np.dot(Dn, Ln)))
        """Orthonormality"""
        self.assertTrue(np.allclose(Xn, np.eye(self.k)))
        """Probability vector"""
        self.assertTrue(np.allclose(np.sum(Ln[0,:]), 1.0))

        """Reversible"""

        """k=None"""
        Rn, Dn, Ln=rdl_decomposition(P, norm='reversible')        
        Xn=np.dot(Ln, Rn)
        """Right-eigenvectors"""
        self.assertTrue(np.allclose(np.dot(P, Rn), np.dot(Rn, Dn)))
        """Left-eigenvectors"""
        self.assertTrue(np.allclose(np.dot(Ln, P), np.dot(Dn, Ln)))
        """Orthonormality"""
        self.assertTrue(np.allclose(Xn, np.eye(self.dim)))
        """Probability vector"""
#.........這裏部分代碼省略.........
開發者ID:greglever,項目名稱:PyEMMA,代碼行數:103,代碼來源:test_decomposition.py


注:本文中的birth_death_chain.BirthDeathChain.stationary_distribution方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。