sermal
sermal

Reputation: 93

Predict the next probable hidden state via RHmm package for discrete distribution

I have a train sequence and model with finite set of values (discrete distribution). I'm training this model, getting the hidden states for X sequence by Viterbi algorithm and I want to predict the next hidden state. How can I calculate it?

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)

Upvotes: 1

Views: 1021

Answers (1)

Sergei Lebedev
Sergei Lebedev

Reputation: 2679

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.

Upvotes: 3

Related Questions