Linearization¶
How the filters turn a nonlinear information operator into the affine model each update conditions on: a Taylor expansion at a point (EK0 / EK1, iterated for the IEKF) or a statistical linear regression over a Gaussian (SLR, iterated for the IPLF). See Linearization schemes for when to use which.
Corrections¶
Correction
¶
Bases: Module
Base class of the linearization/correction strategies.
A Correction is an equinox.Module (static configuration), so it can be
captured by jax.jit / jax.lax.scan without retracing.
correct
abstractmethod
¶
correct(
measure: MeasurementModel,
x: Gaussian,
model: AffineModel,
*,
t: ArrayLike,
) -> tuple[Gaussian, Gaussian]
Update the predicted Gaussian x with the measurement model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure
|
MeasurementModel
|
Measurement model. |
required |
x
|
Gaussian
|
Predicted Gaussian. |
required |
model
|
AffineModel
|
|
required |
t
|
ArrayLike
|
Time. |
required |
Returns:
| Type | Description |
|---|---|
Gaussian
|
|
Gaussian
|
the step's evidence. |
linearize
¶
linearize(
measure: MeasurementModel, m: Array, *, t: ArrayLike
) -> AffineModel
The affine model at the predicted mean m (EK1 by default).
The diffusion calibration estimates sigma^2 from it before the
predicted covariance is known, and correct receives it.
TaylorCorrection
¶
Bases: Correction
Taylor-series correction: EK1 (order=1) or EK0 (order=0).
Attributes:
| Name | Type | Description |
|---|---|---|
order |
int
|
|
IteratedTaylorCorrection
¶
Bases: Correction
Iterated EKF (IEKF): per-step Gauss-Newton relinearization.
A single forward pass. Within each update, the EK1 linearization is
recomputed at the updated mean and the update is redone, for a fixed number
max_iters of passes (max_iters=1 reproduces EK1). The fixed
iteration count, in place of a while_loop with a convergence test,
keeps the correction reverse-mode differentiable, so it can be used inside
gradient-based parameter inference.
Attributes:
| Name | Type | Description |
|---|---|---|
max_iters |
int
|
Number of linearizations per step (>= 1). |
correct
¶
Update x, relinearizing at the updated mean max_iters - 1 times.
QuadratureCorrection
¶
Bases: Correction
Statistical linearization by quadrature (sigma-point / SLF family).
Replaces the Taylor tangent at the predicted mean with the affine map that
best fits the residual over the predictive distribution, and computes the
Gaussian expectations by quadrature on the projected marginal (see
ode_filters.linearization.statistical). Two things change relative to
TaylorCorrection(order=1):
Hbecomes the expected Jacobian instead of the Jacobian at the mean;- the linearization-residual covariance
Omegais added to the measurement noise, so the innovation covariance isH P H^T + Omega + R.Omegais the term that theSof a sigma-point filter carries and that of the EKF omits.
Both differences vanish for an affine vector field, so on linear problems this correction coincides with EK1 up to floating point. The diffusion calibration still uses the EK1 linearization at the predicted mean, because the statistical one needs the predicted covariance it is calibrating.
Where it matters: the closure error scales with the predictive spread of the
vector field's arguments. In a pure ODE solve that spread vanishes as
h -> 0 and this reduces to EK1, but with a latent force it has a floor
set by the irreducible force uncertainty, and the resulting Jensen gap does
not vanish under grid refinement.
Attributes:
| Name | Type | Description |
|---|---|---|
rule |
QuadratureRule
|
|
n_nodes |
int
|
Nodes per dimension for the Gauss-Hermite rule; exactness is
|
max_iters |
int
|
Number of posterior-linearization passes. |
correct
¶
Update x with the statistical linearization over the density.
taylor_linearize
¶
taylor_linearize(
measure: MeasurementModel,
state: Array,
*,
t: ArrayLike,
order: int = 1,
) -> AffineModel
Taylor linearization H x + c ~= g(x) of measure at state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure
|
MeasurementModel
|
Measurement model. |
required |
state
|
Array
|
Linearization point, shape |
required |
t
|
ArrayLike
|
Time. |
required |
order
|
int
|
|
1
|
Returns:
| Type | Description |
|---|---|
AffineModel
|
The affine model, with the measurement noise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Frozen linearizations¶
One affine model per filter step, for affine_filter and iterated_smoother.
AffineSurrogate
¶
Bases: NamedTuple
One affine information model per filter step, stacked.
On a grid ts with nodes 0..N, step i (0..N-1) moves from node
i to node i + 1, and its residual is
z_i = H[i] @ x_{i+1} + c[i] + v_i with v_i ~ N(0, R_sqr[i].T @ R_sqr[i]);
the filter observes z_i = 0. A linearization trajectory is accordingly
the states at nodes 1..N.
Attributes:
| Name | Type | Description |
|---|---|---|
H |
Array
|
Observation matrices, shape |
c |
Array
|
Offsets, shape |
R_sqr |
Array
|
Upper-triangular square roots of the effective noise (including
any linearization residual), shape |
taylor_surrogate
¶
taylor_surrogate(
measure: MeasurementModel,
m_seq: Array,
*,
ts: ArrayLike,
) -> AffineSurrogate
First-order Taylor (EK1) linearization of measure along a trajectory.
Linearizing at a filter result's m_pred reproduces that EK1 filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure
|
MeasurementModel
|
ODE-information model. |
required |
m_seq
|
Array
|
Linearization points, the states at nodes |
required |
ts
|
ArrayLike
|
The |
required |
Returns:
| Type | Description |
|---|---|
AffineSurrogate
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
slr_surrogate
¶
slr_surrogate(
measure: MeasurementModel,
m_seq: Array,
P_seq_sqr: Array,
*,
ts: ArrayLike,
rule: QuadratureRule = "gauss_hermite",
n_nodes: int = 4,
) -> AffineSurrogate
Statistical linearization of measure over a trajectory of Gaussians.
The linearization residual Omega of each step is part of its effective
noise R_sqr (see slr_linearize).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure
|
MeasurementModel
|
ODE-information model. |
required |
m_seq
|
Array
|
Means at nodes |
required |
P_seq_sqr
|
Array
|
Square-root covariances at nodes |
required |
ts
|
ArrayLike
|
The |
required |
rule
|
QuadratureRule
|
Quadrature rule (see |
'gauss_hermite'
|
n_nodes
|
int
|
Nodes per dimension for the Gauss-Hermite rule. |
4
|
Returns:
| Type | Description |
|---|---|
AffineSurrogate
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Statistical linearization¶
The primitive behind QuadratureCorrection and slr_surrogate, and a check for
the argument selectors of a custom measurement model. The quadrature rule is
chosen by name (rule="gauss_hermite" or "cubature", with n_nodes).
slr_linearize
¶
slr_linearize(
measure: MeasurementModel,
m_lin: Array,
P_lin_sqr: Array,
*,
t: ArrayLike,
rule: QuadratureRule = "gauss_hermite",
n_nodes: int = 4,
) -> SLRModel
Statistically linearise the residual with respect to N(m_lin, P_lin).
Computes the MSE-optimal affine surrogate of measure.g under the given
Gaussian, with the required expectations evaluated by quadrature over the
projected marginal N(E_args m_lin, E_args P_lin E_args^T). See the
module docstring for why that projection is exact.
The linearisation density is a free argument, and it is the axis that separates the filter variants: passing the predictive moments gives the one-shot sigma-point / SLF update, passing the current posterior moments gives the posterior-linearisation iteration (IPLF), and passing smoothed moments gives IPLS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure
|
MeasurementModel
|
ODE-information measurement model. Its |
required |
m_lin
|
Array
|
Mean of the linearisation density, shape |
required |
P_lin_sqr
|
Array
|
Square-root covariance of the linearisation density
( |
required |
t
|
ArrayLike
|
Current time. |
required |
rule
|
QuadratureRule
|
Quadrature rule (see |
'gauss_hermite'
|
n_nodes
|
int
|
Nodes per dimension for the Gauss-Hermite rule. Exactness is
|
4
|
Returns:
| Type | Description |
|---|---|
SLRModel
|
The |
SLRModel
¶
Bases: NamedTuple
Affine surrogate of the residual produced by statistical linearisation.
Attributes:
| Name | Type | Description |
|---|---|---|
H |
Array
|
Effective observation matrix, shape |
c |
Array
|
Effective offset, shape |
R_eff_sqr |
Array
|
Square root of the effective measurement noise
|
Omega_sqr |
Array
|
Square-root factor of the linearisation-residual covariance
alone, shape |
check_arg_projection
¶
check_arg_projection(
measure: MeasurementModel,
state: ArrayLike,
*,
t: ArrayLike,
offsets: ArrayLike | None = None,
atol: float = 1e-10,
) -> None
Verify that measure.E_args covers every coordinate g is nonlinear in.
If E_args omits a coordinate that the vector field reads,
slr_linearize is wrong and raises no error, because the quadrature
misses the spread in that direction. This function checks the defining
property directly: the Jacobian of g must not change under a state
perturbation that leaves E_args @ state fixed. It perturbs the state
along the null space of E_args.
Intended for tests and for validating a custom measurement subclass; it is a
concrete-value check and cannot run inside jit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure
|
MeasurementModel
|
Measurement model to check. |
required |
state
|
ArrayLike
|
Base state to check at, shape |
required |
t
|
ArrayLike
|
Current time. |
required |
offsets
|
ArrayLike | None
|
Perturbation magnitudes to try along each null-space direction.
Defaults to |
None
|
atol
|
float
|
Absolute tolerance on the Jacobian difference. |
1e-10
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If some null-space perturbation changes the Jacobian, i.e.
|