示例#1
0
    def test_timescales(self):
        P_dense=self.bdc.transition_matrix()
        P=self.bdc.transition_matrix_sparse()
        ev=eigvals(P_dense)
        """Sort with decreasing magnitude"""
        ev=ev[np.argsort(np.abs(ev))[::-1]]
        ts=-1.0/np.log(np.abs(ev))

        """k=None"""
        with self.assertRaises(ValueError):
            tsn=timescales(P)

        """k is not None"""
        tsn=timescales(P, k=self.k)
        self.assertTrue(np.allclose(ts[1:self.k], tsn[1:]))

        """k is not None, ncv is not None"""
        tsn=timescales(P, k=self.k, ncv=self.ncv)
        self.assertTrue(np.allclose(ts[1:self.k], tsn[1:]))
        

        """tau=7"""      

        """k is not None"""
        tsn=timescales(P, k=self.k, tau=7)
        self.assertTrue(np.allclose(7*ts[1:self.k], tsn[1:]))
示例#2
0
    def test_timescales(self):
        P=self.bdc.transition_matrix()
        ev=eigvals(P)
        """Sort with decreasing magnitude"""
        ev=ev[np.argsort(np.abs(ev))[::-1]]
        ts=-1.0/np.log(np.abs(ev))

        """k=None"""
        tsn=timescales(P)
        self.assertTrue(np.allclose(ts[1:], tsn[1:]))

        """k is not None"""
        tsn=timescales(P, k=self.k)
        self.assertTrue(np.allclose(ts[1:self.k], tsn[1:]))
        

        """tau=7"""
        
        """k=None"""
        tsn=timescales(P, tau=7)
        self.assertTrue(np.allclose(7*ts[1:], tsn[1:]))

        """k is not None"""
        tsn=timescales(P, k=self.k, tau=7)
        self.assertTrue(np.allclose(7*ts[1:self.k], tsn[1:]))
示例#3
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=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     
示例#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.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)
示例#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.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
示例#6
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 = 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)
示例#7
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)
示例#8
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)
            self.assertTrue(np.allclose(tsn, ts))
            assert issubclass(w[-1].category, ImaginaryEigenValueWarning)        
示例#9
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)
示例#10
0
 def test_timescales(self):
     P = self.bdc.transition_matrix()
     ev = eigvals(P)
     """Sort with decreasing magnitude"""
     ev = ev[np.argsort(np.abs(ev))[::-1]]
     ts = -1.0 / np.log(np.abs(ev))
     """k=None"""
     tsn = timescales(P)
     assert_allclose(ts[1:], tsn[1:])
     """k is not None"""
     tsn = timescales(P, k=self.k)
     assert_allclose(ts[1:self.k], tsn[1:])
     """tau=7"""
     """k=None"""
     tsn = timescales(P, tau=7)
     assert_allclose(7 * ts[1:], tsn[1:])
     """k is not None"""
     tsn = timescales(P, k=self.k, tau=7)
     assert_allclose(7 * ts[1:self.k], tsn[1:])
示例#11
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)
            self.assertTrue(np.allclose(tsn, ts))
            assert issubclass(w[-1].category, SpectralWarning)
示例#12
0
 def test_timescales(self):
     P_dense = self.bdc.transition_matrix()
     P = self.bdc.transition_matrix_sparse()
     ev = eigvals(P_dense)
     """Sort with decreasing magnitude"""
     ev = ev[np.argsort(np.abs(ev))[::-1]]
     ts = -1.0 / np.log(np.abs(ev))
     """k=None"""
     with self.assertRaises(ValueError):
         tsn = timescales(P)
     """k is not None"""
     tsn = timescales(P, k=self.k)
     assert_allclose(ts[1:self.k], tsn[1:])
     """k is not None, ncv is not None"""
     tsn = timescales(P, k=self.k, ncv=self.ncv)
     assert_allclose(ts[1:self.k], tsn[1:])
     """tau=7"""
     """k is not None"""
     tsn = timescales(P, k=self.k, tau=7)
     assert_allclose(7 * ts[1:self.k], tsn[1:])
示例#13
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=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     
示例#14
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 = 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