当前位置: 首页>>代码示例>>Python>>正文


Python usage.Rates类代码示例

本文整理汇总了Python中cogent.seqsim.usage.Rates的典型用法代码示例。如果您正苦于以下问题:Python Rates类的具体用法?Python Rates怎么用?Python Rates使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Rates类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_isComplex

 def test_isComplex(self):
     """Rates isComplex should return True if complex elements"""
     r = Rates([0,0,0.1j,0,0,0,0,0,0], self.abc_pairs)
     assert r.isComplex()
     
     r = Rates([0,0,0.1,0,0,0,0,0,0], self.abc_pairs)
     assert not r.isComplex()
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:7,代码来源:test_usage.py

示例2: test_fixNegsConstrainedOpt

 def test_fixNegsConstrainedOpt(self):
     """Rates fixNegsConstrainedOpt should fix negatives w/ constrained opt"""
     q = Rates(array([[-0.28936029,  0.14543346, -0.02648614,  0.17041297],
         [ 0.00949624, -0.31186005,  0.17313171,  0.1292321 ],
         [ 0.10443209,  0.16134479, -0.30480186,  0.03902498],
         [ 0.01611264,  0.12999161,  0.15558259, -0.30168684]]), DnaPairs)
     r = q.fixNegsFmin()
     assert not q.isValid()
     assert r.isValid()
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:9,代码来源:test_usage.py

示例3: test_normalize

 def test_normalize(self):
     """Rates normalize should return normalized copy of self where trace=-1"""
     r = Rates([-2,1,1,0,-1,1,2,0,-1], self.abc_pairs)
     n = r.normalize()
     self.assertEqual(n._data, \
         array([[-0.5,.25,.25],[0.,-.25,.25],[.5,0.,-.25]]))
     #check that we didn't change the original
     assert n._data is not r._data
     self.assertEqual(r._data, \
         array([[-2,1,1,],[0,-1,1,],[2,0,-1]]))
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:10,代码来源:test_usage.py

示例4: test_toSimilarProbs

    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)
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:17,代码来源:test_usage.py

示例5: test_random_q_matrix_diag_vector

 def test_random_q_matrix_diag_vector(self):
     """Rates random should init with vector as diagonal"""
     diag = [1, -1, 2, -2]
     for i in range(NUM_TESTS):
         q = Rates.random(RnaPairs, diag)._data
         for i, d, row in zip(range(4), diag, q):
             self.assertFloatEqual(sum(row, axis=0), 0.0)
             self.assertEqual(row[i], diag[i])
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:8,代码来源:test_usage.py

示例6: test_toProbs

 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))
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:17,代码来源:test_usage.py

示例7: test_isSignificantlyComplex

 def test_isSignificantlyComplex(self):
     """Rates isSignificantlyComplex should be true if large imag component"""
     r = Rates([0,0,0.2j,0,0,0,0,0,0], self.abc_pairs)
     assert r.isSignificantlyComplex()
     assert r.isSignificantlyComplex(0.01)
     assert not r.isSignificantlyComplex(0.2)
     assert not r.isSignificantlyComplex(0.3)
     
     r = Rates([0,0,0.1,0,0,0,0,0,0], self.abc_pairs)
     assert not r.isSignificantlyComplex()
     assert not r.isSignificantlyComplex(1e-30)
     assert not r.isSignificantlyComplex(1e3)
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:12,代码来源:test_usage.py

示例8: test_isValid

    def test_isValid(self):
        """Rates isValid should check row sums and neg off-diags"""
        r = Rates([-2,1,1,0,-1,1,0,0,0], self.abc_pairs)
        assert r.isValid()

        r = Rates([0,0,0,0,0,0,0,0,0], self.abc_pairs)
        assert r.isValid()
        #not valid if negative off-diagonal
        r = Rates([-2,-1,3,1,-1,0,2,2,-4], self.abc_pairs)
        assert not r.isValid()
        #not valid if rows don't all sum to 0
        r = Rates([0,0.0001,0,0,0,0,0,0,0], self.abc_pairs)
        assert not r.isValid()
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:13,代码来源:test_usage.py

示例9: test_evolve

 def test_evolve(self):
     """RangeNode evolve should work on a starting vector"""
     t = self.t1
     t.Q = Rates.random(DnaPairs)
     t.assignQ()
     t.assignLength(0.1)
     t.assignP()
     start = array([1,0,2,1,0,0,2,1,2,0,1,2,1,0,2,0,0,3,0,2,1,0,3,1,0,2,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3])
     t.evolve(start)
     for i in t.traverse():
         self.assertEqual(len(i.Sequence), len(start))
         self.assertNotEqual(i.Sequence, start)
开发者ID:miklou,项目名称:pycogent,代码行数:12,代码来源:test_tree.py

示例10: test_assignP

 def test_assignP(self):
     """RangeNode assignP should work when Qs set."""
     t = self.t1
     for i in t.traverse(self_before=True):
         i.Length = random() * 0.5 #range 0 to 0.5
     t.Q = Rates.random(DnaPairs)
     t.assignQ()
     t.assignP()
     t.assignIds()
     for node in t.traverse(self_after=True):
         if node.Parent is not None:
             self.assertFloatEqual(average(1-diag(node.P._data), axis=0), \
                 node.Length)
开发者ID:miklou,项目名称:pycogent,代码行数:13,代码来源:test_tree.py

示例11: test_random_q_matrix

 def test_random_q_matrix(self):
     """Rates random should return matrix of correct size"""
     for i in range(NUM_TESTS):
         q = Rates.random(RnaPairs)._data
         self.assertEqual(len(q), 4)
         self.assertEqual(len(q[0]), 4)
         for row in q:
             self.assertFloatEqual(sum(row), 0.0)
             assert min(row) < 0
             assert max(row) > 0
             l = list(row)
             l.sort()
             assert min(l[1:]) >= 0
             assert max(l[1:]) <= 1
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:14,代码来源:test_usage.py

示例12: test_random_q_matrix_diag

 def test_random_q_matrix_diag(self):
     """Rates random should set diagonal correctly from scalar"""
     for i in range(NUM_TESTS):
         q = Rates.random(RnaPairs, -1)._data
         self.assertEqual(len(q), 4)
         for i, row in enumerate(q):
             self.assertFloatEqual(sum(row), 0)
             self.assertEqual(row[i], -1)
             assert max(row) <= 1
             l = list(row)
             l.sort()
             assert min(l[1:]) >= 0
             assert max(l[1:]) <= 1
     for i in range(NUM_TESTS):
         q = Rates.random(RnaPairs, -5)._data
         self.assertEqual(len(q), 4)
         for i, row in enumerate(q):
             self.assertFloatEqual(sum(row), 0)
             self.assertEqual(row[i], -5)
             assert max(row) <= 5
             l = list(row)
             l.sort()
             assert min(l[1:]) >= 0
             assert max(l[1:]) <= 5
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:24,代码来源:test_usage.py

示例13: test_tree_twoway_rates

 def test_tree_twoway_rates(self):
     """tree_twoway_rates should give plausible results on rand trees"""
     t = self.t1
     t.assignLength(0.05)
     t.Q = Rates.random(DnaPairs).normalize()
     t.assignQ()
     t.assignP()
     t.evolve(randint(0,4,100))
     t.makeIdIndex()
     result = tree_twoway_rates(t)
     self.assertEqual(result.shape, (5,5,16))
     #check that row sums are 0
     for x in [(i,j) for i in range(5) for j in range(5)]:
         self.assertFloatEqual(sum(result[x]), 0)
     #need to make sure we didn't just get an empty array
     self.assertGreaterThan((abs(result)).sum(), 0)
     #check that it works without_diag
     result = tree_twoway_rates(t, without_diag=True)
     self.assertEqual(result.shape, (5,5,12))
     #check that it works with/without normalize
     #default: no normalization, so row sums shouldn't be 1 after omitting
     #diagonal
     result = tree_twoway_rates(t, without_diag=True)
     self.assertEqual(result.shape, (5,5,12))
     #check that the row sums are not 1 before normalization (note that they
     #can be zero, though)
     sums_before = []
     for x in [(i,j) for i in range(5) for j in range(5)]:
         curr_sum = sum(result[x])
         sums_before.append(curr_sum)
     #...but if we tell it to normalize, row sums should be nearly 1
     #after omitting diagonal
     result = tree_twoway_rates(t, without_diag=True, \
         normalize=True)
     self.assertEqual(result.shape, (5,5,12))
     sums_after = []
     for x in [(i,j) for i in range(5) for j in range(5)]:
         curr_sum = sum(result[x])
         sums_after.append(curr_sum)
         if curr_sum != 0:
             self.assertFloatEqual(curr_sum, 1)
     try:
         self.assertFloatEqual(sums_before, sums_after)
     except AssertionError:
         pass
     else:
         raise AssertionError, "Expected different arrays before/after norm"
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:47,代码来源:test_analysis.py

示例14: test_tree_threeway_rates

 def test_tree_threeway_rates(self):
     """tree_threeway_rates should give plausible results on rand trees"""
     #note: the following fails occasionally, but repeating it 5 times
     #and checking that one passes is fairly safe
     for i in range(5):
         try:
             t = self.t1
             t.assignLength(0.05)
             t.Q = Rates.random(DnaPairs).normalize()
             t.assignQ()
             t.assignP()
             t.evolve(randint(0,4,100))
             t.makeIdIndex()
             depths = t.leafLcaDepths()
             result = tree_threeway_rates(t, depths)
             self.assertEqual(result.shape, (5,5,5,16))
             #check that row sums are 0
             for x in [(i,j,k) for i in range(5) for j in range(5) \
                 for k in range(5)]:
                 self.assertFloatEqual(sum(result[x]), 0)
             assert any(result)
             #check that it works without_diag
             result = tree_threeway_rates(t, depths, without_diag=True)
             self.assertEqual(result.shape, (5,5,5,12))
             #check that it works with/without normalize
             #default: no normalization, so row sums shouldn't be 1 after 
             #omitting diagonal
             result = tree_threeway_rates(t, depths, without_diag=True)
             self.assertEqual(result.shape, (5,5,5,12))
             for x in [(i,j,k) for i in range(5) for j in range(5) \
                 for k in range(5)]:
                 assert sum(result[x]) == 0 or abs(sum(result[x]) - 1) > 0.01
             #...but if we tell it to normalize, row sums should be nearly 1
             #after omitting diagonal
             result = tree_threeway_rates(t, depths, without_diag=True, \
                 normalize=True)
             self.assertEqual(result.shape, (5,5,5,12))
             for x in [(i,j,k) for i in range(5) for j in range(5) \
                 for k in range(5)]:
                     s = sum(result[x])
                     if s != 0:
                         self.assertFloatEqual(s, 1)
             break
         except AssertionError:
             pass
开发者ID:chungtseng,项目名称:pycogent,代码行数:45,代码来源:test_analysis.py

示例15: test_assignPs

 def test_assignPs(self):
     """RangeNode assignPs should assign multiple scaled P matrices"""
     t = self.t1
     for i in t.traverse(self_before=True):
         i.Length = random() * 0.5 #range 0 to 0.5
     t.Q = Rates.random(DnaPairs)
     t.assignQ()
     t.assignPs([1, 0.5, 0.25])
     t.assignIds()
     for node in t.traverse(self_after=True):
         if node.Parent is not None:
             self.assertEqual(len(node.Ps), 3)
             self.assertFloatEqual(average(1-diag(node.Ps[0]._data), axis=0), \
                 node.Length)
             self.assertFloatEqual(average(1-diag(node.Ps[1]._data), axis=0), \
                 0.5*node.Length)
             self.assertFloatEqual(average(1-diag(node.Ps[2]._data), axis=0), \
                 0.25*node.Length)
开发者ID:miklou,项目名称:pycogent,代码行数:18,代码来源:test_tree.py


注:本文中的cogent.seqsim.usage.Rates类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。