Approximate Bayesian Inference in Linear State Space Models for Intermittent Demand Forecasting at Scale

Matthias W. Seeger, Syama Sundar Rangapuram, Yuyang Wang, David Salinas, Jan Gasthaus, Tim Januschowski, Valentin FlunkertarXiv 2017

Abstract

We present a scalable and robust Bayesian inference method for linear state space models. The method is applied to demand forecasting in the context of a large e-commerce platform, paying special attention to intermittent and bursty target statistics. Inference is approximated by the Newton-Raphson algorithm, reduced to linear-time Kalman smoothing, which allows us to operate on several orders of magnitude larger problems than previous related work. In a study on large real-world sales datasets, our method outperforms competing approaches on fast and medium moving items.

Introduction: The Challenge of the Long Tail

In massive e-commerce catalogs, such as Amazon's, the vast majority of products exhibit demand patterns that are difficult to model using traditional statistical methods. These patterns are characterized by being intermittent—long periods with zero sales—and bursty—sudden, unpredictable spikes in volume. Standard forecasting tools like ARIMA or Exponential Smoothing often assume Gaussian noise, which is ill-suited for these distributions. They may predict negative sales or fail to capture the extreme uncertainty inherent in rare events.

Typical intermittent demand time series and its corresponding distribution, showing a heavy concentration at zero and a long tail of bursty demand.

While Bayesian methods are naturally suited to handle non-Gaussian distributions and provide probabilistic forecasts, they have historically been computationally prohibitive at the scale of hundreds of millions of items. The challenge lies in building a system that provides accurate uncertainty quantiles—crucial for inventory decisions—while remaining operationally robust enough to run on millions of items without manual intervention.

Methodology

The proposed framework combines Innovation State Space Models (ISSM) with a Generalized Linear Model (GLM) backbone. The core technical innovations include:

  1. Multi-stage Likelihood: The model decomposes demand into three stages to better capture the zero-inflated nature of the data:
  2. Stage 0: Binary classification of zero vs. non-zero demand (Logistic regression).
  3. Stage 1: Binary classification of exactly one vs. more than one unit (Logistic regression).
  4. Stage 2: Poisson regression for quantities greater than one.
  5. Newton-Raphson via Kalman Smoothing: Finding the posterior mode is framed as a Newton-Raphson optimization. The authors demonstrate that each iteration can be mathematically reduced to a Kalman smoothing pass. This reduction shifts the computational complexity from $O(T^3)$ to $O(T)$, enabling linear-time inference relative to the number of time steps $T$.
  6. Numerical Stability: To prevent numerical overflow during demand bursts (e.g., holidays), a "twice logistic" transfer function is used instead of the standard exponential function. This ensures the model remains log-concave and stable even during extreme spikes.

Bayesian Inference and Parameter Estimation

The Bayesian approach allows for the estimation of posterior distributions for latent states and parameters, providing a principled way to handle uncertainty. This is essential for generating reliable probabilistic forecasts that inform risk-aware inventory management.

Posterior distributions for model parameters l0, b0, and innovation noise (unoise), demonstrating the probabilistic nature of the inference.

By treating periods where items are out-of-stock (OOS) as missing observations, the Bayesian framework avoids the common pitfall of under-biasing demand forecasts during supply gaps. The model maintains its internal state and uncertainty during these periods, leading to more accurate predictions once the item returns to stock.

Experimental Results

The model was evaluated across several datasets, ranging from public spare parts data to massive internal Amazon datasets (EC-all) comprising over 500,000 items and 150 million item-days.

  • Accuracy: The proposed method (LS-feats) consistently outperformed Negative Binomial and Exponential Smoothing (ETS) baselines, particularly in P90 risk metrics, which are vital for avoiding stockouts.
  • Scalability: Implemented in Apache Spark, the system successfully processed hundreds of millions of item-days. Parameter learning for a single item-stage typically took between 0.1 and 3.2 seconds, making it viable for massive production environments.
  • Robustness: The "twice logistic" function prevented the numerical "total failure" seen when using standard exponential transfer functions on bursty real-world data.

Conclusion

This work demonstrates that Bayesian inference for linear state space models can be scaled to massive datasets by leveraging the connection between Newton-Raphson and Kalman smoothing. By combining the strengths of GLMs for feature handling and ISSMs for latent state continuity, the framework provides a robust solution for the "long tail" of e-commerce demand. Future work includes exploring coupled latent processes across related items and incorporating time-dependent innovation variance to better capture volatility during major shopping events.

Summary updated

BibTeX
@misc{seeger2017approximate,
  author = {Matthias W. Seeger and Syama Sundar Rangapuram and Yuyang Wang and David Salinas and Jan Gasthaus and Tim Januschowski and Valentin Flunkert},
  title = {{Approximate Bayesian Inference in Linear State Space Models for Intermittent Demand Forecasting at Scale}},
  year = {2017},
  eprint = {1709.07638},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1709.07638},
}
Figure