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(get_init_log_density, 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 |
|---|---|---|---|
get_init_log_density
|
GetInitLogDensity
|
Function to get log density log p(x_0)
and linearization point.
Only takes |
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
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
GetInitLogDensity
Bases: Protocol
Protocol for extracting the initial specifications.
__call__(model_inputs)
Get the initial log density and initial linearization point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_inputs
|
ArrayTreeLike
|
Model inputs. |
required |
Returns:
| Type | Description |
|---|---|
tuple[LogDensity, Array]
|
Tuple with initial log density and initial linearization point. |
Source code in cuthbert/gaussian/taylor/types.py
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. |