Mean-Field Family and Coordinate Ascent VI (CAVI)

Summary

The mean-field family assumes the latent variables are mutually independent under : . With this family the ELBO can be maximized one factor at a time, and the optimal factor has a closed form: , the exponentiated expected log complete conditional (Blei et al. 2017, Eq. 17). Iterating this update is coordinate ascent variational inference (CAVI), a deterministic cousin of the Gibbs sampler. The family “can capture any marginal density of the latent variables” but “cannot capture correlation between them,” and under reverse KL this makes it systematically underestimate marginal variances.

Overview

Mean-field CAVI is the classical form of VI and the one to understand first, because every pathology of modern black-box VI is already visible in it. Its strengths are that updates are closed-form for a large class of models (conditionally conjugate exponential families), the ELBO increases monotonically, and there are no step sizes to tune. Its weaknesses are that each new model needs a hand derivation, each sweep touches the whole data set, the optimum is only local, and the independence assumption is wrong for nearly every posterior of applied interest. The first two weaknesses motivate Stochastic and Black-Box Variational Inference; the last motivates full-rank ADVI and flows.

Main Content

Mean-field variational family ^def-mean-field

“Each latent variable is governed by its own variational factor” (Blei et al., Eq. 15). The family is not a model of the data ( does not appear); the ELBO connects to the data. The parametric form of each is not assumed in advance; for many models it is determined by the update below. Generalizations: structured VI adds dependencies between factors; mixture families add latent variables inside . Both improve fidelity at the cost of a harder optimization (Sec. 2.3).

Optimal coordinate update ^thm-cavi-update

Fix all factors , . The factor maximizing the ELBO is

where is the expectation under (Blei et al., Eqs. 17-18).

Proof sketch (Eq. 19). By iterated expectation and the mean-field factorization, as a function of alone

which is, up to a constant, . It is maximized by . Because the right side of the update does not involve , this is a valid coordinate step.

CAVI (Blei et al., Algorithm 1) ^alg-cavi

Input: model , data . Output: .

  1. Initialize the factors .
  2. While the ELBO has not converged:
    • for : set .
    • Compute .
  3. Return .

CAVI “goes uphill on the ELBO… eventually finding a local optimum.”

Relation to Gibbs sampling. The Gibbs sampler “maintains a realization of the latent variables and iteratively samples from each variable’s complete conditional.” CAVI “uses the same complete conditional. It takes the expected log, and uses this quantity to iteratively set each variable’s variational factor” (Sec. 2.4). Any model for which a Gibbs sampler is easy to write is one for which CAVI is easy to derive. CAVI can also be read as variational message passing on the graphical model: each variable’s update depends only on the variational parameters of its Markov blanket, which is what enabled automated software for conjugate-exponential graphs.

Exponential-family complete conditionals ^thm-expfam

Suppose each complete conditional is in an exponential family,

Then : the optimal factor is in the same exponential family as the complete conditional, with natural parameter

(Blei et al., Eqs. 36-40). For conditionally conjugate models with global variables and local variables , , this gives the local update and the global update (Eqs. 47-48). The class includes Bayesian mixtures of exponential families, matrix factorization, some hierarchical linear and probit regressions, stochastic block models and LDA (Sec. 4).

This is the structural reason the global/local split in Hierarchical Models matters computationally: CAVI alternates an “E-like” step over per-unit latents and an “M-like” step over shared parameters, and the global step is what SVI makes stochastic.

Practicalities (Sec. 2.5)

  • Initialization and local optima. “CAVI only guarantees convergence to a local optimum, which can be sensitive to initialization”; ten random starts on a Gaussian mixture give ten different final ELBOs (Fig. 2). For mixtures, many optima are label-switched copies, and “representing one of these modes is sufficient for exploring latent clusters or predicting new observations.” The same symmetry is what defeats HMC on mixtures (Monsters and Mixtures).
  • Convergence. Stop when the ELBO change falls below a threshold. The ELBO trajectory shows “elbows”: plateaus followed by jumps as the approximation changes shape (Fig. 3), so a loose threshold can stop on a plateau.
  • Numerical stability. Work with log probabilities and use with (Eq. 20).

Accuracy

What is known about mean-field accuracy ^thm-mf-accuracy

  • The mean-field optimum for a correlated Gaussian “has the same mean as the original density” but “the marginal variances of the approximation under-represent those of the target density” (Sec. 2.3, Fig. 1).
  • Wang & Titterington (2005, 2006), for Bayesian Gaussian mixtures: CAVI converges to a local optimum, the variational posterior mean is a consistent estimator approaching the MLE at rate , but the asymptotic variational posterior covariance is “too small”, differing from the inverse Fisher information by a positive-definite matrix (Sec. 5.2).
  • You et al. (2014): mean-field posterior means are consistent for the Bayesian linear model with normal / inverse-gamma priors.
  • Giordano et al. (2015) post-process mean-field output to correct the covariance (linear response); see Sec. 5.4.

The pattern: point estimates usually fine, uncertainty too narrow.

Examples

Mean-field fit to a correlated Gaussian ^ex-mf-gaussian

Apply the update to a target with precision matrix (the standard calculation from Bishop 2006, Sec. 10.1.2, which both Blei et al. and Kucukelbir et al. cite for this effect). Keeping terms in ,

so . The fixed point has (means exact) and

The mean-field variance is the conditional variance of given the others, not the marginal variance. For two unit-variance coordinates with correlation , : at the standard deviation is understated by a factor . Kucukelbir et al.’s Fig. 4 reports true variances against mean-field , a ratio of about , which corresponds to under this formula.

Linear regression. With known noise , a flat prior and design columns , the posterior precision of is . Hence

a ratio of . For spread uniformly over that ratio is : the mean-field posterior standard deviation of the slope is half the truth. This is a sufficient mechanism for the slope miscalibration that SBC Case Studies reports for ADVI on a simple linear regression, and it disappears if the predictor is centered, a reparameterization that makes the posterior itself factorize.

CAVI for a Bayesian mixture of Gaussians (Blei et al., Sec. 3, Algorithm 2) ^ex-cavi-gmm

Model: , , . Family: , which turns out to be the optimal mean-field form. Updates (Eqs. 26, 34):

The update is a “weighted complete conditional, where each data point is weighted by its variational probability of being assigned to component .”

import numpy as np
from scipy.special import logsumexp
 
def cavi_gmm(x, K, sigma2=10.0, iters=100, seed=0):
    rng = np.random.default_rng(seed)
    m = rng.normal(x.mean(), x.std(), K); s2 = np.ones(K)
    for _ in range(iters):
        # local step: responsibilities, E[mu]=m, E[mu^2]=m^2+s2
        logphi = np.outer(x, m) - 0.5 * (m**2 + s2)
        phi = np.exp(logphi - logsumexp(logphi, axis=1, keepdims=True))
        # global step: weighted conjugate update
        prec = 1.0 / sigma2 + phi.sum(0)
        m, s2 = (phi * x[:, None]).sum(0) / prec, 1.0 / prec
    return m, s2, phi

On 10,000 image histograms (imageCLEF, 576 dimensions, ) CAVI reaches its held-out predictive plateau “in less than a minute,” orders of magnitude faster than NUTS on the same model (Sec. 3.4, Fig. 6), with the authors’ caveat that this “is not a definitive comparison” since a collapsed Gibbs sampler might do better.

Connections

See Also