Exemplo n.º 1
0
    def test_tpm(self):
        """Checking transition probability matrix."""
        tfm = np.array([[0, 3, 1], [1, 0, 4], [3, 2, 0]], dtype=np.float)
        result = tfm / tfm.sum(axis=1)[:, None]

        a = mc.MarkovChain().from_data(self.seq)
        self.assertTrue(np.allclose(a.observed_p_matrix, result))
Exemplo n.º 2
0
    def test_mcsim(self):
        '''Checking simulation process'''
        a = mc.MarkovChain().from_data(self.seq)
        si, sn = a.simulate(15, start=0, ret='both', seed=11)
        si2 = a.simulate(15, start=0, ret='indices', seed=11)
        sn2 = a.simulate(15, start=0, ret='states', seed=11)

        self.assertTrue(np.allclose(si, si2) and np.all(sn == sn2))
Exemplo n.º 3
0
    def test_mcsim(self):
        """Checking simulation process."""
        a = mc.MarkovChain().from_data(self.seq)
        seed = np.random.randint(0, 15, 15)
        si, sn = a.simulate(15, start=0, ret='both', seed=seed)
        si2 = a.simulate(15,
                         tf=a.observed_matrix,
                         start=0,
                         ret='indices',
                         seed=seed)
        sn2 = a.simulate(15,
                         start=0,
                         states=['A', 'B', 'C'],
                         ret='states',
                         seed=seed)
        si3, sn3 = a.simulate(15, start='A', ret='both', seed=seed)
        si4, sn4 = a.simulate(15, start='B', ret='both', seed=seed)
        si5, sn5 = a.simulate(15, ret='both', seed=seed)

        self.assertTrue(np.allclose(si, si2) and np.all(sn == sn2))
        self.assertTrue(np.allclose(si, si3) and np.all(sn == sn3))
        self.assertTrue(np.allclose(si4, si5) and np.all(sn4 == sn5))
Exemplo n.º 4
0
 def test_mcgraph(self):
     """Checking graphing process for MC."""
     a = mc.MarkovChain().from_data(self.seq)
     graph = a.graph_make()
     self.assertTrue(isinstance(graph, Digraph))
Exemplo n.º 5
0
 def test_nom(self):
     """Checking raising a matrix to power N."""
     a = mc.MarkovChain().from_data(self.seq)
     a2 = a.n_order_matrix()
     self.assertTrue(
         np.allclose(a2, a.observed_p_matrix @ a.observed_p_matrix))
Exemplo n.º 6
0
 def test_prf(self):
     """Checking prob_to_freq method."""
     a = mc.MarkovChain().from_data(self.seq)
     self.assertTrue(np.allclose(a.prob_to_freq_matrix(),
                                 a.observed_matrix))
Exemplo n.º 7
0
    def test_tfm(self):
        """Checking transition frequency matrix."""
        result = np.array([[0, 3, 1], [1, 0, 4], [3, 2, 0]])

        a = mc.MarkovChain().from_data(self.seq)
        self.assertTrue(np.allclose(a.observed_matrix, result))