本文整理汇总了Python中Bio.MarkovModel._baum_welch方法的典型用法代码示例。如果您正苦于以下问题:Python MarkovModel._baum_welch方法的具体用法?Python MarkovModel._baum_welch怎么用?Python MarkovModel._baum_welch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bio.MarkovModel
的用法示例。
在下文中一共展示了MarkovModel._baum_welch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_baum_welch
# 需要导入模块: from Bio import MarkovModel [as 别名]
# 或者: from Bio.MarkovModel import _baum_welch [as 别名]
def test_baum_welch(self):
states = ["CP", "IP"]
alphabet = ["cola", "ice_t", "lem"]
outputs = [
(2, 1, 0)
]
p_initial = [1.0, 0.0000001]
p_transition = [[0.7, 0.3],
[0.5, 0.5]]
p_emission = [[0.6, 0.1, 0.3],
[0.1, 0.7, 0.2]]
N, M = len(states), len(alphabet)
x = MarkovModel._baum_welch(N, M, outputs,
p_initial=p_initial,
p_transition=p_transition,
p_emission=p_emission
)
p_initial, p_transition, p_emission = x
markov_model = MarkovModel.MarkovModel(states, alphabet,
p_initial, p_transition,
p_emission)
self.assertEqual(markov_model.states, ['CP', 'IP'])
self.assertEqual(markov_model.alphabet, ['cola', 'ice_t', 'lem'])
self.assertEqual(len(markov_model.p_initial), 2)
self.assertAlmostEqual(markov_model.p_initial[0], 1.0,
places=4)
self.assertAlmostEqual(markov_model.p_initial[1], 0.0,
places=4)
self.assertEqual(len(markov_model.p_transition), 2)
self.assertEqual(len(markov_model.p_transition[0]), 2)
self.assertEqual(len(markov_model.p_transition[1]), 2)
self.assertAlmostEqual(markov_model.p_transition[0][0], 0.02460365,
places=4)
self.assertAlmostEqual(markov_model.p_transition[0][1], 0.97539634,
places=4)
self.assertAlmostEqual(markov_model.p_transition[1][0], 1.0,
places=4)
self.assertAlmostEqual(markov_model.p_transition[1][1], 0.0,
places=4)
self.assertEqual(len(markov_model.p_emission), 2)
self.assertEqual(len(markov_model.p_emission[0]), 3)
self.assertEqual(len(markov_model.p_emission[1]), 3)
self.assertAlmostEqual(markov_model.p_emission[0][0], 0.5)
self.assertAlmostEqual(markov_model.p_emission[0][1], 0.0)
self.assertAlmostEqual(markov_model.p_emission[0][2], 0.5)
self.assertAlmostEqual(markov_model.p_emission[1][0], 0.0)
self.assertAlmostEqual(markov_model.p_emission[1][1], 1.0)
self.assertAlmostEqual(markov_model.p_emission[1][2], 0.0)
示例2: len
# 需要导入模块: from Bio import MarkovModel [as 别名]
# 或者: from Bio.MarkovModel import _baum_welch [as 别名]
print "TESTING baum welch"
states = ["CP", "IP"]
alphabet = ["cola", "ice_t", "lem"]
outputs = [
(2, 1, 0)
]
print "Training HMM"
p_initial = [1.0, 0.0000001]
p_transition = [[0.7, 0.3],
[0.5, 0.5]]
p_emission = [[0.6, 0.1, 0.3],
[0.1, 0.7, 0.2]]
N, M = len(states), len(alphabet)
x = MarkovModel._baum_welch(N, M, outputs,
p_initial=p_initial,
p_transition=p_transition,
p_emission=p_emission
)
p_initial, p_transition, p_emission = x
mm = MarkovModel.MarkovModel(states, alphabet,
p_initial, p_transition, p_emission)
print_mm(mm)
# Test Baum-Welch. This is hard because it is a non-deterministic
# algorithm. Each run will result in different states having to
# different emissions. In order to help this, we need to specify some
# initial probabilities to bias the final results. This is not
# implemented yet in the MarkovModel module.
## states = [