本文整理汇总了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