Exemplo n.º 1
0
 def test_toRates(self):
     """Probs toRates should return log of probs, optionally normalized"""
     a = Alphabet('abc')**2
     p = Probs([0.9,0.05,0.05,0.1,0.85,0.05,0.02,0.02,0.96], a)
     assert p.isValid()
     r = p.toRates()
     assert isinstance(r, Rates)
     assert r.isValid()
     assert not r.isComplex()
     self.assertEqual(r._data, logm(p._data))
     r_norm = p.toRates(normalize=True)
     self.assertFloatEqual(trace(r_norm._data), -1.0)
Exemplo n.º 2
0
 def test_toRates(self):
     """Probs toRates should return log of probs, optionally normalized"""
     a = Alphabet('abc')**2
     p = Probs([0.9, 0.05, 0.05, 0.1, 0.85, 0.05, 0.02, 0.02, 0.96], a)
     assert p.isValid()
     r = p.toRates()
     assert isinstance(r, Rates)
     assert r.isValid()
     assert not r.isComplex()
     self.assertEqual(r._data, logm(p._data))
     r_norm = p.toRates(normalize=True)
     self.assertFloatEqual(trace(r_norm._data), -1.0)
Exemplo n.º 3
0
 def test_timeForSimilarity(self):
     """Rates timeToSimilarity should return correct time"""
     a = self.abc_pairs
     p = Probs([0.75, 0.1, 0.15, 0.2, 0.7, 0.1, 0.05, 0.15, 0.8], a)
     q = p.toRates()
     d = 0.5
     t = q.timeForSimilarity(d)
     x = expm(q._data)(t)
     self.assertFloatEqual(average(diagonal(x), axis=0), d)
     t = q.timeForSimilarity(d, array([1/3.0]*3))
     x = expm(q._data)(t)
     self.assertFloatEqual(average(diagonal(x), axis=0), d)
     self.assertEqual(q.timeForSimilarity(1), 0)
Exemplo n.º 4
0
 def test_timeForSimilarity(self):
     """Rates timeToSimilarity should return correct time"""
     a = self.abc_pairs
     p = Probs([0.75, 0.1, 0.15, 0.2, 0.7, 0.1, 0.05, 0.15, 0.8], a)
     q = p.toRates()
     d = 0.5
     t = q.timeForSimilarity(d)
     x = expm(q._data)(t)
     self.assertFloatEqual(average(diagonal(x), axis=0), d)
     t = q.timeForSimilarity(d, array([1 / 3.0] * 3))
     x = expm(q._data)(t)
     self.assertFloatEqual(average(diagonal(x), axis=0), d)
     self.assertEqual(q.timeForSimilarity(1), 0)
Exemplo n.º 5
0
    def test_toSimilarProbs(self):
        """Rates toSimilarProbs should match individual steps"""
        a = self.abc_pairs
        p = Probs([0.75, 0.1, 0.15, 0.2, 0.7, 0.1, 0.05, 0.15, 0.8], a)
        q = p.toRates()
        self.assertEqual(q.toSimilarProbs(0.5), \
            q.toProbs(q.timeForSimilarity(0.5)))

        #test a case that didn't work for DNA
        q = Rates(array(
            [[-0.64098451,  0.0217681 ,  0.35576469,  0.26345171],
             [ 0.31144238, -0.90915091,  0.25825858,  0.33944995],
             [ 0.01578521,  0.43162879, -0.99257581,  0.54516182],
             [ 0.13229986,  0.04027147,  0.05817791, -0.23074925]]),
            DnaPairs)
        p = q.toSimilarProbs(0.66)
        self.assertFloatEqual(average(diagonal(p._data), axis=0), 0.66)
Exemplo n.º 6
0
 def test_toProbs(self):
     """Rates toProbs should return correct probability matrix"""
     a = self.abc_pairs
     p = Probs([0.75, 0.1, 0.15, 0.2, 0.7, 0.1, 0.05, 0.1, 0.85], a)
     q = p.toRates()
     self.assertEqual(q._data, logm(p._data))
     p2 = q.toProbs()
     self.assertFloatEqual(p2._data, p._data)
     
     #test a case that didn't work for DNA
     q = Rates(array(
         [[-0.64098451,  0.0217681 ,  0.35576469,  0.26345171],
          [ 0.31144238, -0.90915091,  0.25825858,  0.33944995],
          [ 0.01578521,  0.43162879, -0.99257581,  0.54516182],
          [ 0.13229986,  0.04027147,  0.05817791, -0.23074925]]),
         DnaPairs)
     self.assertFloatEqual(q.toProbs(0.5)._data, expm(q._data)(t=0.5))
Exemplo n.º 7
0
    def test_toSimilarProbs(self):
        """Rates toSimilarProbs should match individual steps"""
        a = self.abc_pairs
        p = Probs([0.75, 0.1, 0.15, 0.2, 0.7, 0.1, 0.05, 0.15, 0.8], a)
        q = p.toRates()
        self.assertEqual(q.toSimilarProbs(0.5), \
            q.toProbs(q.timeForSimilarity(0.5)))

        #test a case that didn't work for DNA
        q = Rates(
            array([[-0.64098451, 0.0217681, 0.35576469, 0.26345171],
                   [0.31144238, -0.90915091, 0.25825858, 0.33944995],
                   [0.01578521, 0.43162879, -0.99257581, 0.54516182],
                   [0.13229986, 0.04027147, 0.05817791, -0.23074925]]),
            DnaPairs)
        p = q.toSimilarProbs(0.66)
        self.assertFloatEqual(average(diagonal(p._data), axis=0), 0.66)
Exemplo n.º 8
0
    def test_toProbs(self):
        """Rates toProbs should return correct probability matrix"""
        a = self.abc_pairs
        p = Probs([0.75, 0.1, 0.15, 0.2, 0.7, 0.1, 0.05, 0.1, 0.85], a)
        q = p.toRates()
        self.assertEqual(q._data, logm(p._data))
        p2 = q.toProbs()
        self.assertFloatEqual(p2._data, p._data)

        #test a case that didn't work for DNA
        q = Rates(
            array([[-0.64098451, 0.0217681, 0.35576469, 0.26345171],
                   [0.31144238, -0.90915091, 0.25825858, 0.33944995],
                   [0.01578521, 0.43162879, -0.99257581, 0.54516182],
                   [0.13229986, 0.04027147, 0.05817791, -0.23074925]]),
            DnaPairs)
        self.assertFloatEqual(q.toProbs(0.5)._data, expm(q._data)(t=0.5))