Markov Models¶
In these notes, we walk through a model for modeling time-dependent data. By enforcing the Markov chain properties, we only have a variable at time, , depend on the variable at a previous time step, . This results in very efficient directed graph which leads to inference of order .
The main source of inspiration for this is the lecture from the Probabilistic ML course from Tubingen Henning, 2020. Some of the details we taken from the probabilistic machine learning textbook from Kevin Murphy Murphy, 2012.
Motivation¶
Consider a large dimensional dataset, e.g. a data cube. This will be of size:
But let’s assume that it is a spatio-temporal dataset. Then we can decompose the dimension, into the following components.
So we can rewrite this with this decomposition
This poses some immediate problems when we consider the full decomposition.
High Dimensionality. This is a very high dimensional dataset. For example, if we have a very long time series like time steps, then we will have a massive -dimensional vector for the input variable.
Time Dependencies. These time dependencies are very difficult to model. They are highly correlated, especially at very near, e.g. , , and .
Let’s say we are given a sequence of measurements, .
How do we find an appropriate generative model for this sequence of measurements?
Schematic¶
This method seeks to decouple time by enforcing the Markov assumption.
A graphical model for the dependencies between the variables x and z. Notice how z only depends on the previous time step.
This gives us the classical state-space formulation
Here, we have an initial distribution as a prior over the first state, . We have a dynamics model as the prior over the forward state transitions. We have a measurement model as a generative model for the observations of the latent state.
The key is that by enforcing these Markovian assumptions, we have a directed graph structure that results in very efficient inference. This is all due to the Markov property due to the chain structure.
Markov Properties¶
Property of States¶
Given the immediate past, the present state is independent of the entire history before it.
Given , is independent of any other of the previous states, e.g. .
This is enforcing some kind of local memory within our system. So even if we have the full system of observed variables, , and the posterior states, , we still only have the dependencies on the previous time step:
Bottom line - the past is independent of the future given the present.
Conditional Independence of Measurements¶
The current measurement is conditionally independent of the past measurements and states given the current state.
We assume that the measurement, , given the current state, , is conditionally independent of the measurements and its histories.
So as you can see, the measurement at time, , is only dependent on the state, , at time state irregardless of how many other time steps have been observed.
Joint Distribution¶
Given the above properties, this represents how we decompose the time series. We use the properties mentioned above.
While this may not be immediately useful, it is useful for certain other quantities of interest.
Posterior¶
We are interested in finding the latent states, , given our observations, .
However, due to the Markovian nature of the state space model, this process is a combination of
This is known as filtering.
Quantities of Interest¶
Once we have the model structure, now we are interested in the specific quantities. All of them really boil down to quantities from inference.
TLDR¶
Posterior, - this is the probability of the state, given the current and previous measurements, .
Predict Step, - the current state, , given the past measurements, .
Measurement Step, - the current state, , given the present measurement and past measurements,
Marginal Likelihood - - the likelihood of measurements, , given the state, .
Posterior Predictive: - The probability of the measurement, , given the previous measurements, .
Sampling (Posterior): - Trajectories for states, , given the measurements, .
Sampling (Measurements): - Trajectories for observations, , given the state space model, .
Filtering/Posterior¶
The probability of the state, given the current and previous measurements, .
We are interested in computing the belief of our state, . This is given by
This equation is the posterior probability of given the present measurement, , and all of the past measurements, . We can compute this using the Bayes method (eq bayes) in a sequential way.
This is given by the predict-update equations:
It is a recursive relationship where the predict step depends on the correction step and vice versa.
Predict¶
The current state, , given the past measurements, .
This quantity is given via the Chapman-Kolmogrov equation.
Term I: the transition distribution between time steps.
Term II: the posterior distribution of the state, , given all of the observations, .
Note: term III is the posterior distribution but at a previous time step.
Correction¶
The posterior distribution of state, , given the current and previous measurements, .
Term I: The observation model for the current measurement, , given the current state, .
Term II: The posterior distribution of the current state, , given all of the previous measurements, .
Term III: The marginal distribution for the current measurement, .
Filtering Algorithm¶
The full form for filtering equation is given by an iterative process between the predict step and the update step.
1. Predict the next hidden state
- First you get the posterior of the previous state, , given all of the observations, .
- Second, you get the posterior of the current state, , given all of the observations,
2. Predict the observation
- First, you take the state, , given the previous measurements, .
- Second you predict the current measurement, , given all previous measurements, .
3. Update the hidden state given the observation
- First, you take the new observation,
- Then, you do an update step to get the current state, , given all previous measurements, .
Smoothing¶
We compute the state, , given all of the measurements, where .
We condition on the past and the future to significantly reduce the uncertainty.
This use case is very common when we want to understand and learn from data. In a practical sense, many reanalysis datasets take this into account.
Term I: The current state, , given all of the past, current and future measurements, (smoothing step)
Term II: The current state, , given all of the present and previous measurements, (the predict step)
Term III: The “future” state, , given the previous state, (transition prob)
Term IV: The “future” state, , given all of the measurements, .
Term V: The “future” state, , given all of the current and past measurements, .
Predictions¶
We want to predict the future state, , given the past measurements, .
where . τ is the horizon of our forecasting, i.e. it is how far ahead of we are trying to predict. So we can expand this to write that we are interested in the future hidden states, , given all of the past measurements, .
We could also want to get predictions for what we observe
This is known as the posterior predictive density.
This is often the most common use case in applications, e.g. weather predictions and climate model projections. The nice thing is that we will have this as a by-product of our model.
Likelihood Estimation¶
For learning, we need to calculate the most probable state-space that matches the given observations. This assumes that we have access to all of the measurements, .
Note: This is a non-probabilistic approach to maximizing the likelihood. However, this could be very useful for some applications. Smoothing would be better but we still need to find the best parameters.
Posterior Samples¶
We are interested in generating possible states and state trajectories. In this case, we want the likelihood of a state trajectory, , given some measurements, . This is given by:
This is very informative because it can show us plausible interpretations of possible state spaces that could fit the measurements.
Marginal Likelihood¶
This is the probability of the evidence, i.e., the marginal probability of the measurements. This may be useful as an evaluation of the density of given measurements. We could write this as the joint probabilty
We can decompose this using the conditional probability. This gives us
As shown by the above function, this is done by summing all of the hidden paths.
This can be useful if we want to use the learned model to classify sequences, perform clustering, or possibly anomaly detection.
Note: We can use the log version of this equation to deal with instabilities.
Complexity¶
This is the biggest reason why one would do a Markov assumptions aside from the simplicity. Let be the dimensionality of the state space, and be the number of time steps given by the measurements. We can give the computational complexity for each of the quantities listed above.
Filter-Predict
This is of order
If we assume sparsity in the methods, then we can reduce this to .
We can reduce the complexity even further by assuming some special matrices within the functions to give us a complexity of .
If we do a parallel computation, we can even have a really low computational complexity of .
Overall: the bottleneck of this method is not the computational speed, it’s the memory required to do all of the computations cheaply.
Viz¶
Bars¶
Regression¶
Cons¶
While we managed to reduce the dimensionality of our dataset, this might not be the optimal model to choose. We assume that only depends on the previous time step, . But it could be the case that could depend on previous time steps, e.g. . There is no reason to assume that
Multiscale Time Dependencies¶
One way to overcome this is to assume
Long Term¶
- Henning, P. (2020). Probabilistic ML - Lecture 12 - Gauss-Markov Models. https://youtu.be/FydcrDtZroU
- Murphy, K. P. (2012). Machine Learning: A Probabilistic Perspective. MIT Press. probml.ai