Kalman
This sub-repository provides modular functions for Kalman filtering and smoothing.
The core functions are:
predict: Single prediction step.filter_update: Single update step.smoother_update: Single Rauch-Tung-Striebel smoothing step.
Together, predict and filter_update can be used to perform an online filtering step.
In all cases, we operate on the square-root form of the covariance matrix, which is more numerically stable (in low-precision floating point arithmetic) as the outputs are guaranteed to be positive-definite. This means we also require input covariance matrices to be provided in square-root (Cholesky) form.
cuthbertlib.kalman.filtering
Implements the square root parallel Kalman filter and associative variant.
FilterScanElement
Bases: NamedTuple
Arrays carried through the Kalman filter scan.
A
instance-attribute
b
instance-attribute
U
instance-attribute
eta
instance-attribute
Z
instance-attribute
ell
instance-attribute
predict(m, chol_P, F, c, chol_Q)
Propagate the mean and square root covariance through linear Gaussian dynamics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
ArrayLike
|
Mean of the state. |
required |
chol_P
|
ArrayLike
|
Generalized Cholesky factor of the covariance of the state. |
required |
F
|
ArrayLike
|
Transition matrix. |
required |
c
|
ArrayLike
|
Transition shift. |
required |
chol_Q
|
ArrayLike
|
Generalized Cholesky factor of the transition noise covariance. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Array, Array]
|
Propagated mean and square root covariance. |
References
Paper: G. J. Bierman, Factorization Methods for Discrete Sequential Estimation, Code: https://github.com/EEA-sensors/sqrt-parallel-smoothers/tree/main/parsmooth/sequential
Source code in cuthbertlib/kalman/filtering.py
update(m, chol_P, H, d, chol_R, y, log_normalizing_constant=0.0)
Update the mean and square root covariance with a linear Gaussian observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
ArrayLike
|
Mean of the state. |
required |
chol_P
|
ArrayLike
|
Generalized Cholesky factor of the covariance of the state. |
required |
H
|
ArrayLike
|
Observation matrix. |
required |
d
|
ArrayLike
|
Observation shift. |
required |
chol_R
|
ArrayLike
|
Generalized Cholesky factor of the observation noise covariance. |
required |
y
|
ArrayLike
|
Observation. |
required |
log_normalizing_constant
|
ArrayLike
|
Optional input of log normalizing constant to be added to log normalizing constant of the Bayesian update. |
0.0
|
Returns:
| Type | Description |
|---|---|
tuple[tuple[Array, Array], Array]
|
Updated mean and square root covariance as well as the log marginal likelihood. |
References
Paper: G. J. Bierman, Factorization Methods for Discrete Sequential Estimation, Code: https://github.com/EEA-sensors/sqrt-parallel-smoothers/tree/main/parsmooth/sequential
Source code in cuthbertlib/kalman/filtering.py
associative_params_single(F, c, chol_Q, H, d, chol_R, y)
Single time step for scan element for square root parallel Kalman filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
Array
|
State transition matrix. |
required |
c
|
Array
|
State transition shift vector. |
required |
chol_Q
|
Array
|
Generalized Cholesky factor of the state transition noise covariance. |
required |
H
|
Array
|
Observation matrix. |
required |
d
|
Array
|
Observation shift. |
required |
chol_R
|
Array
|
Generalized Cholesky factor of the observation noise covariance. |
required |
y
|
Array
|
Observation. |
required |
Returns:
| Type | Description |
|---|---|
FilterScanElement
|
Prepared scan element for the square root parallel Kalman filter. |
Source code in cuthbertlib/kalman/filtering.py
filtering_operator(elem_i, elem_j)
Binary associative operator for the square root Kalman filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elem_i
|
FilterScanElement
|
Filter scan element for the previous time step. |
required |
elem_j
|
FilterScanElement
|
Filter scan element for the current time step. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FilterScanElement |
FilterScanElement
|
The output of the associative operator applied to the input elements. |
Source code in cuthbertlib/kalman/filtering.py
cuthbertlib.kalman.smoothing
Implements the square root Rauch–Tung–Striebel (RTS) smoother and associative variant.
SmootherScanElement
Bases: NamedTuple
Kalman smoother scan element.
g
instance-attribute
E
instance-attribute
D
instance-attribute
update(filter_m, filter_chol_P, smoother_m, smoother_chol_P, F, c, chol_Q)
Single step of the square root Rauch–Tung–Striebel (RTS) smoother.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_m
|
ArrayLike
|
Mean of the filtered state. |
required |
filter_chol_P
|
ArrayLike
|
Generalized Cholesky factor of the filtering covariance. |
required |
smoother_m
|
ArrayLike
|
Mean of the smoother state. |
required |
smoother_chol_P
|
ArrayLike
|
Generalized Cholesky factor of the smoothing covariance. |
required |
F
|
ArrayLike
|
State transition matrix. |
required |
c
|
ArrayLike
|
State transition shift vector. |
required |
chol_Q
|
ArrayLike
|
Generalized Cholesky factor of the state transition noise covariance. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Array, Array]
|
A tuple |
Array
|
|
tuple[tuple[Array, Array], Array]
|
|
References
Paper: Park and Kailath (1994) - Square-root RTS smoothing algorithms Code: https://github.com/EEA-sensors/sqrt-parallel-smoothers/tree/main/parsmooth/sequential
Source code in cuthbertlib/kalman/smoothing.py
associative_params_single(m, chol_P, F, c, chol_Q)
Single time step for scan element for square root parallel Kalman smoother.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
Array
|
Mean of the smoother state. |
required |
chol_P
|
Array
|
Generalized Cholesky factor of the smoothing covariance. |
required |
F
|
Array
|
State transition matrix. |
required |
c
|
Array
|
State transition shift vector. |
required |
chol_Q
|
Array
|
Generalized Cholesky factor of the state transition noise covariance. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SmootherScanElement |
SmootherScanElement
|
The output of the associative operator applied to the input elements. |
Source code in cuthbertlib/kalman/smoothing.py
smoothing_operator(elem_i, elem_j)
Binary associative operator for the square root Kalman smoother.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elem_i
|
SmootherScanElement
|
Smoother scan element. |
required |
elem_j
|
SmootherScanElement
|
Smoother scan element. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SmootherScanElement |
SmootherScanElement
|
The output of the associative operator applied to the input elements. |
Source code in cuthbertlib/kalman/smoothing.py
cuthbertlib.kalman.sampling
Implements the square root parallel Kalman associative operator for sampling.
Samples from the smoothing distribution without doing the smoothing scan for means and (chol) covariances.
SamplerScanElement
Bases: NamedTuple
Kalman sampling scan element.
gain
instance-attribute
sample
instance-attribute
sqrt_associative_params(key, ms, chol_Ps, Fs, cs, chol_Qs, shape)
Compute the sampler scan elements.
Source code in cuthbertlib/kalman/sampling.py
sampling_operator(elem_i, elem_j)
Binary associative operator for sampling.