Hidden Markov Models #93
rlouf
started this conversation in
New features
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hidden Markov Models
Please comment if you see issues with this design or have ideas, know use cases I did not think about!
Finding the right abstraction: the HMM distribution
We would like simplify the expression of hidden markov models (HMMs) in MCX. It is common to represent HMMs by separating the hidden state transitions, and the process that transforms hidden states into observations. Here we take a different approach, whose underlying idea is that HMMs are made of units that are repeated.
Simple HMM
In their simplest form:
And the elementary unit is:
Let us see if this is possible to build a model from the expression of one unit as a generative model:
Knowing the previous value of
x
and the observationy
we can compute the posterior distribution ofx_prev
. How do we combine the units? We can create a new distribution!Let us assume this
hmm
distribution exists. A simple HMM would thus be loosely expressed in MCX asHMM where observations depend on previous observations
To challenge this abstraction let us assume a more complex model:
The elementary unit becomes:
So the model can be written:
Factorial HMM
What if we have a Factorial HMM instead:
Elementary unit is:
And in code:
The abstraction seems to be robust.
Implementing the HMM distribution
We need to provide an implementation for the
sample
andlogpdf
methods of the HMM distribution.Sample
When parsing the model to compile it into a sampling function, MCX will transform
hmm_unit
into thesample_hmm_unit
function below:HMM.sample(rng_key)
should return samples fory
andx
's prior distribution. We can achieve it with:likelihood
When parsing the model to compile it into a loglikelihood, MCX with transform
hmm_unit
into thelogpdf_hmm_unit
function below:HMM.logpdf(x, y)
should return the loglikelihood of the model given the values ofx_probs
,y_probs
(in the higher-level context)x
andy=obs
. We could use:To be continued with time-dependent transitions. These can be implemented by adding the time
t
as an argument to the unit model, and automatically broadcasting the transition matrix to the number of time steps.Beta Was this translation helpful? Give feedback.
All reactions