【问题标题】:Generating a Markov model from a matrix从矩阵生成马尔可夫模型
【发布时间】:2012-04-16 18:23:00
【问题描述】:

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

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。

回答常见问题“您尝试过什么?”:“我尝试了几种方法,但都没有完全实现,所以我希望其中一个答案有助于澄清一些事情”。

非常感谢。

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

【问题讨论】:

  • 你能从你的输入矩阵中代表完整的 OP 吗?你的解释不是很清楚
  • three four two "e" 这样的行的物理意义是什么?它是从状态 3->4->2 开始然后结束的底层马尔可夫链的特定实现吗?
  • 是的,就是这样

标签: python matrix markov-chains hidden-markov-models


【解决方案1】:

您没有给出转换矩阵(这些将是概率),而是给出了由基础马尔可夫模型产生的一系列观察到的转换。

除非您有无限数量的这些观察结果,否则您无法准确地重建底层转换参数。但是,您可以选择转换,以便您的可观察序列是最有可能。如果我理解您的问题,您应该查看Hidden Markov Models 的解决方案。可以在here找到一个免费提供的python模块GHMM。

【讨论】:

    【解决方案2】:

    这是一个想法: 与其尝试创建{"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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-25
      相关资源
      最近更新 更多