通过RHmm包预测下一个可能的隐藏状态,以进行离散分配

时间:2016-07-08 09:25:13

标签: r hidden-markov-models

我有一个列车序列和具有有限值集的模型(离散分布)。我训练这个模型,通过维特比算法得到X序列的隐藏状态,我想预测下一个隐藏状态。我怎么计算呢?

library(RHmm)

seq.train <- rbinom(1000, 1, 0.5)
hmm <- HMMFit(seq.train, dis = 'DISCRETE', nStates = 3)
x <- c(1, 1, 1, 0, 0, 1)
v <- viterbi(hmm, x)

1 个答案:

答案 0 :(得分:1)

You don't need Viterbi algorithm to compute the next hidden state. All you need is the estimated transition matrix, and the posterior state distribution of the last training observation.

> Gamma <- RHmm::forwardbackward(hmm, seq.train)$Gamma
> Gamma[nrow(Gamma), ]
[1] 0.008210024 0.035381361 0.956408615
> Gamma[nrow(Gamma), ] %*% hmm$HMM$transMat
          [,1]     [,2]      [,3]
[1,] 0.2222393 0.293037 0.4847237

See this CrossValidated answer.