mixle.inference.forecast module¶
forecast – horizon predictions with honest intervals from a fitted sequence model.
The forecasting front door for state-space families. For a fitted HMM: filter the history to the current state posterior (the forward-backward’s final step), propagate it through the transition matrix, and at each horizon step draw from the exact predictive mixture over states — so the mean, the central interval, and the per-step state probabilities all come from the model itself, for ANY emission family with a sampler (Gaussian, Gamma, categorical, wrapped, neural, …):
f = forecast(hmm, history, horizon=12, level=0.9)
f.mean, f.lo, f.hi # (H,) arrays (or lists for non-scalar emissions)
f.state_probs # (H, S): where the chain is expected to be at each step
Sampling-based on purpose: exact for the state marginals (p_T A^h), Monte Carlo only for the
emission quantiles, so the intervals are honest for arbitrary (skewed / multimodal / discrete)
emission families rather than pretending everything is Gaussian.
- class Forecast(mean, lo, hi, level, state_probs, samples=None)[source]
Bases:
objectPer-step predictive summaries plus the state-marginal trajectory.
- mean: Any
- lo: Any
- hi: Any
- level: float
- state_probs: ndarray
- samples: Any = None
- forecast(model, history, horizon, *, level=0.9, n=4000, seed=0, keep_samples=False)[source]
Forecast
horizonsteps beyondhistoryunder a fitted HMM.- Parameters:
model (Any) – a fitted
HiddenMarkovModelDistribution(any emission family with a sampler).history (Any) – the observed sequence to condition on (one sequence).
horizon (int) – number of future steps to predict.
level (float) – central-interval mass (0.9 -> the 5%..95% band).
n (int) – Monte-Carlo draws per step for the emission quantiles (state marginals are exact).
seed (int) – reproducibility.
keep_samples (bool) – also return the raw
(H, n)predictive draws (scalar emissions only).
- Return type:
Forecast