Skip to content

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

self.linearize(measure, x.m, t=t).

required
t ArrayLike

Time.

required

Returns:

Type Description
Gaussian

(posterior, innovation); the innovation's density at zero is

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

1 for the first-order (EK1) linearization with the full vector-field Jacobian (default). 0 for the zeroth-order (EK0) linearization, which never evaluates the vector-field Jacobian.

correct

correct(measure, x, model, *, t)

A Kalman update of x with the linearization at the prediction.

linearize

linearize(measure, m, *, t)

Taylor-linearize measure at m (order self.order).

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

correct(measure, x, model, *, t)

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):

  • H becomes the expected Jacobian instead of the Jacobian at the mean;
  • the linearization-residual covariance Omega is added to the measurement noise, so the innovation covariance is H P H^T + Omega + R. Omega is the term that the S of 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

"gauss_hermite" (default; tensor product, spectrally accurate, n_nodes ** p nodes) or "cubature" (third-degree spherical, 2 p nodes, derivative-free-equivalent and dimension-linear). p is the dimension of the vector field's arguments, not the state dimension.

n_nodes int

Nodes per dimension for the Gauss-Hermite rule; exactness is 2 * n_nodes - 1. A polynomial vector field of degree k needs n_nodes >= ceil((k + 1) / 2) for H and c, and n_nodes >= ceil((2 k + 1) / 2) for Omega as well. A cubic field (Duffing, van der Pol) is therefore reproduced exactly at n_nodes = 4, and a quadratic one (Lotka-Volterra, SIRD) at n_nodes = 3. Ignored by the cubature rule.

max_iters int

Number of posterior-linearization passes. 1 (default) is the one-shot filter; > 1 is the iterated posterior-linearization filter (IPLF), which refits the surrogate over the updated density. Contrast IteratedTaylorCorrection, which iterates the linearization point at zero spread. The whole-trajectory version is iterated_smoother(linearization="slr").

correct

correct(measure, x, model, *, t)

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 [D].

required
t ArrayLike

Time.

required
order int

1 for the full Jacobian (EK1); 0 drops the vector-field Jacobian from the ODE rows (EK0), which needs a model with a linearize_ek0 method (EK0Linearizable, which the ODE-information models implement).

1

Returns:

Type Description
AffineModel

The affine model, with the measurement noise.

Raises:

Type Description
TypeError

If order is 0 and measure has no linearize_ek0.

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 [N, m, D].

c Array

Offsets, shape [N, m].

R_sqr Array

Upper-triangular square roots of the effective noise (including any linearization residual), shape [N, m, m].

model

model(i: ArrayLike) -> AffineModel

The affine model of step i.

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 1..N, shape [N, D].

required
ts ArrayLike

The N update times, i.e. the grid's ts[1:].

required

Returns:

Type Description
AffineSurrogate

The AffineSurrogate with the measurement noise as R_sqr.

Raises:

Type Description
ValueError

If ts does not have one time per linearization point.

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 1..N, shape [N, D].

required
P_seq_sqr Array

Square-root covariances at nodes 1..N, shape [N, D, D].

required
ts ArrayLike

The N update times, i.e. the grid's ts[1:].

required
rule QuadratureRule

Quadrature rule (see QuadratureCorrection).

'gauss_hermite'
n_nodes int

Nodes per dimension for the Gauss-Hermite rule.

4

Returns:

Type Description
AffineSurrogate

The AffineSurrogate.

Raises:

Type Description
ValueError

If ts does not have one time per linearization point.

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 E_args declares which coordinates the vector field reads; use check_arg_projection when writing a custom subclass.

required
m_lin Array

Mean of the linearisation density, shape [state_dim].

required
P_lin_sqr Array

Square-root covariance of the linearisation density (P_lin = P_lin_sqr.T @ P_lin_sqr).

required
t ArrayLike

Current time.

required
rule QuadratureRule

Quadrature rule (see quadrature_nodes).

'gauss_hermite'
n_nodes int

Nodes per dimension for the Gauss-Hermite rule. Exactness is 2 * n_nodes - 1, so a degree-k polynomial vector field needs n_nodes >= (k + 1) / 2 for H and c and n_nodes >= (2k + 1) / 2 for Omega as well (a cubic wants n_nodes = 4).

4

Returns:

Type Description
SLRModel

The SLRModel surrogate.

SLRModel

Bases: NamedTuple

Affine surrogate of the residual produced by statistical linearisation.

Attributes:

Name Type Description
H Array

Effective observation matrix, shape [obs_dim, state_dim]. Equals the expected Jacobian of g under the linearisation density; the EK1 Jacobian is its zero-spread limit.

c Array

Effective offset, shape [obs_dim], so that H x + c has the correct mean under the linearisation density.

R_eff_sqr Array

Square root of the effective measurement noise R + Omega, shape [obs_dim, obs_dim], upper triangular (R_eff = R_eff_sqr.T @ R_eff_sqr). This is what the update consumes: the linearisation residual enters the innovation covariance as inflated measurement noise, which is exactly how a sigma-point filter's S differs from the EKF's H P H^T + R.

Omega_sqr Array

Square-root factor of the linearisation-residual covariance alone, shape [K, obs_dim] with K the total number of quadrature nodes (n_nodes ** p for Gauss-Hermite, 2 p for cubature; Omega = Omega_sqr.T @ Omega_sqr). It is neither triangular nor square, since it stacks the weighted fit residuals at the nodes. Exposed for diagnostics; R_eff_sqr already contains it. Zero for an affine vector field.

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 [state_dim].

required
t ArrayLike

Current time.

required
offsets ArrayLike | None

Perturbation magnitudes to try along each null-space direction. Defaults to (1.0, -3.7).

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. E_args omits a coordinate the residual is nonlinear in.