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


Python Probs.mutate方法代碼示例

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


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

示例1: test_mutate

# 需要導入模塊: from cogent.seqsim.usage import Probs [as 別名]
# 或者: from cogent.seqsim.usage.Probs import mutate [as 別名]
 def test_mutate(self):
     """Probs mutate should return correct vector from input vector"""
     a = Alphabet('abc')**2
     m = Probs([0.5,0.25,0.25,0.1,0.8,0.1,0.3,0.6,0.1], a)
     #because of fp math in accumulate, can't predict boundaries exactly
     #so add/subtract eps to get the result we expect
     eps = 1e-6
     #            a b b a c c a b c
     seq = array([0,1,1,0,2,2,0,1,2])
     random_vec = array([0,.01,.8-eps,1,1,.3,.05,.9+eps,.95])
     self.assertEqual(m.mutate(seq, random_vec), \
         #      a a b c c a a c c
         array([0,0,1,2,2,0,0,2,2]))
     #check that freq. distribution is about right
     seqs = array([m.mutate(seq) for i in range(1000)])
     #WARNING: bool operators return byte arrays, whose sums wrap at 256!
     zero_count = asarray(seqs == 0, 'int32')
     sums = sum(zero_count, axis=0)
     #expect: 500, 100, 100, 500, 300, 300, 500, 100, 300
     #std dev = sqrt(npq), which is sqrt(250), sqrt(90), sqrt(210)
     means = array([500, 100, 100, 500, 300, 300, 500, 100, 300])
     var   = array([250, 90, 90,  250, 210, 210, 250, 90, 210])
     three_sd = 3 * sqrt(var)
     for obs, exp, sd in zip(sums, means, three_sd):
         assert exp - 2*sd < obs < exp + 2*sd
開發者ID:GavinHuttley,項目名稱:pycogent,代碼行數:27,代碼來源:test_usage.py


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