本文整理汇总了Python中cogent.seqsim.usage.Rates.random方法的典型用法代码示例。如果您正苦于以下问题:Python Rates.random方法的具体用法?Python Rates.random怎么用?Python Rates.random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.seqsim.usage.Rates
的用法示例。
在下文中一共展示了Rates.random方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_random_q_matrix_diag_vector
# 需要导入模块: from cogent.seqsim.usage import Rates [as 别名]
# 或者: from cogent.seqsim.usage.Rates import random [as 别名]
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])
示例2: test_evolve
# 需要导入模块: from cogent.seqsim.usage import Rates [as 别名]
# 或者: from cogent.seqsim.usage.Rates import random [as 别名]
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)
示例3: test_assignP
# 需要导入模块: from cogent.seqsim.usage import Rates [as 别名]
# 或者: from cogent.seqsim.usage.Rates import random [as 别名]
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)
示例4: test_random_q_matrix
# 需要导入模块: from cogent.seqsim.usage import Rates [as 别名]
# 或者: from cogent.seqsim.usage.Rates import random [as 别名]
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
示例5: test_random_q_matrix_diag
# 需要导入模块: from cogent.seqsim.usage import Rates [as 别名]
# 或者: from cogent.seqsim.usage.Rates import random [as 别名]
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
示例6: test_tree_twoway_rates
# 需要导入模块: from cogent.seqsim.usage import Rates [as 别名]
# 或者: from cogent.seqsim.usage.Rates import random [as 别名]
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"
示例7: test_tree_threeway_rates
# 需要导入模块: from cogent.seqsim.usage import Rates [as 别名]
# 或者: from cogent.seqsim.usage.Rates import random [as 别名]
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
示例8: test_assignPs
# 需要导入模块: from cogent.seqsim.usage import Rates [as 别名]
# 或者: from cogent.seqsim.usage.Rates import random [as 别名]
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)
示例9: test_evolveSeqs
# 需要导入模块: from cogent.seqsim.usage import Rates [as 别名]
# 或者: from cogent.seqsim.usage.Rates import random [as 别名]
def test_evolveSeqs(self):
"""PhlyoNode evolveSeqs should evolve multiple sequences"""
t = self.t1
for i in t.traverse(self_before=True):
i.Length = 0.5
t.Q = Rates.random(DnaPairs)
t.assignQ()
t.assignPs([1, 1, 0.1])
t.assignIds()
orig_seqs = [array(i) for i in [randint(0,4,200), randint(0,4,200), \
randint(0,4,200)]]
t.evolveSeqs(orig_seqs)
for node in t.traverse(): #only look at leaves
if node.Parent is not None:
self.assertEqual(len(node.Sequences), 3)
for orig, new in zip(orig_seqs, node.Sequences):
self.assertEqual(len(orig), len(new))
self.assertNotEqual(orig, new)
assert sum(orig_seqs[1]!=node.Sequences[1]) > \
sum(orig_seqs[2]!=node.Sequences[2])