The Viterbi algorithm predicts the most likely sequence of hidden states. But what if the variable of interest is the final hidden state? For example, predicting if a friend (whom you can't visit due to Covid) is currently ill or healthy using emission observations from a series of daily phone calls.

We can generate marginal hidden state distributions $p(z_T)$ at time T by running Monte Carlo simulations on the HMM structure, but I'm wondering is it possible to obtain this distribution given a set of observations $p(z_T|x_1, x_2, ..., x_T)$?

$p(z_T|x_1, x_2, ..., x_T) = \frac{p(x_1, x_2, ..., x_T|z_T) . p(z_T)}{p(x_1, x_2, ..., x_T)}$

If we apply Bayes’s formula as above, does it make sense to derive $p(x_1, x_2, ..., x_T|z_T)$ from the Backward algorithm?


1 Answer 1


Estimating $p\left(z_T \mid x_{1\ldots T}\right)$ is called filtering, and it’s a fundamental operation on HMMs. Filtering is estimation of the current state, given all observations up to this point. (Contrast it with smoothing: estimating a state based on past and future observations.)

You’d want to perform filtering with the forward algorithm, not the backward algorithm. Unlike the Monte Carlo approach, this gives an exact solution in polynomial time.

  • $\begingroup$ You're right. I was confused at first because the forward algorithm directly evaluates $p(z_T, x_{1...T})$, but $p(z_T | x_{1...T})$ can be obtained by simply normalising it to sum to 1 according to Bayes's Formula . $\endgroup$ Commented Jun 16, 2021 at 1:51
  • 1
    $\begingroup$ Even easier: according to the law of total probability. $\endgroup$ Commented Jun 16, 2021 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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