What are the ways of deciding probabilities in hidden markov models?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Hidden Markov Models (HMMs) are a powerful statistical tool used for modeling time-series data where the system being modeled is assumed to be a Markov process with hidden states. The task of deciding probabilities in HMMs involves two key aspects: estimating the model parameters and inferring the hidden states. In this article, we'll explore the techniques used to determine these probabilities, providing detailed technical explanations and examples to enhance your understanding.
Overview of an HMM
Before diving into the methods of deciding probabilities, let's briefly review the structure of an HMM:
- States: .
- Observation Symbols: .
- Initial State Distribution: where .
- State Transition Probability Matrix: where .
- Observation Probability Matrix: where .
The parameters of an HMM are typically represented by .
Estimation of HMM Parameters
Parameter estimation is crucial for model training and understanding. The two prominent techniques for estimating the probabilities are:
1. Maximum Likelihood Estimation (MLE)
MLE is used to determine the model parameters that maximize the likelihood of the observed data.
Calculating Transition Probabilities
To estimate the state transition probabilities, we use the counts of transitions observed in the training data. Assuming we have a sequence of hidden states, , the transition probability can be estimated as:
Calculating Emission Probabilities
The observation probability can be estimated by:
2. Expectation-Maximization (EM) and the Baum-Welch Algorithm
The Baum-Welch algorithm, a specific case of the EM algorithm, is widely used for the training of HMMs when the state sequence is not known.
Initialization: Start with an initial estimate of the parameters .
Expectation Step (E-step): Calculate the expected frequency of transitions and emissions using the Forward-Backward algorithm.
Maximization Step (M-step): Update estimates of , , and using the expected counts calculated in the E-step.
The Forward-Backward algorithm calculates the forward probability and backward probability :
• Forward Probability: is the probability of observing the first observations and being in state at time .
• Backward Probability: is the probability of observing the remaining observations from to given the state at time is .
Comparison of MLE and EM
| Method | Description | Advantage | Disadvantage |
| MLE | Uses observed counts to directly estimate probabilities. | Simple, fast computation | Not suitable if hidden states are unknown |
| EM (Baum-Welch) | Iteratively refines estimates using the Forward-Backward algorithm. | Handles incomplete data, more accurate | Computationally intensive |
Inference of Hidden States
After the parameters are estimated, the next step is to infer the hidden states, typically using the Viterbi algorithm.
Viterbi Algorithm
The Viterbi algorithm finds the most probable sequence of hidden states given the observed data and estimated model parameters. It uses dynamic programming to recursively calculate the probability of the most probable path leading to each state at time :
Let be the probability of the most likely state sequence ending in at time :
Conclusion
Deciding probabilities in Hidden Markov Models involves the estimation of model parameters (using MLE or EM) and the inference of hidden states (using the Viterbi algorithm). These techniques, while computationally intensive, allow HMMs to be powerful models for stochastic processes with unobserved states. Understanding these methods provides a foundation for practical applications in diverse fields such as speech recognition, bioinformatics, and finance.
Related reading
- What are X_train and y_train?
- What can cause the tensorflow import to be so slow?
- what class is this replicated system
- What do columns ‘rawPrediction’ and ‘probability’ of DataFrame mean in Spark MLlib?
- What distribution do you get from this broken random shuffle?
- What does the property losses of the Bayesian layers of TensorFlow Probability represent?
- What do maskers really do in SHAP package and fit them to train or test?
- What do the functions tf.squeeze and tf.nn.rnn do?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.