#### Overview of this book

Hidden Markov Model (HMM) is a statistical model based on the Markov chain concept. Hands-On Markov Models with Python helps you get to grips with HMMs and different inference algorithms by working on real-world problems. The hands-on examples explored in the book help you simplify the process flow in machine learning by using Markov model concepts, thereby making it accessible to everyone. Once you’ve covered the basic concepts of Markov chains, you’ll get insights into Markov processes, models, and types with the help of practical examples. After grasping these fundamentals, you’ll move on to learning about the different algorithms used in inferences and applying them in state and parameter inference. In addition to this, you’ll explore the Bayesian approach of inference and learn how to apply it in HMMs. In further chapters, you’ll discover how to use HMMs in time series analysis and natural language processing (NLP) using Python. You’ll also learn to apply HMM to image processing using 2D-HMM to segment images. Finally, you’ll understand how to apply HMM for reinforcement learning (RL) with the help of Q-Learning, and use this technique for single-stock and multi-stock algorithmic trading. By the end of this book, you will have grasped how to build your own Markov and hidden Markov models on complex datasets in order to apply them to projects.
Preface
Free Chapter
Introduction to the Markov Process
Hidden Markov Models
State Inference - Predicting the States
Parameter Learning Using Maximum Likelihood
Parameter Inference Using the Bayesian Approach
Time Series Predicting
Natural Language Processing
2D HMM for Image Processing
Markov Decision Process
Other Books You May Enjoy

# Forward-backward algorithm (smoothing)

Coming to the forward-backward algorithm, we are now trying to compute the conditional distribution of the hidden state given the observations.

Taking the example of our robot localization, we are trying to now find the probability distribution of the robot's position at some time instance given the sensor readings:

Forward-backward algorithm: P(Zk|X)
Figure 3.5: HMM showing three time slices, k-1, k, and k+1

Now, since we have been given all the observed variables in the model, we can say that the value of P(Zk|X) is going to be proportional to the joint distribution over Zk and X:

Now, we know that we can write X={X1:k, Xk+1:n}. Replacing this in the preceding equation, we get:

We can apply the chain rule in the preceding equation to write it as:

From our model structure, we know that , and using this independence property we can...