Understanding Hidden Markov Model
A hidden Markov model applies the Bayesian-network idea to a world that changes. Variables are split into a state, which is true but unobservable, and evidence, which is observed and unreliable. Time is cut into fixed slices, and the model is assumed stationary, meaning the same two conditional distributions apply at every step. Russell and Norvig introduce it with a security guard who cannot see the weather and must infer whether it is raining from whether his director arrives carrying an umbrella.
The two assumptions are what make the model finite. The Markov assumption states that the current state depends on the entire history only through the immediately preceding state; the sensor Markov assumption states that the current observation depends only on the current state. Both are claims about whether the state variable has been chosen well rather than about the physical sensor. When the first fails, the usual repairs are to raise the order of the model or, better, to enlarge the state so that the missing dependence runs through a variable instead of through time.
Under those assumptions the joint distribution over a complete history factorises into a prior, one transition factor per step and one sensor factor per step. Every query is then answered by one of four tasks. Filtering computes the belief about the current state given all evidence so far, and is what a running agent maintains. Prediction extends that belief into the future, where in the absence of new evidence it relaxes toward the stationary distribution of the chain and eventually carries no information. Smoothing estimates an earlier state using evidence that arrived afterwards, by multiplying the forward message by a backward message that summarises the later observations. Running the forward pass once and then sweeping backward smooths an entire sequence in time linear in its length, the forward-backward algorithm.
The fourth task is different in kind. Asking for the single most likely sequence of states is not the same as asking for the most likely state at each step, because marginals sum over all paths through a state while a sequence is one path. Assembling per-step winners can therefore produce a history less probable than another, and the Viterbi algorithm exists to optimise over whole paths: it is the forward recursion with the sum over the previous state replaced by a maximum, plus a back-pointer at each step so that the winning path can be recovered and not merely its probability. When the state is continuous rather than discrete, the same predict-and-update cycle survives only for special families; the linear-Gaussian case gives the Kalman filter.
How to Calculate
P(X₀:ₜ, E₁:ₜ) = P(X₀) Πᵢ P(Xᵢ | Xᵢ₋₁) P(Eᵢ | Xᵢ)
where
- Xᵢ
- the hidden state at time i, which is never observed directly
- Eᵢ
- the observation emitted at time i
- P(Xᵢ | Xᵢ₋₁)
- the transition model, identical at every step for a stationary process
- P(Eᵢ | Xᵢ)
- the sensor model, the probability of a reading given the true state
Example of Hidden Markov Model
In the umbrella world the state is whether it rains, with P(rain today | rain yesterday) = 0.7 and P(rain today | dry yesterday) = 0.3, and the sensor is whether an umbrella appears, with P(umbrella | rain) = 0.9 and P(umbrella | dry) = 0.2. Starting from a uniform prior, one umbrella gives a filtered belief of ⟨0.818, 0.182⟩, and a second on the following day gives ⟨0.883, 0.117⟩.
Smoothing day 1 once day 2 has been seen raises it from 0.818 to 0.883, because the second umbrella makes rain on day 2 likelier and rain persists. The backward message that carries this is ⟨0.69, 0.41⟩, which does not sum to one because it is a likelihood rather than a distribution.
On the observations no umbrella, umbrella, no umbrella, the smoothed probability of rain on day 2 is 0.554, yet the most likely sequence is dry on all three days at 0.402 against 0.332 for the runner-up. The marginal collects its mass from four separate histories; the winning sequence concentrates its own into one.
Advantages and Disadvantages
Pros
- Inference cost per time step is constant, so an agent can run a filter indefinitely on bounded memory.
- The same small model answers questions about the present, the future and the past.
- Parameters can be fitted from observation sequences alone, using forward-backward inside expectation-maximisation.
Cons
- A single discrete state variable means the number of states grows exponentially when several features must be tracked at once.
- The first-order assumption is often a poor fit, and repairing it by enlarging the state costs tractability.
- Long-range dependence is representable only through the state, so genuinely long memories are awkward.
Frequently Asked Questions
How does a hidden Markov model differ from a Markov chain?
A Markov chain has observable states. A hidden Markov model adds a sensor model and hides the state, so the chain must be inferred from its emissions. That extra layer is what makes filtering and smoothing necessary rather than trivial.
Why is smoothing better than filtering for the same time step?
Filtering uses only the evidence available at the time; smoothing also uses everything that arrived afterwards. Because consecutive states are coupled by the transition model, later observations are genuinely informative about earlier states, so the smoothed estimate is based on strictly more evidence.
When should a Kalman filter be used instead?
When the state is continuous and the dynamics and sensor are approximately linear with Gaussian noise. The belief then stays Gaussian and is carried as a mean and a covariance. If the belief is genuinely multi-modal, neither a Gaussian nor a small discrete state fits well, and a sampling method is the honest choice.
The Bottom Line
A hidden Markov model buys unlimited time depth with two independence assumptions, reducing an unbounded history to a prior and two small tables. One forward recursion answers the present, a backward pass buys hindsight, and the most likely history needs Viterbi rather than a string of per-step winners.