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
¶
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
¶
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']
|
|
min_sigma_sqr |
float
|
Lower bound on each component's estimate. |
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 |
required |
H
|
Array
|
Its Jacobian (the linearization's ODE rows), shape |
required |
Q_sqr
|
Array
|
Square-root process noise of the step, shape |
required |
H_ek0
|
Callable[[], Array]
|
Returns the ODE's left-hand-side selector in the same
coordinates as |
required |
Returns:
| Type | Description |
|---|---|
Array
|
|
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]
|
( |
validate
¶
Reject a prior this policy cannot calibrate (called once per solve).
Post-hoc estimators¶
posthoc_mle_sigma_sqr
¶
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 |
required |
Pz_seq_sqr
|
ArrayLike
|
Sequence of square-root observation covariances, shape
|
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar JAX array containing the MLE of sigma^2. |
quasi_mle_sigma_sqr
¶
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 |
required |
Pz_sqr
|
Array
|
Square-root of the noise-free predicted observation
covariance, shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar JAX array containing the per-step quasi-MLE of sigma^2. |
quasi_mle_sigma_sqr_from_Q
¶
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 |
required |
H
|
Array
|
Linearised observation Jacobian, shape |
required |
Q_sqr
|
Array
|
Square-root of the per-step process noise, shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar JAX array containing |
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 |
required |
kind
|
Literal['mean', 'last', 'running']
|
Aggregation method.
|
'mean'
|
Returns:
| Type | Description |
|---|---|
Array
|
Scalar JAX array ( |
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
|
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Rescaled square-root covariance, same shape as |
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 |
required |
sigma_sqr
|
ArrayLike
|
Either a scalar (applied globally) or a 1-D array of
length |
required |
prior
|
_StateRescalable | None
|
Optional prior; see |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Rescaled stack, same shape as |