I am studying hidden Markov models, but I have some doubts about the inference phase. If I have any observations and I want to know the three parameters that characterize the model, can I use one of the MCMC techniques directly on the observations or do I have to first use the Viterbi algorithm or the forward-backward algorithm on the observations and then use one of MCMC techniques to know the three parameters?


2 Answers 2


The question is not clear to me. But if you want to sample from HMM, forward sampling can be used. Assuming $X$ are hidden states and $Y$ is observations, and we want to sample $N$ observations.

enter image description here

The steps are:

  • Sample from $X_1$
  • Based on the sample we got of $X_1$ and $P(Y_1|X_1)$, sample $Y_1$
  • Based on the sample we got of $X_1$ and $P(Y_2|X_1)$, sample $X_2$
  • $\cdots$
  • $\begingroup$ Hi, I apologize for the lack of clarity of the question. But the hidden states I can sample them through one of the mcmc techniques or I must necessarily use the forward sampling? $\endgroup$
    – G.Carlà
    Jul 28, 2017 at 15:34
  • $\begingroup$ why MCMC? that is the part I do not understand. $\endgroup$
    – Haitao Du
    Jul 28, 2017 at 15:36
  • $\begingroup$ I read a pdf file where it is written: Markov Chain Monte Carlo methods observe a series of observations, and iteratively costruct a markov chain such that it's equilibrium distribution. This is the pdf file site:isi.edu/~galstyan/courses/Presentations/… $\endgroup$
    – G.Carlà
    Jul 28, 2017 at 15:44
  • $\begingroup$ @G.Carlà i think you confused with HMM learning and HMM sampling/inference. $\endgroup$
    – Haitao Du
    Jul 28, 2017 at 15:45
  • $\begingroup$ You could kindly clarify the situation. Thanks in advance $\endgroup$
    – G.Carlà
    Jul 28, 2017 at 15:47

This is a very old question but I think the answer is actually misleading. You don't want to do 'forward sampling' here (I think the reference linked was from the Kohler PGM book which states that forward sampling like this doesn't apply to directed graphical models), and the procedure to sample in an unbiased way is actually:

  • Take the last forward probability and sample a hidden state from that.

  • Sample from the previous hidden state conditional on the last hidden state being known (i.e. multiply the forward probabilities at position L - 1 by the transition matrix to the known hidden state

  • Continue back down the chain until you reach the first index

I hope this procedure is helpful / correct, as I don't often see it outlined in books


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.