Time Series Variational Inference

Statistics
Introduced by
Jordan, Ghahramani, Jaakkola, Saul; extended by Blei and colleagues
Year
1999–2017
Type
Approximate Bayesian inference
Family
Bayesian / computational

What does it do?

Time series variational inference applies variational Bayes to sequential data.

It approximates the intractable posterior over latent states with a tractable family of distributions, found by maximising the evidence lower bound (ELBO). The approach targets state-space models, dynamic latent variable models and other time-ordered probabilistic systems where sampling-based inference is slow.

The intuition behind the method

In a time series model, the joint posterior over hidden states at all time points usually cannot be computed exactly. Variational inference turns the problem into optimisation: choose a family of distributions that is tractable to work with, then find the member closest to the true posterior, with closeness measured by KL divergence. Maximising the ELBO is equivalent to minimising the KL divergence from the approximation to the true posterior. The result is an approximate posterior over the state trajectory that can be computed in reasonable time even for long sequences, though its accuracy depends on how well the chosen family matches the true posterior.

History

Jordan, Ghahramani, Jaakkola and Saul (1999) gave an introduction to variational methods for graphical models, the general framework on which variational inference for latent-variable models rests. Blei, Kucukelbir and McAuliffe (2017) reviewed variational inference for statisticians, covering mean-field methods, exponential-family models and stochastic optimisation for large datasets, and noted that it tends to be faster than classical methods such as Markov chain Monte Carlo sampling. Applications to sequential latent-variable models build on this general framework.

When to use it

Choose time series variational inference when you have a probabilistic generative model for sequential data and MCMC is too slow for the problem, for example with long series, large datasets or high-dimensional latent spaces. It suits online or streaming settings and models embedded in a deep learning pipeline, such as variational autoencoders or neural state-space models. Prefer sequential Monte Carlo or particle MCMC when accurate posterior coverage matters more than speed, when the dataset is small enough for these methods to be feasible, or when the variational family is likely to be too restrictive for multimodal or strongly non-Gaussian posteriors.

Limitations and considerations

  • The variational posterior is only an approximation; the ELBO can be loose when the chosen family is misspecified.
  • Mean-field variants underestimate posterior variance and fail to capture temporal correlations between latent states.
  • Convergence to a local optimum of the ELBO is not guaranteed; results depend on initialisation and learning-rate choices.
  • Model comparison via ELBO is a lower bound on marginal likelihood and may not rank models correctly.
  • Stochastic ELBO optimisation with reparameterised gradients requires continuous latent variables; discrete latent states need other gradient estimators.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Scales to long sequences and large datasets, where MCMC sampling can become prohibitively slow.
  • The ELBO is a single scalar objective that can be monitored during optimisation to check that the optimiser has stopped improving. A plateau does not guarantee that the approximation is accurate, so compare against posterior predictive checks or an MCMC/SMC benchmark on a small dataset.
  • Works with deep learning components: inference networks and generative networks can be trained jointly by gradient ascent on the ELBO.
  • Gives analytic or sample-based approximate uncertainty over hidden states and forecasts.
  • Amortised variants use an inference network, so new sequences can be processed without re-optimising for each one.

Applications

  • Learning latent dynamics in financial time series and volatility modelling.
  • Approximate state estimation in nonlinear state-space models where the Kalman filter is inapplicable.
  • Training variational recurrent neural networks and neural state-space models for sequence generation.
  • Bayesian changepoint detection and regime-switching models in long time series.
  • Epidemiological surveillance: inferring latent infection dynamics from noisy reported counts.
  • Sensor fusion and tracking problems with missing or irregularly sampled observations.

How it works

How it works

1

The generative model is a state-space (or more general latent-variable) structure: latent states z evolve through a transition model and emit observations y at each time step. The joint distribution over latent states and observations factors across time, which is what allows structured approximations to follow the temporal dependence.

Formula
p(\mathbf{y}_{1:T}, \mathbf{z}_{1:T}) = p(\mathbf{z}_1)\prod_{t=2}^{T}p(\mathbf{z}_t|\mathbf{z}_{t-1})\prod_{t=1}^{T}p(\mathbf{y}_t|\mathbf{z}_t)
2

A variational family q(z_{1:T}) is chosen to approximate the joint posterior over the latent states. The simplest choice is the mean-field family, which factorises across time steps: q(z_{1:T}) = ∏_{t=1}^{T} q_t(z_t). It is easy to optimise but ignores temporal correlation between states. A structured family keeps some of that dependence, for example a Markov-chain factorisation q(z_{1:T}) = q(z_1) ∏_{t=2}^{T} q(z_t | z_{t-1}). The family must be rich enough to represent the main features of the posterior and simple enough that its expectations can be computed or estimated.

Formula
q(\mathbf{z}_{1:T}) \approx p(\mathbf{z}_{1:T}|\mathbf{y}_{1:T})
3

The ELBO is the expected log joint minus the expected log of the variational distribution, and it lower-bounds the log marginal likelihood log p(y). The gap between the two equals the KL divergence from q to the true posterior, so maximising the bound tightens the approximation. When latent variables are continuous, reparameterised gradients allow the ELBO to be optimised stochastically on large datasets. This requires latent variables that can be written as differentiable transformations of a fixed base noise distribution. Discrete latent states need other gradient estimators, such as score-function estimators, or marginalisation where the model allows it.

Formula
\mathcal{L}(q) = \mathbb{E}_q[\log p(\mathbf{y},\mathbf{z})] - \mathbb{E}_q[\log q(\mathbf{z})] \leq \log p(\mathbf{y})
4

The ELBO is maximised using gradient ascent, typically Adam or a similar adaptive optimiser, run until convergence. For amortised VI, an inference network (encoder) maps observed sequences directly to variational parameters, enabling fast inference on new sequences without re-optimisation.

Formula
q^* = \arg\max_q \mathcal{L}(q)
5

After convergence, the optimised q gives approximate marginal posteriors for each latent state in the sequence, and for model parameters only if they are included among the latent variables. Posterior means serve as point estimates, and credible intervals are read from the variational distribution; these can understate uncertainty when the family is restrictive. Forecasts are produced by propagating the approximate posterior through the transition and emission model.

Common pitfalls

  • Selecting an overly restrictive variational family (e.g. independent Gaussians per time step) that cannot represent the true posterior structure.
  • Reporting variational credible intervals as if they were exact Bayesian posteriors without acknowledging the approximation gap.
  • Stopping optimisation prematurely before the ELBO plateaus, yielding a poor approximation.
  • Neglecting to validate the model with posterior predictive checks on held-out segments of the time series.

Frequently asked questions

How is time series variational inference different from the Kalman filter?

The Kalman filter computes the exact posterior for linear Gaussian state-space models, so approximate inference is not needed there. Variational inference is designed for models where that exactness no longer holds, such as nonlinear or non-Gaussian dynamics.

What is the ELBO and why is it maximised instead of the marginal likelihood?

The evidence lower bound (ELBO) is a tractable surrogate for the intractable log marginal likelihood log p(y). Maximising the ELBO is equivalent to minimising the KL divergence between the variational distribution and the true posterior. The gap between the ELBO and the true log-evidence equals this KL divergence and is always non-negative.

Can variational inference give wrong uncertainty estimates?

Yes. Standard VI minimises the reverse KL divergence KL(q||p), which is what maximising the ELBO does. Because of this direction, the variational posterior tends to underestimate variance and may concentrate on one mode of a multimodal posterior. Always check with posterior predictive checks and, where feasible, compare against an MCMC benchmark on a small dataset.

When should I prefer sequential Monte Carlo over variational inference for time series?

Sequential Monte Carlo (particle filters/smoothers) provides asymptotically exact posterior samples and handles highly nonlinear or non-Gaussian dynamics without approximation bias. Prefer SMC when the dataset is small to moderate, when exact uncertainty quantification is critical, or when the variational family cannot be made flexible enough. Use VI when scalability and speed are paramount.

What software implements time series variational inference?

Several probabilistic programming systems implement variational inference for user-defined generative models, including Stan and the Python-based Pyro and NumPyro. Check the documentation of your chosen tool for which variational families it supports and how custom structured approximations for state-space models are specified.

Related methods

Sources

  1. Blei, D. M., Kucukelbir, A. & McAuliffe, J. D. (2017). Variational inference: A review for statisticians. Journal of the American Statistical Association, 112(518), 859-877.

    Open DOI reference
  2. Jordan, M. I., Ghahramani, Z., Jaakkola, T. S. & Saul, L. K. (1999). An introduction to variational methods for graphical models. Machine Learning, 37(2), 183-233.

    Open DOI reference