Skip to content

Filters

The solvers return a FilterResult in the original state coordinates. The module provides the following functions:

  • gaussian_filter solves on a given time grid (uniform or not) and linearizes the ODE information at each prediction with a Correction.
  • gaussian_filter_adaptive takes adaptive steps between given save times.
  • affine_filter filters a frozen linearization (an AffineSurrogate).
  • rts_smoother smooths any result that carries backward conditionals.
  • sample_posterior draws a joint sample path from the smoothing posterior.
  • interpolate returns filtered or smoothed marginals between the grid nodes.
  • iterated_smoother implements the IEKS and the IPLS, which linearize along the smoothed trajectory, filter and smooth, and repeat.

Every step calibrates the diffusion with the calibration= policy ("dynamic" by default; see Diffusion calibration) and conditions on the data, if any, after the ODE information. The solvers take the data as measurements=, a list of Measurement objects, or as an obs_model built with prepare_observations (see Information). A preconditioned prior changes how a step is computed, not its result. See How to choose.

Data between the grid nodes

A data time between two grid nodes becomes a data-only node. On the fixed grid (gaussian_filter, affine_filter, iterated_smoother), the filter predicts to it, conditions on the data and continues without an update on the ODE information. The ODE information is that of the grid ts. At a data-only node the ODE evidence is zero, and the ODE innovation is reported with zero mean and an identity factor. The diffusion of a grid interval is estimated once, at the interval's start, from the prediction over the whole interval, and every step inside the interval propagates with it and reports it in sigma_sqr and diffusion. The update on the ODE information at the interval's end linearizes at the prediction that follows the data inside the interval. The result lives on the timeline, the grid with the data-only nodes, so rts_smoother, sample_posterior and interpolate apply unchanged. iterated_smoother linearizes at the smoothed marginals of the grid nodes.

gaussian_filter_adaptive lands on every data time between the save times and chooses its steps between them, so a data time is a full node there. Its result also lives on the timeline.

The FilterResult

Recover a covariance with P = P_sqr.T @ P_sqr (see notation). On K nodes, per-step fields have K - 1 entries; entry n belongs to the step from t[n] to t[n + 1].

Field Meaning
t the nodes: the time grid (the save times on the adaptive path), with the data-only nodes of the data, if any
m, P_sqr filtered mean and square-root covariance
log_likelihood ODE-information evidence, after calibration (not comparable across calibration policies)
log_likelihood_obs data evidence, each observation conditioned on the ODE information up to its time (None without data)
sigma_sqr per-step diffusion estimate (None on the adaptive path)
diffusion the diffusion each step propagated with: sigma_sqr under a calibrating policy, ones under "none" (None on the adaptive path); interpolate bridges with it
m_pred, P_pred_sqr predictions before each update (None on the adaptive path)
G_back, d_back, P_back_sqr backward conditionals p(x_n \| x_{n+1}), consumed by rts_smoother
mz, Pz_sqr ODE-information innovations; zero mean and identity factor at a data-only node
mz_obs, Pz_obs_sqr data innovations; rows without data are zero with unit variance
success adaptive: every save time reached with a finite evidence
n_accepted, n_rejected adaptive: steps per save interval
steps adaptive with record_steps > 0: every accepted step (a StepRecord)

result.filtered and result.backward return the marginals and the backward conditionals as a stacked Gaussian and Conditional.

By default (smoother=False), gaussian_filter_adaptive only filters. Its backward fields are then None, and rts_smoother raises. With smoother=True it composes one backward conditional per save interval (O(#save points) memory), with or without data.

Solvers

gaussian_filter

gaussian_filter(
    m_0: ArrayLike,
    P_0_sqr: ArrayLike,
    prior: BasePrior,
    measure: MeasurementModel,
    ts: ArrayLike,
    *,
    correction: Correction | None = None,
    calibration: Calibration | CalibrationMode = "dynamic",
    obs_model: ObsModel | None = None,
    measurements: Sequence[Measurement] | None = None,
    checkpoint: bool = False,
) -> FilterResult

Gaussian ODE filter over the time grid ts.

Each step predicts with the prior, calibrates the diffusion, updates on the ODE information linearized by correction at the prediction, and then on the data, if any (see ode_filters.filters.kernel). The grid may be non-uniform; on a uniform one the prior's transition is computed once.

Data between the grid nodes add data-only nodes, where the filter conditions on the data without an update on the ODE information. The diffusion of a grid interval is estimated at its start from the prediction over the whole interval, and its steps propagate with it. The result then lives on the timeline, the grid with the data-only nodes (see ode_filters.filters.fixed_grid).

Parameters:

Name Type Description Default
m_0 ArrayLike

Initial mean, shape [D].

required
P_0_sqr ArrayLike

Initial square-root covariance, shape [D, D].

required
prior BasePrior

Gauss-Markov prior (plain or preconditioned).

required
measure MeasurementModel

ODE-information model (the ODE plus conservation laws).

required
ts ArrayLike

Time grid, shape [K], strictly increasing; ts[0] is the time of the initial state.

required
correction Correction | None

Linearization (TaylorCorrection / IteratedTaylorCorrection / QuadratureCorrection); None is EK1.

None
calibration Calibration | CalibrationMode

Diffusion calibration policy, or one of "dynamic" (default), "none", "diagonal", "diagonal_ekf0" (deprecated).

'dynamic'
obs_model ObsModel | None

Data for the grid ts, from prepare_observations(measurements, prior.E0_state, ts).

None
measurements Sequence[Measurement] | None

The data as Measurement objects, in place of obs_model. They are converted with prepare_observations(measurements, prior.E0_state, ts), so the A of a measurement acts on the solution x = prior.E0_state @ state (for a JointPrior, the solution without the input), or on the full state with full_state=True.

None
checkpoint bool

Wrap each step in jax.checkpoint. Reverse-mode differentiation then stores only the state carried between steps and recomputes each step's intermediates in the backward pass, which costs one more forward pass. The values are identical and the gradients agree to round-off. Default False.

False

Returns:

Type Description
FilterResult

A FilterResult over ts, or over the timeline of the data if

FilterResult

they have data-only nodes.

Raises:

Type Description
ValueError

For an invalid grid, an obs_model built for another grid, both obs_model and measurements, invalid measurement times, or a calibration the prior does not support.

gaussian_filter_adaptive

gaussian_filter_adaptive(
    m_0: ArrayLike,
    P_0_sqr: ArrayLike,
    prior: BasePrior,
    measure: MeasurementModel,
    save_at: ArrayLike,
    *,
    correction: Correction | None = None,
    calibration: Calibration | CalibrationMode = "dynamic",
    obs_model: ObsModel | None = None,
    measurements: Sequence[Measurement] | None = None,
    atol: ArrayLike = 0.0001,
    rtol: ArrayLike = 0.01,
    h_init: ArrayLike | Literal["auto"] | None = None,
    max_step: ArrayLike | None = None,
    controller: StepSizeController | None = None,
    sigma_in_error: SigmaInError = "per_step",
    max_steps: int = 4096,
    smoother: bool = False,
    record_steps: int = 0,
) -> FilterResult

Adaptive-step Gaussian ODE filter, returning the solution at save_at.

Parameters:

Name Type Description Default
m_0 ArrayLike

Initial mean, shape [D].

required
P_0_sqr ArrayLike

Initial square-root covariance, shape [D, D].

required
prior BasePrior

Gauss-Markov prior (plain or preconditioned). Its q sets the default controller order.

required
measure MeasurementModel

ODE-information model (the ODE plus conservation laws).

required
save_at ArrayLike

Strictly increasing save times; save_at[0] is the initial time, where the initial state is returned unchanged.

required
correction Correction | None

Linearization; None is EK1.

None
calibration Calibration | CalibrationMode

Diffusion calibration policy, or one of "dynamic" (default), "none", "diagonal", "diagonal_ekf0" (deprecated).

'dynamic'
obs_model ObsModel | None

Data for the save times, from prepare_observations(measurements, prior.E0_state, save_at); conditioned on after landing on each save time. Data between the save times give the ObsModel data-only nodes; the solver then lands on every node of its timeline and conditions on the data there. Between two landing points it chooses its steps, so a data time becomes a node like a save time, unlike a data-only node of the fixed grid, which has no ODE update.

None
measurements Sequence[Measurement] | None

The data as Measurement objects, in place of obs_model. They are converted with prepare_observations(measurements, prior.E0_state, save_at), so the A of a measurement acts on the solution x = prior.E0_state @ state (for a JointPrior, the solution without the input), or on the full state with full_state=True.

None
atol ArrayLike

Absolute tolerance of the local-error estimate.

0.0001
rtol ArrayLike

Relative tolerance of the local-error estimate.

0.01
h_init ArrayLike | Literal['auto'] | None

First trial step. None (default) takes (save_at[-1] - save_at[0]) / 100. "auto" computes it from m_0 and the tolerances by the starting step-size rule of Hairer, Norsett & Wanner (1993, Sec. II.4). With the scale sc = atol + rtol |x0| and the RMS norms d0 = ||x0 / sc||, d1 = ||x0' / sc|| and d2 = ||x0'' / sc||, the step is min(100 h0, h1) with h0 = 0.01 d0 / d1 and h1 = (0.01 / max(d1, d2))^(1 / (q + 1)). If d0 or d1 is below 1e-5, h0 is 1e-6; if max(d1, d2) <= 1e-15, h1 is max(1e-6, 1e-3 h0). Both fallbacks are in the time unit of save_at; a zero x0 or x0' limits the step to at most 1e-4. The rule reads x0' (E1) and, for q >= 2, x0'' (E2) from m_0, which must therefore carry the derivatives, as taylor_mode_initialization provides. For q = 1, x0'' is the explicit-Euler difference (f(x0 + h0 x0', t0 + h0) - f(x0, t0)) / h0 of the first-order ODE rows of measure. max_step and the next save time bound the first step as they bound every step.

None
max_step ArrayLike | None

Upper bound on every step, the first trial step included; None (default) leaves the next save time as the only bound. A loose tolerance can step over a feature much shorter than its steps, such as a brief pulse in a forcing term, without the error estimate seeing it; a max_step shorter than the feature resolves it. There is no lower bound: a solve that needs too many steps reports success=False (see max_steps).

None
controller StepSizeController | None

Step-size controller; defaults to PIController(order=prior.q). Its propose runs inside the traced loop, so a custom controller must use jax.numpy.

None
sigma_in_error SigmaInError

The diffusion in the error estimate. "per_step" (default) uses the step's own estimate (Bosch et al. 2021); "running_mean" the mean over the accepted steps so far. The noise of this mean decreases with the number of steps, so the step sizes vary more smoothly, but the mean lags an abrupt change in the problem's stiffness.

'per_step'
max_steps int

Cap on attempts per save interval (it bounds the checkpointed while-loop). Raise it, or loosen the tolerances, if result.success is False.

4096
smoother bool

Also compose a backward conditional per save interval, so rts_smoother applies to the result.

False
record_steps int

Record up to this many accepted steps in result.steps (see StepRecord); 0 records none. The record is carried through the loop, so keep it off where memory or speed matters, e.g. inside an optimization.

0

Returns:

Type Description
FilterResult

A FilterResult on save_at, or on the timeline of the data if

FilterResult

they have data-only nodes. log_likelihood and

FilterResult

log_likelihood_obs are the ODE-information and data evidence;

FilterResult

n_accepted / n_rejected count the steps per save interval;

FilterResult

m_pred, P_pred_sqr and sigma_sqr are None.

Raises:

Type Description
ValueError

For an invalid save_at, sigma_in_error, record_steps or max_step (not a positive scalar), an obs_model built for another grid, both obs_model and measurements, invalid measurement times, a calibration the prior does not support, or an h_init string other than "auto". Also for h_init="auto" with a prior of order q = 0, or of order q = 1 with a measure whose number of ODE rows differs from the dimension of the solution.

affine_filter

affine_filter(
    m_0: ArrayLike,
    P_0_sqr: ArrayLike,
    prior: BasePrior,
    surrogate: AffineSurrogate,
    ts: ArrayLike,
    *,
    obs_model: ObsModel | None = None,
    measurements: Sequence[Measurement] | None = None,
    checkpoint: bool = False,
) -> FilterResult

Square-root Kalman filter of a frozen linearization.

Runs the same steps as gaussian_filter, but the ODE information of step i is the given affine model surrogate.model(i) instead of a linearization at the prediction. The diffusion is fixed (the prior carries its scale); sigma_sqr reports the quasi-MLE over all rows of the surrogate. The result supports everything a gaussian_filter result does, e.g. rts_smoother. With data-only nodes, the surrogate keeps one model per step of the grid ts, which updates at the grid node that ends the step, and the result lives on the timeline.

Parameters:

Name Type Description Default
m_0 ArrayLike

Initial mean, shape [D].

required
P_0_sqr ArrayLike

Initial square-root covariance, shape [D, D].

required
prior BasePrior

Gauss-Markov prior (plain or preconditioned).

required
surrogate AffineSurrogate

One affine model per step of ts (see AffineSurrogate), e.g. from taylor_surrogate or slr_surrogate.

required
ts ArrayLike

Time grid, shape [N + 1].

required
obs_model ObsModel | None

Data for the grid ts, from prepare_observations(measurements, prior.E0_state, ts).

None
measurements Sequence[Measurement] | None

The data as Measurement objects, in place of obs_model (see gaussian_filter).

None
checkpoint bool

Wrap each step in jax.checkpoint (see gaussian_filter). Default False.

False

Returns:

Type Description
FilterResult

A FilterResult over ts, or over the timeline of the data if

FilterResult

they have data-only nodes.

Raises:

Type Description
ValueError

If the surrogate does not have one model per step, or its shapes do not match each other or the state; for an obs_model built for another grid, or both obs_model and measurements.

rts_smoother

rts_smoother(result: FilterResult) -> Gaussian

Rauch-Tung-Striebel smoothing of a filter result.

Runs the stored backward conditionals p(x_n | x_{n+1}) from the last filtered marginal back to the first. Works on any result that carries them: gaussian_filter, affine_filter, and gaussian_filter_adaptive with smoother=True (one composite conditional per save interval).

Parameters:

Name Type Description Default
result FilterResult

A FilterResult with backward conditionals.

required

Returns:

Type Description
Gaussian

The smoothed marginals as a stacked Gaussian: means [K, D] and

Gaussian

square-root covariances [K, D, D] (unpacks as m, P_sqr).

Raises:

Type Description
ValueError

If the result carries no backward conditionals.

Posterior samples and dense output

sample_posterior

sample_posterior(key: Array, result: FilterResult) -> Array

A sample path from the smoothing posterior of a filter result.

Draws the last state from its filtered marginal, then each earlier state from the backward conditional p(x_n | x_{n+1}). The result is an exact sample of the joint posterior over all nodes, whereas independent draws from the marginals would not be. The key is split into one key per node. Vmap over keys for many paths.

With exact ODE information (zero noise R) the posterior is singular and the path for a given key depends on which square-root factor the QR returns: a batched and a looped run can differ, and the path is not smooth in the model's parameters. Each path is still an exact draw. A small ODE noise, e.g. measure.with_noise(1e-10), makes the paths reproducible.

Parameters:

Name Type Description Default
key Array

A jax.random key.

required
result FilterResult

A FilterResult with backward conditionals.

required

Returns:

Type Description
Array

The path at result.t, shape [K, D].

Raises:

Type Description
ValueError

If the result carries no backward conditionals.

interpolate

interpolate(
    result: FilterResult,
    prior: BasePrior,
    ts: ArrayLike,
    *,
    smoothed: bool = True,
) -> Gaussian

Marginals of a fixed-grid result at times between its nodes.

For t in [t_n, t_{n+1}] the prior bridges the two nodes of result.t (grid nodes or data-only nodes): predict from the filtered state at t_n to t, and, for the smoothed marginal, condition on the smoothed state at t_{n+1} through the backward conditional of the remaining step. Each sub-step uses the diffusion its step propagated with (result.diffusion), so the result agrees with the filter and the smoother at the grid nodes.

Parameters:

Name Type Description Default
result FilterResult

A gaussian_filter / affine_filter result.

required
prior BasePrior

The prior the result was computed with.

required
ts ArrayLike

Query times in [t_0, t_K], shape [M].

required
smoothed bool

Return smoothed marginals (default) or filtered ones (the prediction from the last node before t).

True

Returns:

Type Description
Gaussian

The marginals at ts as a stacked Gaussian.

Raises:

Type Description
ValueError

If the result has no per-step diffusion (an adaptive result).

Result types

FilterResult

Bases: NamedTuple

Result of a Gaussian ODE filter, in the original state coordinates.

The solve has K nodes; per-step arrays have K - 1 entries, entry n belonging to the step from t[n] to t[n + 1]. Covariances are square-root factors: P = P_sqr.T @ P_sqr.

Attributes:

Name Type Description
t Array

The nodes, shape [K]: the time grid (the save times on the adaptive path), or the timeline of data with data-only nodes.

m Array

Filtered means, shape [K, D].

P_sqr Array

Filtered square-root covariances, shape [K, D, D].

log_likelihood Array

ODE-information evidence, sum_n log p(z_n | z_<n, y_<n), with the ODE residuals z observed as zero, taken after the diffusion calibration (so not comparable across calibration policies).

log_likelihood_obs Array | None

Data evidence, sum_n log p(y_n | z_<=n, y_<n): each observation conditioned on the ODE information up to its own time only (None without data). The sum with log_likelihood is log p(Z, Y); it is not the conditional evidence log p(Y | Z), which also conditions on later ODE information (see fenrir_loglik).

sigma_sqr Array | None

Diffusion estimate per step, shape [K - 1] ([K - 1, d] for a per-component policy); None on the adaptive path.

diffusion Array | None

The diffusion each step propagated with: sigma_sqr under a scaling policy, one under NoCalibration (None on the adaptive path).

m_pred Array | None

Predicted means per step, [K - 1, D] (None on the adaptive path).

P_pred_sqr Array | None

Predicted square-root covariances per step.

G_back Array | None

Gains of the backward conditionals p(x_n | x_{n+1}), per step, [K - 1, D, D]. On the adaptive path with smoother=True one composite conditional per save interval; None without.

d_back Array | None

Offsets of the backward conditionals.

P_back_sqr Array | None

Square-root covariances of the backward conditionals.

mz Array | None

Means of the ODE-information innovations per step (the residual at the predicted mean). Zero at a step that ends at a data-only node, which has no ODE update.

Pz_sqr Array | None

Square-root covariances of the ODE-information innovations; the identity at a step that ends at a data-only node.

mz_obs Array | None

Means of the data innovations per step, h(m) - y at the state after the ODE update (None without data). Rows without data at a step are zero.

Pz_obs_sqr Array | None

Square-root covariances of the data innovations. Rows without data have unit variance and no correlation, so they add nothing to the whitened residual.

success Array | None

Adaptive path: whether every save time was reached with a finite log-likelihood (None on the fixed grid).

n_accepted Array | None

Adaptive path: accepted steps per save interval.

n_rejected Array | None

Adaptive path: rejected steps per save interval.

steps StepRecord | None

Adaptive path with record_steps > 0: the accepted steps (see StepRecord).

backward property

backward: Conditional

The backward conditionals as a stacked Conditional.

Raises:

Type Description
ValueError

If the result carries none (the adaptive path without smoother=True).

filtered property

filtered: Gaussian

The filtered marginals as a stacked Gaussian.

StepRecord

Bases: NamedTuple

The accepted steps of an adaptive solve, in order.

Rows past count (or past the record's length, if the solve took more steps than it holds) are NaN.

Attributes:

Name Type Description
t Array

Time at the end of each accepted step, shape [n].

h Array

Size of each accepted step, shape [n].

m Array

Filtered mean after each accepted step, shape [n, D].

sigma_sqr Array

Diffusion estimate of each accepted step, shape [n, d].

count Array

Number of accepted steps of the whole solve.

Iterated smoothing

See Linearization schemes.

iterated_smoother

iterated_smoother(
    m_0: ArrayLike,
    P_0_sqr: ArrayLike,
    prior: BasePrior,
    measure: MeasurementModel,
    ts: ArrayLike,
    *,
    linearization: Literal["taylor", "slr"] = "taylor",
    n_iters: int = 3,
    init: ArrayLike | None = None,
    init_P_sqr: ArrayLike | None = None,
    obs_model: ObsModel | None = None,
    measurements: Sequence[Measurement] | None = None,
    rule: QuadratureRule = "gauss_hermite",
    n_nodes: int = 4,
    diagnostics: Callable[[IterationState], Any]
    | None = None,
    checkpoint: bool = False,
) -> IteratedSmootherResult

Iterated smoother (IEKS / IPLS) over a time grid.

Without init, the first linearization point is the smoothed trajectory of a one-shot filter with the matching correction (EK1 for Taylor, a QuadratureCorrection for SLR). Each of the n_iters passes then linearizes along the current point (taylor_surrogate / slr_surrogate), runs affine_filter and rts_smoother, and takes the smoothed marginals as the next point. n_iters=0 returns the one-shot filter and smoother.

With data-only nodes (data between the grid nodes, see prepare_observations), the surrogates stay on the grid: each pass linearizes at the smoothed marginals of the grid nodes, while its filter and smoother run over the timeline of the data.

Parameters:

Name Type Description Default
m_0 ArrayLike

Initial mean, shape [D].

required
P_0_sqr ArrayLike

Initial square-root covariance, shape [D, D].

required
prior BasePrior

Gauss-Markov prior (plain or preconditioned) carrying the diffusion scale.

required
measure MeasurementModel

ODE-information model.

required
ts ArrayLike

Time grid, shape [N + 1].

required
linearization Literal['taylor', 'slr']

"taylor" (IEKS) or "slr" (IPLS).

'taylor'
n_iters int

Number of passes (>= 0; >= 1 with init).

3
init ArrayLike | None

Warm start: the means at nodes 1..N to linearize at first, shape [N, D]. Skips the one-shot filter.

None
init_P_sqr ArrayLike | None

With linearization="slr" and init: the square-root covariances at nodes 1..N, shape [N, D, D]. Not accepted for Taylor.

None
obs_model ObsModel | None

Data for the same grid, from prepare_observations.

None
measurements Sequence[Measurement] | None

The data as Measurement objects, in place of obs_model (see gaussian_filter).

None
rule QuadratureRule

Quadrature rule for "slr".

'gauss_hermite'
n_nodes int

Gauss-Hermite nodes per dimension for "slr".

4
diagnostics Callable[[IterationState], Any] | None

Optional traceable IterationState -> PyTree, called in every pass; its outputs are stacked in result.diagnostics.

None
checkpoint bool

Wrap each filter step, of the one-shot filter and of every pass, in jax.checkpoint (see gaussian_filter).

False

Returns:

Type Description
IteratedSmootherResult

An IteratedSmootherResult.

Raises:

Type Description
ValueError

For an unknown linearization, n_iters < 0, init with n_iters=0, an inconsistent init / init_P_sqr, an obs_model built for another grid, or both obs_model and measurements.

IteratedSmootherResult

Bases: NamedTuple

Result of iterated_smoother.

Attributes:

Name Type Description
t Array

The nodes of the solve: the grid, shape [N + 1], or the timeline of data with data-only nodes, shape [E + 1].

m Array

Smoothed means of the final pass at t, shape [N + 1, D] ([E + 1, D] on a timeline).

P_sqr Array

Smoothed square-root covariances of the final pass.

filter FilterResult

FilterResult of the final pass.

surrogate AffineSurrogate | None

The linearization the final pass used (None when n_iters == 0, where the one-shot filter linearized online).

n_iters int

Number of passes.

step Array

RMS change of the smoothed means at grid nodes 1..N in each pass, shape [n_iters]: a convergence diagnostic.

diagnostics Any

The diagnostics outputs of each pass, stacked along a leading axis of length n_iters (None without a callable).

IterationState

Bases: NamedTuple

What one pass of iterated_smoother produced (passed to diagnostics).

Attributes:

Name Type Description
surrogate AffineSurrogate

The linearization of the pass.

filter_result FilterResult

Its filter result.

m_smooth Array

Its smoothed means at the nodes of the solve, shape [N + 1, D], or [E + 1, D] on the timeline of data with data-only nodes.

P_smooth_sqr Array

Its smoothed square-root covariances.

previous_point Array

The means it linearized at (grid nodes 1..N).

The filter step

The step every solver is built from, for building new drivers.

filter_step

filter_step(
    x: Gaussian,
    transition: Transition,
    information: Information,
    *,
    t: ArrayLike,
    calibration: Calibration,
    scale_noise: Callable[[Array, Array], Array],
    observation: AffineModel | None = None,
    mask: Array | None = None,
) -> StepOutput

One step: calibrate, predict, update on the information, observe.

Parameters:

Name Type Description Default
x Gaussian

The state at the previous node.

required
transition Transition

The prior's transition over the step.

required
information Information

The ODE information of the step.

required
t ArrayLike

The time of the step's update (the next node).

required
calibration Calibration

Diffusion calibration policy.

required
scale_noise Callable[[Array, Array], Array]

Applies a diffusion to the prior's noise (prior.apply_state_sigma_sqr).

required
observation AffineModel | None

The step's data model, or None for none.

None
mask Array | None

Which rows of observation carry data.

None

Returns:

Type Description
StepOutput

The step's StepOutput.

estimate_diffusion

estimate_diffusion(
    x: Gaussian,
    transition: Transition,
    information: Information,
    *,
    t: ArrayLike,
    calibration: Calibration,
) -> tuple[Array, Array, AffineModel]

The diffusion of a step, from the ODE residual at its predicted mean.

The diffusion is estimated before the predicted covariance exists, from the information linearized at the predicted mean A m + b; the ODE rows alone drive it.

Parameters:

Name Type Description Default
x Gaussian

The state at the start of the step.

required
transition Transition

The prior's transition over the step.

required
information Information

The ODE information at the end of the step.

required
t ArrayLike

The time at the end of the step.

required
calibration Calibration

Diffusion calibration policy.

required

Returns:

Type Description
Array

(sigma_sqr, diffusion, model): the estimate, the diffusion to

Array

propagate with, and the information linearized at the predicted mean.

StepOutput

Bases: NamedTuple

Everything one filter step produces (original coordinates).

Attributes:

Name Type Description
predicted Gaussian

The prediction p(x_{n+1} | data up to t_n).

backward Conditional

The backward conditional p(x_n | x_{n+1}).

innovation Gaussian

Predictive distribution of the ODE-information residual.

filtered Gaussian

The updated state at t_{n+1}.

sigma_sqr Array

The diffusion estimate of the step.

diffusion Array

The diffusion the step propagated with: sigma_sqr under a scaling policy, one under NoCalibration.

log_likelihood Array

The ODE-information evidence of the step.

innovation_obs Gaussian | None

Predictive distribution of the data residual (None without data). Rows without data at this step have zero mean and unit variance, so they add nothing to the whitened residual.

log_likelihood_obs Array | None

The data evidence of the step (None without data; zero at a step without data).

predict

predict(
    x: Gaussian, transition: Transition
) -> tuple[Gaussian, Conditional]

Prediction and backward conditional of one transition.

For a preconditioned transition both are computed in its coordinates and returned in the original ones.

observe

observe(
    x: Gaussian, model: AffineModel, mask: Array
) -> tuple[Gaussian, Gaussian, Array]

Condition on the data rows of model that mask marks as present.

A row without data is replaced by an exact observation of zero with unit noise and a zero row in H: it leaves the state unchanged, its innovation is N(0, 1) and uncorrelated with the other rows, and its log-density -log(2 pi) / 2 is removed from the evidence.

Parameters:

Name Type Description Default
x Gaussian

The state before the data.

required
model AffineModel

The observation model of the step (c = -y).

required
mask Array

Boolean, one entry per row of model.

required

Returns:

Type Description
tuple[Gaussian, Gaussian, Array]

(posterior, innovation, log_likelihood).

Step-size control

See Adaptive step-size control.

StepSizeController

Bases: Protocol

Duck-typed interface for step-size controllers.

The adaptive solvers call propose after every attempted step, from inside jax tracing in the jittable solver, so it must be written with jax.numpy (no float() / Python min / max on its inputs).

err_prev is the normalised error of the previously accepted step. The absence of that memory (first step, or right after a reject) is signalled by None or, inside traced code, by a non-positive value.

propose

propose(
    h: ArrayLike, err: ArrayLike, err_prev: ArrayLike | None
) -> Array

Return the proposed next step size.

PController dataclass

PController(
    order: int,
    safety: float = 0.9,
    alpha: float | None = None,
    min_factor: float = 0.2,
    max_factor: float = 5.0,
)

Proportional (single-error) step-size controller.

The proposed step is

h_new = h * safety * err^(-alpha)

clipped to [min_factor, max_factor] * h. The previous error is ignored, so this controller has no memory.

Default alpha = 1 / order matches the standard "I-controller" of Hairer-Wanner-Norsett (1993) and the elementary controller in scipy's solve_ivp. For an EK1 filter with an IWP(q) prior, order = q.

Parameters:

Name Type Description Default
order int

Convergence order of the local error estimate.

required
safety float

Safety factor on the proposed step.

0.9
alpha float | None

Gain on the current error; defaults to 1.0 / order.

None
min_factor float

Lower clip on h_new / h.

0.2
max_factor float

Upper clip on h_new / h.

5.0

propose

propose(
    h: ArrayLike,
    err: ArrayLike,
    err_prev: ArrayLike | None = None,
) -> Array

Return the next proposed step size.

Parameters:

Name Type Description Default
h ArrayLike

Current step size.

required
err ArrayLike

Normalised error of the current step (1.0 = at tolerance).

required
err_prev ArrayLike | None

Ignored; accepted for protocol compatibility with PIController.

None

PIController dataclass

PIController(
    order: int,
    safety: float = 0.9,
    alpha: float | None = None,
    beta: float | None = None,
    min_factor: float = 0.2,
    max_factor: float = 5.0,
)

Gustafsson-style proportional-integral controller.

The proposed step is

h_new = h * safety * err^(-alpha) * (err_prev / err)^(beta)

clipped to [min_factor, max_factor] * h. When err_prev is unknown (e.g. on the first step or right after a reject) the I-term is dropped and the update reduces to the PController form h_new = h * safety * err^(-alpha).

Defaults follow Gustafsson (1991): alpha = 0.7 / order, beta = 0.4 / order, which are also the values used in Bosch et al. (2021). For an EK1 filter with an IWP(q) prior, order = q.

Parameters:

Name Type Description Default
order int

Convergence order of the local error estimate.

required
safety float

Safety factor on the proposed step.

0.9
alpha float | None

Proportional gain; defaults to 0.7 / order.

None
beta float | None

Integral gain; defaults to 0.4 / order. beta=0 gives a proportional controller. PController is the standalone equivalent, with the default alpha = 1 / order of the elementary controller instead of 0.7 / order.

None
min_factor float

Lower clip on h_new / h.

0.2
max_factor float

Upper clip on h_new / h.

5.0

propose

propose(
    h: ArrayLike, err: ArrayLike, err_prev: ArrayLike | None
) -> Array

Return the next proposed step size.

Parameters:

Name Type Description Default
h ArrayLike

Current step size.

required
err ArrayLike

Normalised error of the current step (1.0 = at tolerance).

required
err_prev ArrayLike | None

Normalised error of the previously accepted step, or None (or a non-positive value, inside traced code) if unavailable.

required