Gaussian Taylor Filter and Smoother
cuthbert.gaussian.taylor
cuthbert.gaussian.taylor.filter
Linearized Taylor Kalman filter.
Uses automatic differentiation to extract conditionally Gaussian parameters from log densities of the dynamics and observation distributions.
This differs from gaussian/moments, which requires mean and chol_cov
functions as input rather than log densities.
I.e., we approximate conditional densities as
and potentials as
where \(L\) is the Cholesky factor of the covariance matrix.
See cuthbertlib.linearize for more details.
Parallelism via associative_scan is supported, but requires the state argument
to be ignored in get_dynamics_log_density and get_observation_func.
I.e. the linearization points are pre-defined or extracted from model inputs.
build_filter(init_log_density, init_linearization_point, get_dynamics_log_density, get_observation_func, associative=False, rtol=None, ignore_nan_dims=False)
Build linearized Taylor Kalman inference filter.
If associative is True all filtering linearization points are pre-defined or
extracted from model inputs. The state argument should be ignored in
get_dynamics_log_density and get_observation_func.
If associative is False the linearization points can be extracted from the
previous filter state for dynamics parameters and the predict state for
observation parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_log_density
|
LogDensity
|
Initial log density log p(x_0). For factorial models, this is the sum of the log densities for all factors. |
required |
init_linearization_point
|
ArrayLike
|
Linearization point for the initial log density. |
required |
get_dynamics_log_density
|
GetDynamicsLogDensity
|
Function to get dynamics log density log p(x_t+1 | x_t)
and linearization points (for the previous and current time points)
If |
required |
get_observation_func
|
GetObservationFunc
|
Function to get observation function (either conditional
log density or log potential), linearization point and optional observation
(not required for log potential functions).
If |
required |
associative
|
bool
|
If True, then the filter is suitable for associative scan, but
assumes that the |
False
|
rtol
|
float | None
|
The relative tolerance for the singular values of precision matrices
when passed to |
None
|
ignore_nan_dims
|
bool
|
Whether to treat dimensions with NaN on the diagonal of the precision matrices (found via linearization) as missing and ignore all rows and columns associated with them. |
False
|
Returns:
| Type | Description |
|---|---|
Filter
|
Linearized Taylor Kalman filter object. |
Source code in cuthbert/gaussian/taylor/filter.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
cuthbert.gaussian.taylor.smoother
Linearized Taylor Kalman smoother.
Uses automatic differentiation to extract conditionally Gaussian parameters from log densities of the dynamics and observation distributions.
This differs from gaussian/moments, which requires mean and chol_cov
functions as input rather than log densities.
I.e., we approximate conditional densities as
and potentials as
where \(L\) is the Cholesky factor of the covariance matrix.
See cuthbertlib.linearize for more details.
build_smoother(get_dynamics_log_density, rtol=None, ignore_nan_dims=False, store_gain=False, store_chol_cov_given_next=False)
Build linearized Taylor Kalman inference smoother.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_dynamics_log_density
|
GetDynamicsLogDensity
|
Function to get dynamics log density log p(x_t+1 | x_t) and linearization points (for the previous and current time points) |
required |
rtol
|
float | None
|
The relative tolerance for the singular values of precision matrices
when passed to |
None
|
ignore_nan_dims
|
bool
|
Whether to treat dimensions with NaN on the diagonal of the precision matrices (found via linearization) as missing and ignore all rows and columns associated with them. |
False
|
store_gain
|
bool
|
Whether to store the gain matrix in the smoother state. |
False
|
store_chol_cov_given_next
|
bool
|
Whether to store the chol_cov_given_next matrix in the smoother state. |
False
|
Returns:
| Type | Description |
|---|---|
Smoother
|
Linearized Taylor Kalman smoother object, suitable for associative scan. |
Source code in cuthbert/gaussian/taylor/smoother.py
cuthbert.gaussian.taylor.types
Provides types for the Taylor-series linearization of Gaussian state-space models.
LogPotential = LogDensity
module-attribute
GetDynamicsLogDensity
Bases: Protocol
Protocol for extracting the dynamics specifications.
__call__(state, model_inputs)
Get the dynamics log density and linearization points.
Linearization points required for both the previous and current time points
associative_scan only supported when state is ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
LinearizedKalmanFilterState
|
NamedTuple containing |
required |
model_inputs
|
ArrayTreeLike
|
Model inputs. |
required |
Returns:
| Type | Description |
|---|---|
tuple[LogConditionalDensity, Array, Array]
|
Tuple with dynamics log density and linearization points. |
Source code in cuthbert/gaussian/taylor/types.py
GetObservationFunc
Bases: Protocol
Protocol for extracting the required observation specifications.
__call__(state, model_inputs)
Extract observation function, linearization point and optional observation.
State is the predicted state after applying the Kalman dynamics propagation.
associative_scan only supported when state is ignored.
Two types of output are supported: - Observation log density function log p(y | x) and points x and y to linearize around. - Log potential function log G(x) and a linearization point x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
LinearizedKalmanFilterState
|
NamedTuple containing |
required |
model_inputs
|
ArrayTreeLike
|
Model inputs. |
required |
Returns:
| Type | Description |
|---|---|
tuple[LogConditionalDensity, Array, Array] | tuple[LogPotential, Array]
|
Either a tuple with observation function to linearize, linearization point and observation, or a tuple with log potential function and linearization point. |