当前位置: 首页>>代码示例>>Python>>正文


Python MarkovModel.train_visible方法代码示例

本文整理汇总了Python中Bio.MarkovModel.train_visible方法的典型用法代码示例。如果您正苦于以下问题:Python MarkovModel.train_visible方法的具体用法?Python MarkovModel.train_visible怎么用?Python MarkovModel.train_visible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bio.MarkovModel的用法示例。


在下文中一共展示了MarkovModel.train_visible方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_train_visible

# 需要导入模块: from Bio import MarkovModel [as 别名]
# 或者: from Bio.MarkovModel import train_visible [as 别名]
 def test_train_visible(self):
     states = ["0", "1", "2", "3"]
     alphabet = ["A", "C", "G", "T"]
     training_data = [
         ("AACCCGGGTTTTTTT", "001112223333333"),
         ("ACCGTTTTTTT", "01123333333"),
         ("ACGGGTTTTTT", "01222333333"),
         ("ACCGTTTTTTTT", "011233333333"),
         ]
     markov_model = MarkovModel.train_visible(states, alphabet, training_data)
     states = MarkovModel.find_states(markov_model, "AACGTT")
     self.assertEqual(len(states), 1)
     state_list, state_float = states[0]
     self.assertEqual(state_list, ['0', '0', '1', '2', '3', '3'])
     self.assertAlmostEqual(state_float, 0.0082128906)
     self.assertEqual(markov_model.states, ['0', '1', '2', '3'])
     self.assertEqual(markov_model.alphabet, ['A', 'C', 'G', 'T'])
     self.assertEqual(len(markov_model.p_initial), 4)
     self.assertAlmostEqual(markov_model.p_initial[0], 1.0)
     self.assertAlmostEqual(markov_model.p_initial[1], 0.0)
     self.assertAlmostEqual(markov_model.p_initial[2], 0.0)
     self.assertAlmostEqual(markov_model.p_initial[3], 0.0)
     self.assertEqual(len(markov_model.p_transition), 4)
     self.assertEqual(len(markov_model.p_transition[0]), 4)
     self.assertEqual(len(markov_model.p_transition[1]), 4)
     self.assertEqual(len(markov_model.p_transition[2]), 4)
     self.assertEqual(len(markov_model.p_transition[3]), 4)
     self.assertAlmostEqual(markov_model.p_transition[0][0], 0.2)
     self.assertAlmostEqual(markov_model.p_transition[0][1], 0.8)
     self.assertAlmostEqual(markov_model.p_transition[0][2], 0.0)
     self.assertAlmostEqual(markov_model.p_transition[0][3], 0.0)
     self.assertAlmostEqual(markov_model.p_transition[1][0], 0.0)
     self.assertAlmostEqual(markov_model.p_transition[1][1], 0.5)
     self.assertAlmostEqual(markov_model.p_transition[1][2], 0.5)
     self.assertAlmostEqual(markov_model.p_transition[1][3], 0.0)
     self.assertAlmostEqual(markov_model.p_transition[2][0], 0.0)
     self.assertAlmostEqual(markov_model.p_transition[2][1], 0.0)
     self.assertAlmostEqual(markov_model.p_transition[2][2], 0.5)
     self.assertAlmostEqual(markov_model.p_transition[2][3], 0.5)
     self.assertAlmostEqual(markov_model.p_transition[3][0], 0.0)
     self.assertAlmostEqual(markov_model.p_transition[3][1], 0.0)
     self.assertAlmostEqual(markov_model.p_transition[3][2], 0.0)
     self.assertAlmostEqual(markov_model.p_transition[3][3], 1.0)
     self.assertEqual(len(markov_model.p_emission), 4)
     self.assertEqual(len(markov_model.p_emission[0]), 4)
     self.assertEqual(len(markov_model.p_emission[1]), 4)
     self.assertEqual(len(markov_model.p_emission[2]), 4)
     self.assertEqual(len(markov_model.p_emission[3]), 4)
     self.assertAlmostEqual(markov_model.p_emission[0][0], 0.666667,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[0][1], 0.111111,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[0][2], 0.111111,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[0][3], 0.111111,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[1][0], 0.083333,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[1][1], 0.750000,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[1][2], 0.083333,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[1][3], 0.083333,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[2][0], 0.083333,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[2][1], 0.083333,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[2][2], 0.750000,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[2][3], 0.083333,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[3][0], 0.031250,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[3][1], 0.031250,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[3][2], 0.031250,
                            places=4)
     self.assertAlmostEqual(markov_model.p_emission[3][3], 0.906250,
                            places=4)
开发者ID:BioGeek,项目名称:biopython,代码行数:82,代码来源:test_MarkovModel.py

示例2: list

# 需要导入模块: from Bio import MarkovModel [as 别名]
# 或者: from Bio.MarkovModel import train_visible [as 别名]
        x = ["%.2f" % x for x in markov_model.p_emission[i]]
        print "  %s: %s" % (markov_model.states[i], ' '.join(x))



print "TESTING train_visible"
states = ["0", "1", "2", "3"]
alphabet = ["A", "C", "G", "T"]
training_data = [
    ("AACCCGGGTTTTTTT", "001112223333333"),
    ("ACCGTTTTTTT", "01123333333"),
    ("ACGGGTTTTTT", "01222333333"),
    ("ACCGTTTTTTTT", "011233333333"),
    ]
print "Training HMM"
mm = MarkovModel.train_visible(states, alphabet, training_data)
print "Classifying"

#print MarkovModel.find_states(mm, "AACGTT")
#Don't just print this, as the float may have different
#precision on different platforms.  This returns a list
#containing a tuple containing a list (fine), and a float.
states = MarkovModel.find_states(mm, "AACGTT")
for state_list, state_float in states:
    print "State %s, %0.10f" % (repr(state_list), state_float)
print_mm(mm)




print "TESTING baum welch"
开发者ID:Mat-D,项目名称:biopython,代码行数:33,代码来源:test_MarkovModel.py


注:本文中的Bio.MarkovModel.train_visible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。