Skip to main content

surgery.prefix_condition()

Condition a (t+f)-length distribution on a t-length data prefix.

Usage

Source

surgery.prefix_condition(
    noise_dist,
    data,
)

For independent-over-time noise (the elementwise default) the conditional reduces to the forecast-horizon marginal, i.e. a time slice [t:]. Only registered elementwise families take this path; correlated families (e.g. MultivariateNormal) need a dedicated dispatch implementing a genuine Gaussian conditional, which is checked here rather than silently reduced to a slice (the R1 fix). An Independent wrapper (e.g. from .to_event(1)) conditions its base distribution and keeps its reinterpreted_batch_ndims, so wrapping does not change the conditional. A MultivariateNormal over time keeps its layout: the event (time, 1) returned by shift_loc() gives a conditional with event (f, 1), and a bare (time,) event gives (f,). Its conditional factors the full covariance once, after adding 10^{-6} (float32) or 10^{-8} (float64) times the variance of each time step to the diagonal. The jitter is relative, so the result does not depend on the scale of the covariance, overall or per time step, but it still inflates a forecast variance that is far below the marginal variance: for a smooth kernel, the jitter rather than the kernel can set the one-step forecast variance. Every MultivariateNormal event is read as time, so one across the series of a panel is not supported (see shift_loc()).

Parameters

noise_dist: dist.Distribution

The observation distribution over the full horizon (*batch, t+f, obs).

data: Array
The observed prefix with shape (*batch, t, obs).

Returns

dist.Distribution
The forecast-horizon distribution over (*batch, f, obs).

Raises

NotImplementedError
If noise_dist (or the base of an Independent wrapper) is not a registered elementwise family (and has no dedicated dispatch).