从矩阵中生成一个马尔科夫模型

2024-04-26 00:38:04 发布

您现在位置:Python中文网/ 问答频道 /正文

这个定义可能是错误的,如果是这样,请纠正我。。我需要从以下类型的矩阵中生成马尔可夫模型:

four    two "e"         
four    two "e"         
three   three   "e"         
one three   "e"         
zero    six one zero    "e" 
two two "e"         
two two "e"         
two two "e"         
two two "e"         
two two "e"         
four    zero    "e"         
two two "e"         
three   one three   "e"     
three   "e"             
four    one "e"         
three   one "e"         
two one one zero    two "e"
two five    "e"         
three   four    two "e"     
zero    five    "e"         
three   "e"             
three   three   "e"         
three   "e"             
one one "e"         
three   two "e"         
one one "e"         
three   two zero    zero    zero    "e"
three   three   "e"         
three   one "e"         
three   two "e"         

我需要这样的输出:{“four”:[{2:“two”,3:“one”,2:“exit”},{…}],“three”:[{…}]}

上面的数字基本上是过渡到特定状态的次数。。在

我用python来做这个。在

回答通常的问题“你尝试了什么?”:“我尝试了几种方法,但它们都不太奏效,所以我希望其中一个答案能帮助澄清一些问题。”。在

非常感谢。在

编辑,更新以显示完整的矩阵。在


Tags: 模型类型定义状态错误exit矩阵数字
2条回答

你没有给出一个转换矩阵(这些是概率),而是一系列观察到的转换,这些转换是由底层的Markov模型产生的。在

除非你有无限多个这样的观测值,否则你就不能准确地重建底层的跃迁参数。然而,你可以选择转换,使你的观察序列最有可能是。{我应该看看你的答案。免费提供的python模块GHMM可以在here中找到。在

有个主意: 不要尝试创建{"four":[{2:"two", 3:"one",2:"exit"},{...}],"three":[{...}]}(这在python中不太合法),而是尝试创建{"four":[{"two":2, "one":3, "exit":2},{...}],"three":[{...}]}(注意内部字典中顺序的变化)。在

Iterate over the matrix, for each line:
  if the first word isn't in the big dictionary, add it.
  if the second word isn't in its sub-dictionary, add it, otherwise add 1 to its value.

相关问题 更多 >