Skip to content

Gaussian algebra

The QR-based numerical core every filter step is built on. Covariances are propagated as upper-triangular factors P_sqr (with P = P_sqr.T @ P_sqr), never as dense matrices, which keeps them symmetric and positive-semi-definite (no indefiniteness from round-off; see notation).

A filter step is marginalize (predict) and invert (the backward conditional), then update (condition on the information, observed as zero), with log_likelihood of the innovation as its evidence. The adaptive smoother uses compose.

Types

Gaussian

Bases: NamedTuple

A Gaussian N(m, P) with P = P_sqr.T @ P_sqr.

Stacked along a leading axis it is a sequence of marginals, e.g. the smoothed solution: m of shape [K, n] and P_sqr of shape [K, n, n].

Attributes:

Name Type Description
m Array

Mean, shape [n].

P_sqr Array

Square-root covariance, shape [n, n].

cov property

cov: Array

Covariance P = P_sqr.T @ P_sqr (batched over leading axes).

std property

std: Array

Marginal standard deviations sqrt(diag(P)), shaped like m.

Computed from the factor without forming P: P_ii is the squared norm of column i of P_sqr.

Conditional

Bases: NamedTuple

An affine Gaussian conditional x | y ~ N(G y + d, P).

The filters store one per step, p(x_n | x_{n+1}): the backward conditional that smoothing and posterior sampling run on.

Attributes:

Name Type Description
G Array

Gain, shape [n, k].

d Array

Offset, shape [n].

P_sqr Array

Square-root covariance, shape [n, n].

AffineModel

Bases: NamedTuple

An affine Gaussian observation model z | x ~ N(H x + c, R).

The filters condition on z = 0: an ODE-information or data model linearized at some state, with c holding the (negated) data.

Attributes:

Name Type Description
H Array

Observation matrix, shape [k, n].

c Array

Offset, shape [k].

R_sqr Array

Square-root noise covariance, shape [k, k].

Operations

marginalize

marginalize(
    A: Array, b: Array, Q_sqr: Array, x: Gaussian
) -> Gaussian

Marginal of z = A x + b + w with x ~ N(m, P) and w ~ N(0, Q).

z ~ N(A m + b, A P A.T + Q), with the covariance factor from one QR of [P_sqr A.T; Q_sqr] (see the module docstring).

Parameters:

Name Type Description Default
A Array

Linear map, shape [k, n].

required
b Array

Offset, shape [k].

required
Q_sqr Array

Square-root noise covariance, shape [k, k].

required
x Gaussian

The Gaussian over x, mean shape [n].

required

Returns:

Type Description
Gaussian

The Gaussian over z.

Raises:

Type Description
ValueError

If the shapes do not match.

invert

invert(
    A: Array, Q_sqr: Array, x: Gaussian, z: Gaussian
) -> Conditional

Bayes' rule for z = A x + b + w: the conditional p(x | z).

Given the prior x and the marginal z (from marginalize with the same A, b, Q_sqr), returns x | z ~ N(G z + d, Lambda) with the gain G = P A.T Cov(z)^-1, d = m - G E[z] and the Joseph form Lambda = (I - G A) P (I - G A).T + G Q G.T. Observing z = 0 gives the posterior N(d, Lambda); in the filters' prediction it is the backward conditional p(x_n | x_{n+1}).

A component of z with exactly zero variance gets a zero gain column (the pseudo-inverse of Cov(z)): it carries no information about x. This is the backward conditional after an exactly zero calibrated diffusion from an exact initial value, e.g. a solve started at an equilibrium. A Cov(z) that is singular in a direction mixing components still gives NaN.

Parameters:

Name Type Description Default
A Array

Linear map, shape [k, n].

required
Q_sqr Array

Square-root noise covariance of w, shape [k, k]. A noise-free map needs an explicit zero factor.

required
x Gaussian

The prior over x.

required
z Gaussian

The marginal over z.

required

Returns:

Type Description
Conditional

The conditional p(x | z).

update

update(
    model: AffineModel, x: Gaussian
) -> tuple[Gaussian, Gaussian]

Condition x on observing z = 0 under z = H x + c + v.

Parameters:

Name Type Description Default
model AffineModel

The observation model; the data enter through c (observing y is c = -y).

required
x Gaussian

The prior.

required

Returns:

Type Description
Gaussian

(posterior, innovation): the posterior over x and the

Gaussian

predictive distribution of z (mean H m + c, the residual at the

tuple[Gaussian, Gaussian]

prior mean), whose density at zero is the step's evidence.

compose

compose(
    outer: Conditional, inner: Conditional
) -> Conditional

Compose p(x | y) (outer) and p(y | z) (inner) into p(x | z).

G = G1 G2, d = G1 d2 + d1, P = G1 P2 G1.T + P1: the marginal of the inner conditional's noise pushed through the outer one. Used by the adaptive fixed-point smoother to merge the per-step backward conditionals of a save interval into one (Kraemer 2025, "Adaptive Probabilistic ODE Solvers Without Adaptive Memory Requirements", Eq. 18/19).

Parameters:

Name Type Description Default
outer Conditional

p(x | y) = N(G1 y + d1, P1).

required
inner Conditional

p(y | z) = N(G2 z + d2, P2).

required

Returns:

Type Description
Conditional

p(x | z).

log_likelihood

log_likelihood(innovation: Gaussian) -> Array

Log-density at zero of the innovation N(mz, Pz): log N(0; mz, Pz).

The evidence an update contributes when it observes z = 0.