Dynamic Variational Inference

Statistics
Introduced by
Bayer, Osendorfer, Krishnan and colleagues
Year
2014–2015
Type
Bayesian approximate inference
Family
Bayesian / computational

What does it do?

Dynamic variational inference applies variational inference to sequential latent variable models.

It specifies a Markovian generative model in which latent states evolve over time, together with a recognition network that defines an approximate posterior over the whole latent sequence given the observations. Both sets of parameters are learned by maximising a sequential evidence lower bound (ELBO).

The intuition behind the method

Suppose the hidden state of a system, such as a latent volatility, a disease trajectory or a robot's position, must be inferred from noisy observations at each time step. A naive factorised approximation treats each time step's latent variable separately and has no built-in account of how states follow one another. Dynamic variational inference keeps the time ordering: the approximate posterior for each state is conditioned on the previous state and on the observations from that time onward, so later data can inform earlier states. This is loosely analogous to what a Kalman smoother does in the linear Gaussian case, but the dynamics and the posterior are learned rather than fixed in closed form.

History

Bayer and Osendorfer (2014) describe stochastic recurrent networks that combine recurrent neural networks with latent variables. Krishnan, Shalit and Sontag (2015) present the Deep Kalman Filter, which relates such models to classical state-space structure.

When to use it

Choose dynamic variational inference when observations arrive as sequences, you have reason to believe the latent states evolve in a Markov-type way, and you need posterior inference that scales to many long sequences or to repeated inference on new sequences. It suits settings such as longitudinal measurements or sensor streams, where non-linear transition and emission models are plausible. Do not use it when the latent dynamics are unlikely to be Markovian at the level you model, or when you need a posterior whose approximation error can be assessed directly, because the recognition network is a learned approximation whose error the bound does not measure precisely. If the model is linear and Gaussian, a Kalman filter or smoother gives exact posteriors and is usually preferable. When the number of sequences is small and asymptotically consistent inference matters more than speed, sequential Monte Carlo is the more defensible choice.

Limitations and considerations

  • The ELBO is a lower bound on the log marginal likelihood. The size of the gap depends on how well q can match the true posterior over the whole latent sequence, and the bound does not reveal that gap.
  • When q is restricted to a factorised or partly factorised family, it tends to underestimate posterior uncertainty, particularly when latent states are strongly correlated across time.
  • Results depend on the chosen transition and emission architectures. An overly flexible generative model can explain the data without using the latent dynamics, while an overly weak one cannot capture the temporal structure.
  • Gradient-based training of the joint objective can be unstable, and KL weighting or initialisation schedules are often needed to keep the latent variables in use.

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

Strengths

  • The recognition network is conditioned on the previous latent state and on the remaining observations, so the posterior for each state uses future data as well as past data rather than filtering forward only.
  • Stochastic gradient training on mini-batches of sequences keeps the cost manageable where full-sequence iterative inference would be expensive.
  • The amortised encoder gives a posterior for a new sequence in one forward pass, with no per-sequence optimisation.
  • Transition and emission densities can be non-linear and non-Gaussian, because their form is chosen by the modeller and not restricted by the inference algorithm.
  • A single scalar objective, the ELBO, trains the generative and recognition parameters jointly.

Applications

  • Estimating unobserved health states from longitudinal patient measurements, where the state is assumed to evolve Markov-like between visits.
  • Filtering hidden states from sensor streams, such as robot pose or vehicle dynamics, where each observation depends on the current state.
  • Learning stochastic dynamics of sequences, such as speech or video frames, in which a latent state per time step drives the observed signal.
  • Inferring regime or volatility states in financial return series under a Markov transition assumption.

How it works

How it works

1

The model is Markovian: each latent state z_t depends only on z_{t-1} through a transition density, and each observation x_t depends only on z_t through an emission density. The product of these densities defines the joint distribution over the full sequence. The same product is the prior p(z_{1:T}) that appears in the KL term of the ELBO.

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

The recognition network defines q over the latent sequence as a product of conditionals, each depending on the previous latent state and on the observations from time t onward. Sequence encoders, such as recurrent networks run in both directions, are a common way to produce the parameters of each conditional. A Gaussian form for each conditional is a modelling choice rather than something the factorisation requires.

Formula
q(\mathbf{z}_{1:T} \mid \mathbf{x}_{1:T}) = \prod_{t=1}^T q(\mathbf{z}_t \mid \mathbf{z}_{t-1}, \mathbf{x}_{t:T})
3

The bound has two parts: the expected log-likelihood of the observations under q, which rewards latent sequences that explain the data, and the KL divergence between q and the Markov prior, which penalises posteriors that depart from the assumed dynamics. Maximising the bound moves q closer to the true posterior, but the remaining gap cannot be read off from the bound alone. ELBO values are comparable only between models that share the same recognition family and are evaluated on the same held-out data. A higher ELBO does not by itself guarantee a better posterior, because the gap to the log-likelihood can differ between recognition families.

Formula
\mathcal{L} = \mathbb{E}_{q}[\log p(\mathbf{x}_{1:T} \mid \mathbf{z}_{1:T})] - \mathrm{KL}[q(\mathbf{z}_{1:T} \mid \mathbf{x}_{1:T}) \| p(\mathbf{z}_{1:T})]
4

Samples from q are written as deterministic transformations of the encoder outputs and independent noise, so the gradient of the bound can be propagated through the sampled latent states to both the encoder and the generative parameters. Because the states are sampled in sequence, the transformation must respect the conditional structure of q at each time step.

5

Encoder and generative parameters are updated jointly by stochastic gradient ascent on the ELBO, usually using mini-batches of sequences. Once trained, the recognition network gives an approximate posterior for a new sequence in a single forward pass, without running a separate iterative inference procedure for each sequence.

Common pitfalls

  • Posterior collapse: the recognition network ignores the observations and q approaches the prior. Track the reconstruction term and the KL per time step separately to detect it.
  • Reporting the ELBO as if it were the log-likelihood. It is a lower bound, so comparisons based on it are only as reliable as the gap is small.
  • Using a Markov transition when the data show longer-range dependence. The generative prior then misrepresents the dynamics, and the posterior inherits that bias.
  • Evaluating only on training sequences. Held-out sequences and posterior predictive checks are needed to detect overfitting of the recognition network.

Frequently asked questions

How does dynamic variational inference differ from a Kalman filter?

The Kalman filter assumes linear dynamics and Gaussian noise, and under those assumptions it gives exact posteriors. Dynamic variational inference allows non-linear, non-Gaussian transitions and emissions, and it learns them with a neural recognition network. The cost is an approximation error that the ELBO bounds but does not measure precisely.

What is posterior collapse and how can I prevent it?

Posterior collapse occurs when the recognition network outputs a posterior very close to the prior, so the data have little influence on the latent states. Mitigation strategies include KL annealing (gradually increasing the KL weight during training), a free-bits heuristic that keeps a minimum KL per latent dimension, and monitoring the reconstruction loss separately from the KL term.

Can I use dynamic variational inference with missing observations?

Yes. The reconstruction term can be restricted to the observed time steps, while the latent dynamics still propagate uncertainty across the gap. How well the recognition network handles irregular or missing sampling depends on its architecture, so this should be checked on held-out data.

When should I prefer sequential Monte Carlo over dynamic variational inference?

Sequential Monte Carlo (particle filtering) gives asymptotically consistent posterior approximations and is better suited when the quality of the ELBO approximation is unknown or insufficient. Dynamic variational inference is preferable when sequence datasets are large, speed is critical, or amortised inference across many sequences is needed.

Is a GPU required for practical use?

Not strictly. Training relies on backpropagation through sequences, which becomes very slow on a CPU for non-trivial sequence lengths or dataset sizes, so GPU acceleration is strongly recommended for research-scale applications.

Related methods

Sources

  1. Krishnan, R. G., Shalit, U., & Sontag, D. (2015). Deep Kalman Filters. NIPS 2015 Workshop on Advances in Approximate Bayesian Inference.

    Open publication reference
  2. Bayer, J., & Osendorfer, C. (2014). Learning Stochastic Recurrent Networks. NIPS 2014 Workshop on Advances in Variational Inference.

    Open publication reference