Skip to content

Calibration

The diffusion sigma^2 sets the size of the posterior uncertainty. The solvers calibrate it online with the policy passed as calibration= ("dynamic" by default, see Diffusion calibration). The estimators below work on a finished run: estimate sigma^2 from the innovations a result carries (result.mz, result.Pz_sqr) and rescale its stored covariances.

Online policies

NoCalibration

Bases: Calibration

Fixed diffusion: propagate the prior's noise unscaled.

The scalar quasi-MLE is still computed and reported as sigma_sqr, so a run can be rescaled post hoc (see posthoc_mle_sigma_sqr).

calibrate

calibrate(residual, H, Q_sqr, *, H_ek0)

Return the scalar quasi-MLE and a unit diffusion.

DynamicCalibration

Bases: Calibration

Scalar per-step diffusion, baked into the step's process noise.

Attributes:

Name Type Description
min_sigma_sqr float

Lower bound on the estimate. A positive floor keeps a residual that vanishes identically (a system at rest) from collapsing the diffusion to zero.

calibrate

calibrate(residual, H, Q_sqr, *, H_ek0)

Return the floored scalar quasi-MLE, also as the diffusion.

DiagonalCalibration

Bases: Calibration

One diffusion per solution component.

sigma_i^2 = r_i^2 / (H Q H.T)_ii. Requires the state block of Xi to be diagonal; checked when a solve starts.

Attributes:

Name Type Description
jacobian Literal['ek1', 'ek0']

"ek1" (default) takes H from the linearization; for a decoupled system this is the scalar estimate of each component, for a coupled Jacobian the diagonal is a heuristic. "ek0" takes the ODE's left-hand-side selector (E1 for x' = f, E2 for x'' = f). It is deprecated and will be removed in 0.9: with an EK0 correction it equals "ek1", and with EK1 both calibrate to within a few percent on the problems we measured.

min_sigma_sqr float

Lower bound on each component's estimate.

calibrate

calibrate(residual, H, Q_sqr, *, H_ek0)

Return the floored per-component estimate, also as the diffusion.

validate

validate(prior) -> None

Reject a prior whose state block of Xi is not diagonal.

Calibration

Bases: Module

Base class of the diffusion-calibration policies.

calibrate abstractmethod

calibrate(
    residual: Array,
    H: Array,
    Q_sqr: Array,
    *,
    H_ek0: Callable[[], Array],
) -> tuple[Array, Array]

Estimate sigma^2 for one step and choose the diffusion to apply.

Parameters:

Name Type Description Default
residual Array

ODE residual at the predicted mean, shape [d].

required
H Array

Its Jacobian (the linearization's ODE rows), shape [d, D].

required
Q_sqr Array

Square-root process noise of the step, shape [D, D].

required
H_ek0 Callable[[], Array]

Returns the ODE's left-hand-side selector in the same coordinates as H; only called by policies that need it.

required

Returns:

Type Description
Array

(sigma_sqr, diffusion): the estimate (scalar, or one per

Array

component) and the diffusion the step propagates with, which the

tuple[Array, Array]

step applies to the prior's state block

tuple[Array, Array]

(prior.apply_state_sigma_sqr).

validate

validate(prior) -> None

Reject a prior this policy cannot calibrate (called once per solve).

Post-hoc estimators

posthoc_mle_sigma_sqr

posthoc_mle_sigma_sqr(
    mz_seq: ArrayLike, Pz_seq_sqr: ArrayLike
) -> Array

Closed-form MLE of sigma^2 over a fixed-step trajectory.

Computes

sigma_hat^2 = (1 / (N * d)) * sum_n mz^{(n)} . T @ S_n^{-1} @ mz^{(n)}

which is the joint MLE under a constant sigma assumption. Equivalent to the mean of quasi_mle_sigma_sqr applied step-by-step.

The same R=0 caveat as quasi_mle_sigma_sqr applies: Pz_seq_sqr must be the prior-propagated predicted-observation covariance, with no measurement noise mixed in. For the typical fixed-step ODE-information run, Pz_seq_sqr from the loop output already satisfies this because ODEInformation returns R = 0 by default.

Parameters:

Name Type Description Default
mz_seq ArrayLike

Sequence of predicted observation means, shape [N, d].

required
Pz_seq_sqr ArrayLike

Sequence of square-root observation covariances, shape [N, d, d].

required

Returns:

Type Description
Array

Scalar JAX array containing the MLE of sigma^2.

quasi_mle_sigma_sqr

quasi_mle_sigma_sqr(mz: Array, Pz_sqr: Array) -> Array

Per-step quasi-MLE of the scalar diffusion sigma^2 (Bosch et al. 2021).

Computes

sigma_hat^2 = (1 / d) * mz.T @ S^{-1} @ mz

where d = mz.shape[0] and S = Pz_sqr.T @ Pz_sqr is a noise-free predicted-observation covariance under the implicit assumption that S scales linearly with sigma^2. Which S to use depends on the calibration mode (see the module docstring).

Pz_sqr must exclude any measurement noise R. The estimator treats S as scaling linearly with sigma^2. Adding R to the denominator inflates it by a constant and biases sigma_hat^2 down. For filtering on the ODE information alone, measure.noise_sqr returns zero (the usual case), so the predicted covariance is already noise-free. For data-assimilation workflows with R != 0, pre-compute the noise-free covariance with ode_filters.gaussian.marginalize and a zero noise factor, or use quasi_mle_sigma_sqr_from_Q, which builds H Q H.T directly and never sees R.

Parameters:

Name Type Description Default
mz Array

Predicted observation mean (a.k.a. ODE residual mean), shape [d].

required
Pz_sqr Array

Square-root of the noise-free predicted observation covariance, shape [d, d] (upper-triangular).

required

Returns:

Type Description
Array

Scalar JAX array containing the per-step quasi-MLE of sigma^2.

quasi_mle_sigma_sqr_from_Q

quasi_mle_sigma_sqr_from_Q(
    mz: Array, H: Array, Q_sqr: Array
) -> Array

Per-step quasi-MLE of sigma^2 in the dynamic-diffusion convention.

Uses S = H Q(h) H.T, the propagation of the current step's process noise only, as the residual covariance. This is the Bosch-Tronarp- Hennig 2021 per-step quasi-MLE (Eq. 32). The resulting sigma_hat^2 is intended to be baked into Q_h for the current step's propagation; past-step contributions in A P_prev A.T keep their own previously-applied scaling.

Parameters:

Name Type Description Default
mz Array

Predicted observation mean (residual), shape [d].

required
H Array

Linearised observation Jacobian, shape [d, n].

required
Q_sqr Array

Square-root of the per-step process noise, shape [n, n].

required

Returns:

Type Description
Array

Scalar JAX array containing sigma_hat^2.

aggregate_sigma_sqr

aggregate_sigma_sqr(
    sigma_sqr_seq: ArrayLike,
    *,
    kind: Literal["mean", "last", "running"] = "mean",
) -> Array

Aggregate a sequence of per-step sigma^2 estimates.

Parameters:

Name Type Description Default
sigma_sqr_seq ArrayLike

Per-step quasi-MLE estimates, shape [N].

required
kind Literal['mean', 'last', 'running']

Aggregation method.

  • "mean": arithmetic mean (closed-form joint MLE under constant sigma; equivalent to posthoc_mle_sigma_sqr).
  • "last": use only the final per-step estimate.
  • "running": per-step running mean sigma_hat^2_n = (1/n) sum_{k<=n} sigma^2_k. Returns an array of shape [N] rather than a scalar.
'mean'

Returns:

Type Description
Array

Scalar JAX array ("mean", "last") or 1-D array ("running").

Rescaling

rescale_sqr

rescale_sqr(
    P_sqr: Array,
    sigma_sqr: ArrayLike,
    *,
    prior: _StateRescalable | None = None,
) -> Array

Rescale a single square-root covariance by sqrt(sigma^2).

If P = P_sqr.T @ P_sqr, then (sqrt(s) * P_sqr).T @ (sqrt(s) * P_sqr) == s * P. Used to apply a per-step or global sigma to stored covariances.

Parameters:

Name Type Description Default
P_sqr Array

Square-root covariance.

required
sigma_sqr ArrayLike

Non-negative scalar; the variance multiplier.

required
prior _StateRescalable | None

Optional prior. When given, the rescaling is routed through prior.apply_state_sigma_to_cov_sqr so that joint / latent-force priors scale only the ODE-state block and leave the hidden/input block unchanged. For non-joint priors this is identical to the default whole-covariance scaling. Pass it for every JointPrior result: without it the input block is scaled too, which is incorrect.

None

Returns:

Type Description
Array

Rescaled square-root covariance, same shape as P_sqr.

rescale_sqr_seq

rescale_sqr_seq(
    P_seq_sqr: ArrayLike,
    sigma_sqr: ArrayLike,
    *,
    prior: _StateRescalable | None = None,
) -> Array

Rescale a sequence of square-root covariances.

Parameters:

Name Type Description Default
P_seq_sqr ArrayLike

Stacked square-root covariances, shape [N, ...].

required
sigma_sqr ArrayLike

Either a scalar (applied globally) or a 1-D array of length N (applied per step).

required
prior _StateRescalable | None

Optional prior; see rescale_sqr. When given, joint / latent-force priors rescale only the state block.

None

Returns:

Type Description
Array

Rescaled stack, same shape as P_seq_sqr.