Discrete Hidden Markov Models
cuthbert provides exact filtering and smoothing for state-space models with discrete states (aka hidden Markov models):
In this case, we assume the latent states \(x_t\) are discrete, i.e. \(x_t \in \{1, 2, \ldots, K\}\) and therefore distributions over a state can be stored as an array of normalized probabilities.
Observations are handled via a general log likelihood functions that can also be stored as an array of log likelihoods \(b_i = \log p(y_t \mid x_t = i)\) of size \(K\).
The core atomic functions can be found in
cuthbertlib.discrete.
cuthbert.discrete.filter
Parallel-in-time Bayesian filter for discrete hidden Markov models.
References
- https://ieeexplore.ieee.org/document/9512397
- https://github.com/EEA-sensors/sequential-parallelization-examples/tree/main/python/temporal-parallelization-inference-in-HMMs
- https://github.com/probml/dynamax/blob/main/dynamax/hidden_markov_model/parallel_inference.py
build_filter(get_init_dist, get_trans_matrix, get_obs_lls)
Builds a filter object for discrete hidden Markov models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_init_dist
|
GetInitDist
|
Function to get initial state probabilities \(m_i = p(x_0 = i)\). |
required |
get_trans_matrix
|
GetTransitionMatrix
|
Function to get the transition matrix \(A_{ij} = p(x_t = j \mid x_{t-1} = i)\). |
required |
get_obs_lls
|
GetObsLogLikelihoods
|
Function to get observation log likelihoods \(b_i = \log p(y_t | x_t = i)\). |
required |
Returns:
| Type | Description |
|---|---|
Filter
|
Filter object. Suitable for associative scan. |
Source code in cuthbert/discrete/filter.py
cuthbert.discrete.smoother
Parallel-in-time Bayesian smoother for discrete hidden Markov models.
References
- https://ieeexplore.ieee.org/document/9512397
- https://github.com/EEA-sensors/sequential-parallelization-examples/tree/main/python/temporal-parallelization-inference-in-HMMs
build_smoother(get_trans_matrix)
Builds a smoother object for discrete hidden Markov models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_trans_matrix
|
GetTransitionMatrix
|
Function to get the transition matrix \(A_{ij} = p(x_t = j \mid x_{t-1} = i)\). |
required |
Returns:
| Type | Description |
|---|---|
Smoother
|
Smoother object. Suitable for associative scan. |
Source code in cuthbert/discrete/smoother.py
cuthbert.discrete.types
Provides types for representing discrete HMMs.
GetInitDist
Bases: Protocol
Protocol for specifying the initial distribution.
__call__(model_inputs)
Get the initial distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_inputs
|
ArrayTreeLike
|
Model inputs. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
An array \(m\) of shape (N,) where N is the number of states, with \(m_i = p(x_0 = i)\). |
Source code in cuthbert/discrete/types.py
GetTransitionMatrix
Bases: Protocol
Protocol for specifying the transition matrix.
__call__(model_inputs)
Get the transition matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_inputs
|
ArrayTreeLike
|
Model inputs. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
An array \(A\) of shape (N, N) where N is the number of states, with \(A_{ij} = p(x_t = j \mid x_{t-1} = i)\). |
Source code in cuthbert/discrete/types.py
GetObsLogLikelihoods
Bases: Protocol
Protocol for specifying the observation log likelihoods.
__call__(model_inputs)
Get the observation log likelihoods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_inputs
|
ArrayTreeLike
|
Model inputs. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
An array \(b\) of shape (N,) where N is the number of states, with \(b_i = \log p(y_t \mid x_t = i)\). |