AI Glossary / Statistics and probability / Intermediate
Hidden Markov model
Definition
A Hidden Markov model (HMM) is a probabilistic model for a sequence of observations generated by an unobserved sequence of states. In the standard first-order version, each hidden state depends on the previous state, and each observation depends on the current hidden state. The model combines initial-state probabilities, transition probabilities, and state-dependent observation distributions.
What it means
You can observe a machine's readings without directly seeing whether it is operating normally or under strain. An HMM represents those underlying conditions as hidden states and relates them to noisy measurements.
Hidden does not mean mysterious or deliberately concealed. It means the state is not directly observed in the data used for inference. The states are modeling constructs; they do not automatically correspond to verified real-world categories.
How it works
Choose a set of states and define a probability distribution for the starting state. A transition matrix describes the chance of moving from each state to every possible next state. Each row sums to one under the usual row-based convention.
Specify an emission distribution for observations in each state. This can describe discrete symbols, continuous sensor readings, or other supported observation types. Different states may produce overlapping observations, so a single reading rarely determines the state with certainty.
The standard model assumes that the next state depends on the current state rather than the entire earlier state history. It also assumes observations are conditionally independent given the state sequence, with each observation generated from its corresponding state. The observed sequence itself need not satisfy a first-order Markov property.
Different algorithms answer different questions. The forward algorithm sums over possible paths to calculate observation-sequence likelihood and supports filtering. Forward-backward calculations give state probabilities using observations before and after a time point. Viterbi finds the single most probable complete state sequence.
The most probable path is not generally the same as selecting the most probable state separately at every time. Keep path decoding distinct from marginal state estimation, especially when the transition structure prohibits some combinations.
When states are unlabeled, Baum-Welch applies expectation-maximization to estimate parameters. Initialization matters, and local optima are possible. Compare multiple fits and evaluate on held-out sequences rather than relying only on increasing training likelihood.
Use scaled probabilities or log-space calculations for long sequences to avoid numerical underflow. Preserve boundaries between separate sequences; otherwise the model may learn artificial transitions between unrelated subjects or machines.
Assess whether the state assumptions match the application. Standard time-homogeneous HMMs imply geometric state-duration distributions. More flexible duration models, changing transition probabilities, or richer observation models may be needed when that structure is unsuitable.
Three practical examples
- A speech system relates acoustic observations to a sequence of hidden speech units.
- A maintenance team models changing equipment conditions from noisy sensor readings.
- An activity-recognition application estimates sequences of movement states from wearable measurements, subject to appropriate validation.
Think of it this way
Think of hearing sounds through a closed door and estimating which activity is taking place inside. Each sound provides evidence, while knowledge of how activities tend to follow one another helps connect the sequence. The resulting estimate remains uncertain.
Worked example
Consider a constructed two-state model: normal N and strained S. Initial probabilities are P(N) = 0.8 and P(S) = 0.2. Transition probabilities are N to N = 0.9, N to S = 0.1, S to N = 0.2, and S to S = 0.8.
The probability of a high reading is 0.1 in N and 0.7 in S. After the first high reading, unnormalized forward probabilities are 0.8 x 0.1 = 0.08 for N and 0.2 x 0.7 = 0.14 for S.
For a second high reading, the N contribution is (0.08 x 0.9 + 0.14 x 0.2) x 0.1 = 0.010. The S contribution is (0.08 x 0.1 + 0.14 x 0.8) x 0.7 = 0.084.
The probability of observing both high readings is 0.010 + 0.084 = 0.094. The posterior probability of S at the second time is 0.084/0.094, approximately 89.36%.
That is not the probability of the whole S,S path. Its joint probability with the readings is 0.2 x 0.7 x 0.8 x 0.7 = 0.0784, giving posterior path probability about 83.40%. The difference illustrates why a final-state probability and a path probability answer different questions.
Illustrative case study
Fictional case: Willow Works pilots an HMM for monitoring packaging machines. Engineers define candidate operating states and compare their emission patterns with maintenance records. The analyst keeps each machine's sequence separate and reserves later periods for evaluation.
A model finds a persistent high-vibration state, but the team avoids immediately naming it imminent failure. Some episodes coincide with harmless changes in packaging material. Engineers revise the interpretation and compare the HMM with a simpler threshold baseline.
The pilot reports false alerts, detection delay, and state uncertainty. Maintenance decisions remain tied to operational evidence, and the team checks performance again when equipment or workload changes.
Common misconceptions and mistakes
Common mistakes include confusing hidden states with observed labels, treating every high-probability state estimate as certain, and assuming Viterbi output gives marginal posterior probabilities.
Learning a state sequence does not prove a physical mechanism. More states can overfit, and permuting state labels can describe the same fitted model. Standard HMM assumptions also do not capture arbitrary long-range dependence.
Business use
HMMs can support monitoring, sequence classification, segmentation, and interpretable state tracking when their assumptions fit. Business evaluation should compare useful outcomes such as alert quality or segmentation accuracy, not only model likelihood. Online applications must distinguish filtering from smoothing that uses future observations unavailable at decision time.
People also ask
Are HMMs neural networks?
No; a standard HMM is a probabilistic graphical model, though hybrid systems exist.
Must observations be categories?
No. Continuous emission models are common.
Does Baum-Welch guarantee the globally best model?
No. Initialization and local optima matter.
Check your understanding
What is directly observed in the worked example?
Answer: The high readings.
What is the second-time strained-state probability?
Answer: Approximately 89.36%, under the assumed model.
Can a live monitor use future readings for an immediate decision?
Answer: No; that would introduce information unavailable at that time.
Related terms
- Markov Chain
- Latent variable
- Emission probabilities
- Forward algorithm
- Viterbi algorithm
- Filtering
- Smoothing
- emission probability
- transition matrix
- Baum-Welch algorithm
Learn next
Implement a two-state forward calculation by hand, then compare filtering, smoothing, and Viterbi decoding. Study how emission assumptions, sequence boundaries, and state-duration behavior affect the model's usefulness.
More in Statistics and probability
- Heterogeneity of variance - Heterogeneity of variance means that the populations or conditional distributions being compared have different variances.
- Heterogeneous subsamples - Heterogeneous subsamples are distinct subsets within a dataset whose characteristics or statistical relationships differ.
- Heteroskedasticity-consistent standard errors - Heteroskedasticity-consistent standard errors estimate regression-coefficient uncertainty while allowing error variance to differ across observations.
- Hierarchical log-linear model - A hierarchical log-linear model describes expected counts in a contingency table through a linear model for their logarithms, with a hierarchy rule for...
- Hierarchical (sequential) sums of squares - Hierarchical (sequential) sums of squares measure how much residual squared error decreases as terms enter a linear model in a specified order.
- High-dimensional statistics - High-dimensional statistics studies estimation, prediction, and inference when the number of variables or model parameters is large relative to the...
Sources
Jurafsky and Martin, Speech and Language Processing, Hidden Markov Models appendix: https://web.stanford.edu/~jurafsky/slp3/A.pdf hmmlearn, developer tutorial: https://hmmlearn.readthedocs.io/en/stable/tutorial.html
Previous: Hidden Markov Decision Tree Next: Hidden Markov Model with Duration