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


Python Probs.random方法代碼示例

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


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

示例1: test_random_p_matrix_diag_vector

# 需要導入模塊: from cogent.seqsim.usage import Probs [as 別名]
# 或者: from cogent.seqsim.usage.Probs import random [as 別名]
 def test_random_p_matrix_diag_vector(self):
     """Probs random should work with a vector diagonal"""
     for i in range(NUM_TESTS):
         diag = [0, 0.2, 0.6, 1.0]
         p = Probs.random(RnaPairs, diag)._data
         for i, d, row in zip(range(4), diag, p):
             self.assertFloatEqual(sum(row), 1.0)
             self.assertEqual(row[i], diag[i])
開發者ID:GavinHuttley,項目名稱:pycogent,代碼行數:10,代碼來源:test_usage.py

示例2: test_random_p_matrix

# 需要導入模塊: from cogent.seqsim.usage import Probs [as 別名]
# 或者: from cogent.seqsim.usage.Probs import random [as 別名]
 def test_random_p_matrix(self):
     """Probs random should return random Probsrows that sum to 1"""
     for i in range(NUM_TESTS):
         p = Probs.random(RnaPairs)._data
         for i in p:
             self.assertFloatEqual(sum(i), 1.0)
         #length should be 4 by default
         self.assertEqual(len(p), 4)
         self.assertEqual(len(p[0]), 4)
開發者ID:GavinHuttley,項目名稱:pycogent,代碼行數:11,代碼來源:test_usage.py

示例3: test_random_p_matrix_diag

# 需要導入模塊: from cogent.seqsim.usage import Probs [as 別名]
# 或者: from cogent.seqsim.usage.Probs import random [as 別名]
 def test_random_p_matrix_diag(self):
     """Probs random should work with a scalar diagonal"""
     #if diagonal is 1, off-diagonal elements should be 0
     for i in range(NUM_TESTS):
         p = Probs.random(RnaPairs, 1)._data
         self.assertEqual(p, identity(4, 'd'))
     #if diagonal is between 0 and 1, rows should sum to 1
     for i in range(NUM_TESTS):
         p = Probs.random(RnaPairs, 0.5)._data
         for i in range(4):
             self.assertFloatEqual(sum(p[i]), 1.0)
             self.assertEqual(p[i][i], 0.5)
             assert min(p[i]) >= 0
             assert max(p[i]) <= 1
     #if diagonal > 1, rows should still sum to 1
     for i in range(NUM_TESTS):
         p = Probs.random(RnaPairs, 2)._data
         for i in range(4):
             self.assertEqual(p[i][i], 2.0)
             self.assertFloatEqual(sum(p[i]), 1.0)
             assert min(p[i]) < 0
開發者ID:GavinHuttley,項目名稱:pycogent,代碼行數:23,代碼來源:test_usage.py

示例4: test_probs_to_rates

# 需要導入模塊: from cogent.seqsim.usage import Probs [as 別名]
# 或者: from cogent.seqsim.usage.Probs import random [as 別名]
 def test_probs_to_rates(self):
     """probs_to_rates converts probs to rates, omitting problem cases"""
     probs = dict([(i, Probs.random(DnaPairs)) for i in range(100)])
     rates = probs_to_rates(probs)
     #check we got at most the same number of items as in probs
     assert len(rates) <= len(probs)
     #check that we didn't get anything bad
     vals = rates.values()
     for v in vals:
         assert not v.isSignificantlyComplex()
     #check that we didn't miss anything good
     for key, val in probs.items():
         if key not in rates:
             try:
                 r = val.toRates()
                 print r.isValid()
                 assert r.isSignificantlyComplex() or (not r.isValid())
             except (ZeroDivisionError, OverflowError, ValueError):
                 pass
開發者ID:GavinHuttley,項目名稱:pycogent,代碼行數:21,代碼來源:test_analysis.py


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