Python 从矩阵生成马尔可夫模型

Python 从矩阵生成马尔可夫模型,python,matrix,markov-chains,hidden-markov-models,Python,Matrix,Markov Chains,Hidden Markov Models,这个定义可能是错误的,如果是,请纠正我。。我需要从以下类型的矩阵生成马尔可夫模型: 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"

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

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"         
我需要输出类似于:{“四”:[{2:“二”,3:“一”,2:“退出”},{…},,“三”:[{…}]}

上面的数字基本上是转换到特定状态的次数

我正在为此使用python

对通常的问题“你尝试了什么?”的回答:“我尝试了一些方法,但没有完全实现,所以我希望其中一个答案能帮助澄清一些问题。”

非常感谢

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

这里有一个想法: 与其尝试创建<代码>{“四”:[{2:“二”,3:“一”,2:“退出”},{…},“三”:[{…}]}(这在python中不太合法),不如尝试创建<代码>{“四”:[{“二”:2,“一”:3,“退出”:2},{…},“三”:[{…}}(注意内部字典中顺序的变化)


您并没有给出一个转换矩阵(这些将是概率),而是一个由潜在马尔可夫模型产生的观察到的转换序列


除非有无限多的观察值,否则就无法准确地重构底层的过渡参数。但是,您可以选择转换,使您的观察序列最有可能。如果我理解你的问题,你应该研究解决问题的办法。可以找到免费提供的python模块GHMM。

您能从输入矩阵中表示完整的OP吗?你的解释不是很清楚像这样的一行的物理意义是什么:
three-four-two“e”
?它是从底层马尔可夫链的一种特殊实现,从状态
3->4->2
开始,然后结束吗?是的,就是这样
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.