本文整理汇总了Python中cogent.seqsim.usage.Probs.isValid方法的典型用法代码示例。如果您正苦于以下问题:Python Probs.isValid方法的具体用法?Python Probs.isValid怎么用?Python Probs.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.seqsim.usage.Probs
的用法示例。
在下文中一共展示了Probs.isValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_isValid
# 需要导入模块: from cogent.seqsim.usage import Probs [as 别名]
# 或者: from cogent.seqsim.usage.Probs import isValid [as 别名]
def test_isValid(self):
"""Probs isValid should return True if it's a prob matrix"""
a = self.ab_pairs
m = Probs([0.5,0.5,1,0], a)
self.assertEqual(m.isValid(), True)
#fails if don't sum to 1
m = Probs([0.5, 0, 1, 0], a)
self.assertEqual(m.isValid(), False)
#fails if negative elements
m = Probs([1, -1, 0, 1], a)
self.assertEqual(m.isValid(), False)
示例2: test_toRates
# 需要导入模块: from cogent.seqsim.usage import Probs [as 别名]
# 或者: from cogent.seqsim.usage.Probs import isValid [as 别名]
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)