- Introduced by
- Ranganath, Altosaar, Tran & Blei
- Year
- 2016
- Type
- Bayesian approximate inference
- Family
- Bayesian / computational
What does it do?
Hierarchical variational inference (HVI) extends standard variational inference by giving the variational family itself a hierarchical structure.
Instead of a simple factored (mean-field) approximation, HVI introduces auxiliary latent variables and defines the approximating distribution as a marginal over them, so the family can represent dependencies among latent variables that a factored family cannot. It is used for approximate posterior inference in complex Bayesian models.
The intuition behind the method
Standard mean-field variational inference approximates the posterior with a product of simple factors, which tends to miss correlations between parameters and can understate posterior uncertainty. HVI adds a layer of auxiliary variables η, so the approximation q(z) is a marginal over conditional distributions q(z | η). That marginal generally has no closed form, so HVI optimises an auxiliary bound that can be computed. The cost is a more involved optimisation with additional structure to specify and tune.
History
Jordan, Ghahramani, Jaakkola and Saul (1999) gave an introduction to variational methods for graphical models, the mean-field framework that HVI extends. Ranganath, Altosaar, Tran and Blei (ICML 2016) introduced hierarchical variational models, which add auxiliary variables to the variational family and derive an auxiliary ELBO for optimisation.
When to use it
Choose HVI when you have a hierarchical Bayesian model whose latent variables are strongly correlated, so that a mean-field approximation visibly fails to match the posterior, and when full MCMC is too slow or memory-intensive for the data at hand. It suits large-scale or end-to-end trainable models with many latent variables, such as deep generative models. Do not use it when a mean-field approximation already passes posterior predictive checks, because HVI adds implementation and tuning cost. When full conditional distributions are tractable, as in many conjugate models, Gibbs sampling gives asymptotically exact draws and can be cheaper; HVI is considered when those conditionals are not tractable.
Limitations and considerations
- More involved to implement and tune than mean-field variational inference, since the auxiliary variables and the auxiliary distribution r(η | z) must be specified.
- The result is still an approximation: maximising the auxiliary objective does not guarantee that q is close to the true posterior.
- Results depend on the learning rate, initialisation and the chosen variational structure, all of which affect the optimisation.
- Cost per iteration is higher than for mean-field VI, because each update involves the auxiliary variables and the auxiliary distribution r(η | z).
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- The variational family can represent dependencies between latent variables that a factored mean-field family cannot.
- The auxiliary objective is optimised with stochastic gradients, so the method can be applied to large datasets and high-dimensional latent spaces.
- Gradients can be obtained with standard automatic differentiation tools, which makes implementation practical in frameworks such as PyTorch or JAX.
- Because it optimises rather than samples, it can be cheaper than MCMC on large datasets, although the comparison depends on the model and the convergence criterion.
Applications
- Deep generative models such as variational autoencoders with correlated latent spaces.
How it works
How it works
Standard variational inference chooses an approximate posterior q(z | λ) by maximising the evidence lower bound (ELBO), which is the expected log joint density E_q[log p(x, z)] minus the expected log density E_q[log q(z | λ)] of the approximation. Maximising it pulls q toward the posterior, while the second term rewards a spread-out q.
Formula
\mathcal{L}(\lambda) = \mathbb{E}_{q}[\log p(x, z)] - \mathbb{E}_{q}[\log q(z \mid \lambda)]HVI replaces the simple variational family with a hierarchical one. Auxiliary variables η are introduced, and q(z) is the marginal obtained by integrating q(z | η) against q(η). Because this marginal is not restricted to a single factored form, it can express dependencies between latent variables that mean-field families cannot. The marginal generally has no closed form, which is why the next step is needed.
Formula
q(z) = \int q(z \mid \eta)\, q(\eta)\, d\eta
Since q(z) cannot be evaluated directly, the bound is written over the joint distribution q(z, η). The auxiliary distribution r(η | z) enters through the term log r(η | z), and the expectation is taken under q(z, η). The auxiliary objective is a lower bound on the ELBO of the marginal hierarchical approximation, and it is tight only when r(η | z) matches the true conditional of η given z. Maximising the auxiliary objective over the variational parameters therefore gives a computable surrogate for the hierarchical objective, and the choice of r governs how close that surrogate is to the hierarchical bound.
Formula
\mathcal{L}_{\text{aux}}(\lambda) = \mathbb{E}_{q(z,\eta)}\left[\log p(x,z) + \log r(\eta \mid z) - \log q(z,\eta)\right]The auxiliary objective is optimised by stochastic gradient ascent, with the expectations estimated from Monte Carlo samples of q(z, η). Reparameterisation or score-function estimators are the usual ways to obtain these gradients. The derivation of the gradient estimator for this objective is given in the original paper by Ranganath et al. (2016), which should be consulted before implementation.
Training is typically stopped when the auxiliary objective ceases to improve, for example when a moving average of successive Monte Carlo estimates levels off. A plateau indicates that the optimiser has settled, which may be a local optimum rather than the true posterior. The fitted parameters then define the approximate posterior used for predictions and uncertainty summaries.
Common pitfalls
- Reading the auxiliary objective as the exact log evidence. It is a surrogate, so approximation quality should be checked with posterior predictive checks.
- Choosing an auxiliary structure too simple to add expressiveness over the mean-field base. The extra layer then adds cost without changing the fit.
- Ignoring gradient variance. Noisy gradient estimates can stall or destabilise training, and reparameterisation or control variates may be needed.
- Mistaking optimiser convergence for convergence to the true posterior. The objective can plateau at a local optimum.
- Overlooking identifiability. Auxiliary variables can introduce redundant parameterisations that slow convergence.
Frequently asked questions
How does hierarchical variational inference differ from standard variational inference?
Standard VI uses a simple factored (mean-field) distribution, which ignores correlations between latent variables. HVI adds auxiliary latent variables to form a richer variational family that can represent such correlations, and it optimises an auxiliary objective to fit that family.
Is hierarchical variational inference the same as inference in a hierarchical Bayesian model?
No. HVI is a method for performing inference (approximately computing the posterior) and can be applied to any model, including hierarchical ones. It refers to the hierarchical structure of the variational family, not the structure of the model being fitted.
When should I prefer HVI over MCMC?
HVI is preferred when datasets are large, when MCMC mixing is prohibitively slow, or when the model is embedded in an end-to-end trainable pipeline. MCMC remains preferable when exact posterior samples are needed, datasets are small, or computational budget is not the constraint.
What software supports hierarchical variational inference?
Custom implementations are commonly written in automatic differentiation frameworks such as PyTorch or JAX. Before relying on a probabilistic programming tool, check its documentation for support of hierarchical variational families and of the auxiliary structure described here.
How do I evaluate whether the HVI approximation is good enough?
Compare the fitted approximation with a mean-field baseline, run posterior predictive checks against held-out data, and where feasible compare posterior summaries with MCMC results on a smaller version of the problem. Large disagreement with the MCMC reference or poor predictive checks indicate that the approximation is still inadequate.
Related methods
Sources
Ranganath, R., Altosaar, J., Tran, D. & Blei, D. M. (2016). Hierarchical Variational Models. Proceedings of the 33rd International Conference on Machine Learning (ICML 2016), PMLR 48, 324-333.
Open publication referenceJordan, 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