# Examples


<a href="../../docs/examples/arma.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/arma.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


ARMA(1,1) Model


Simulate an ARMA(1,1) process, recover its parameters with NUTS, and evaluate the forecasts with expanding-window cross-validation.


<a href="../../docs/examples/availability_tsb.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/availability_tsb.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


TSB with Availability Constraints for Intermittent Demand


Availability-aware TSB method for intermittent demand. Gating the demand-probability update with a stock availability mask separates true demand from stock-outs, with SVI on a 1,000-series panel and full-availability scenario forecasts.


<a href="../../docs/examples/censored_demand.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/censored_demand.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Demand Forecasting with Censored Likelihood


Demand forecasting when observed sales are censored by stockouts and a capacity cap. An AR(2) model with weekly seasonality whose likelihood mixes the Normal density below the cap with the survival mass at it, fit with NUTS and compared against a naive Normal model on recovering true demand.


<a href="../../docs/examples/croston.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/croston.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Croston's Method for Intermittent Demand


Bayesian Croston method for intermittent demand, with masked exponential smoothing of demand sizes and intervals, NUTS inference, and one-step-ahead cross-validation.


<a href="../../docs/examples/dynestyx_getting_started.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/dynestyx_getting_started.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Getting Started with `dynestyx` State Space Models


Write dynestyx state space models with the state_space building block, integrate a local level out with a Kalman filter, export the in-sample predictive with to_datatree, sample the level explicitly for Student-T noise, fit through a gap of missing observations, and write ARMA(1,1) as a state space model.


<a href="../../docs/examples/dynestyx_integration.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/dynestyx_integration.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


State Space Models with `dynestyx` and `numpyro_forecast`


Write a dynestyx state space model as a plain numpyro_forecast model, choose the inference strategy with a dynestyx handler (Kalman smoother or explicit latent path), and reuse the forecasting, in-sample and backtesting workflow of the package unchanged.


<a href="../../docs/examples/electricity_forecast.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/electricity_forecast.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Electricity demand forecasting


Forecast hourly electricity demand in Victoria, Australia with a varying-coefficient temperature effect built from a Hilbert space Gaussian process, hour-of-day and day-of-week seasonality, and a Student-t likelihood fit with SVI.


<a href="../../docs/examples/electricity_forecast_calibration.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/electricity_forecast_calibration.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Electricity demand forecasting: prior calibration


Calibrate the priors of the electricity demand model against domain knowledge about the temperature effect, iterating with prior predictive checks before refitting.


<a href="../../docs/examples/exponential_smoothing_state_space.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/exponential_smoothing_state_space.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Exponential Smoothing in State Space Form


Write seasonal damped-trend exponential smoothing in innovations state space form so forecast uncertainty is propagated correctly, and fit it with Hamiltonian Monte Carlo.


<a href="../../docs/examples/forecasting_univariate.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/forecasting_univariate.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Univariate forecasting


Forecast weekly BART ridership with a random-walk local level, Fourier seasonality, and a Student-t likelihood fit with SVI, then evaluate the model with rolling-origin backtesting.


<a href="../../docs/examples/fresh_retail_stockout.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/fresh_retail_stockout.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Forecasting retail demand under stockouts


Forecast 1,000 daily store-product demand series from FreshRetailNet-50K with a damped-trend panel model, store-pooled promotion effects, a launch indicator, and a floored saturating availability factor that handles noisy stockout labels, fit with SVI and a custom optax optimizer, ending with a full-availability counterfactual forecast of uncensored demand for planning.


<a href="../../docs/examples/hierarchical_forecasting_1.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/hierarchical_forecasting_1.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Hierarchical forecasting I


Forecast hourly BART arrivals across 50 origin stations to a fixed destination with a hierarchical model that pools information across series, fit with SVI.


<a href="../../docs/examples/hierarchical_forecasting_2.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/hierarchical_forecasting_2.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Hierarchical forecasting II


Scale the hierarchical model to the full 50 by 50 origin-destination panel of hourly BART ridership, forecasting all 2,500 series jointly with SVI.


<a href="../../docs/examples/inference_methods_comparison.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/inference_methods_comparison.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Comparing inference methods: NUTS, SVI, Pathfinder, and MCLMC


Fit the same weekly BART ridership model with NUTS, SVI, Pathfinder, and MCLMC without touching the model code, and compare their forecasts with CRPS.


<a href="../../docs/examples/m5_forecasting.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/m5_forecasting.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


M5 forecasting: top-down, bottom-up and middle-out


Port the three models of the Pyro M5 starter kit (top-down, bottom-up and middle-out) to the full M5 Walmart data, fit them with SVI, backtest them at the twelve hierarchy levels with a weighted scaled CRPS and compare their fitting times.


<a href="../../docs/examples/m5_hierarchical_state_space.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/m5_hierarchical_state_space.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


M5 forecasting II: a hierarchical count state space model


A hierarchical negative binomial state space model of all 30,490 M5 series, trained with minibatch SVI and scored at the twelve hierarchy levels with a weighted scaled CRPS against the Pyro starter kit baseline.


<a href="../../docs/examples/tsb.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/tsb.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


TSB Method for Intermittent Demand


Bayesian TSB method for intermittent demand: masked exponential smoothing of demand sizes and a per-period demand probability, so the forecast decays during zero-runs where Croston's stays frozen. NUTS inference and one-step-ahead cross-validation.


<a href="../../docs/examples/var.html" class="section-card" style="display: block; padding: 1.25rem 1.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; color: inherit; text-decoration: none;"><img src="thumbnails/var.png" class="section-card-img" style="width: 100%; border-radius: 0.375rem; margin-bottom: 0.75rem;" /></a>


Vector Autoregression (VAR)


Fit a Bayesian VAR(2) to US macroeconomic growth rates with NUTS, forecast 30 quarters ahead, compute impulse response functions, and compare a weakly informative prior with Minnesota shrinkage.
