When the dynamics model and the observation model of a state space model are both Gaussian, that is we have a linear gaussian ssm, we can perform inference efficiently using Kalman filtering methods.
We perform filtering to predict one step and obtain
- Time update step
- Measurement step, getting the expected observation
The update for the
The algorithm scales as
When all the data have arrived, we can perform offline smoothing and obtain
parallel (associative) Kalman filter
The standard Kalman filter is sequential – each step depends on the previous filtered mean and covariance, giving
Reformulation as an affine map
Substituting the time update (predict) into the measurement update, the filtered mean at time
where
where:
The covariance update
associative scan
The composition of two affine maps is itself an affine map:
This composition is associative (it is function composition), meaning:
Both sides produce the same
To compute all
The associative scan (parallel prefix scan) computes all of these in
where
cuthbert implements this using jax.lax.associative_scan with parallel=True flag:
from cuthbert import filter
from cuthbert.gaussian import kalman
filter_obj = kalman.build_filter(get_init_params, get_dynamics_params, get_observation_params)
states = filter(filter_obj, model_inputs, parallel=True)cuthbert has three functions that map to the maths above:
init_prepare: creates the initial element with, filter_prepare: encodes one time step’s parametersinto the affine scan element via associative_params_singlefilter_combine: composes two scan elements via the associativefiltering_operator
In parallel mode, all elements are prepared independently via jax.vmap(filter_prepare), then composed via jax.lax.associative_scan(filter_combine, ...). In sequential mode, the same filter_prepare and filter_combine are called inside a jax.lax.scan loop.
square-root form
In practice, the scan element carries additional terms beyond
Joseph form equivalence
The Joseph form is defined as:
Using the definition for the innovation covariance
Using the definition for the Kalman Gain