The mean-field family assumes the latent variables are mutually independent under q: q(z)=∏j=1mqj(zj). With this family the ELBO can be maximized one factor at a time, and the optimal factor has a closed form: qj∗(zj)∝exp{E−j[logp(zj∣z−j,x)]}, 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
q(z)=j=1∏mqj(zj).
“Each latent variable zj is governed by its own variational factor” (Blei et al., Eq. 15). The family is not a model of the data (x does not appear); the ELBO connects q to the data. The parametric form of each qj 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 q. Both improve fidelity at the cost of a harder optimization (Sec. 2.3).
Optimal coordinate update ^thm-cavi-update
Fix all factors qℓ, ℓ=j. The factor maximizing the ELBO is
which is, up to a constant, −KL(qj∥qj∗). It is maximized by qj=qj∗. Because the right side of the update does not involve qj, this is a valid coordinate step.
CAVI (Blei et al., Algorithm 1) ^alg-cavi
Input: model p(x,z), data x. Output:q(z)=∏jqj(zj).
Initialize the factors qj(zj).
While the ELBO has not converged:
forj∈{1,…,m}: set qj(zj)∝exp{E−j[logp(zj∣z−j,x)]}.
Compute ELBO(q)=E[logp(z,x)]−E[logq(z)].
Returnq(z).
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.
Then qj∗(zj)∝h(zj)exp{E[ηj(z−j,x)]⊤zj}: the optimal factor is in the same exponential family as the complete conditional, with natural parameter
νj=E[ηj(z−j,x)]
(Blei et al., Eqs. 36-40). For conditionally conjugate models with global variables β and local variables zi, p(β,z,x)=p(β)∏ip(zi,xi∣β), this gives the local update φi=Eλ[η(β,xi)] and the global update λ=[α1+∑iEφi[t(zi,xi)],α2+n]⊤ (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 log∑iexi=α+log∑iexi−α with α=maxixi (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 O(1/n), 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 p(z)=N(m,Λ−1) 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 zj,
so qj∗=N(mj−Λjj−1∑k=jΛjk(E[zk]−mk),Λjj−1). The fixed point has E[z]=m (means exact) and
Varq(zj)=Λjj1≤(Λ−1)jj=Varp(zj).
The mean-field variance is the conditional variance of zj given the others, not the marginal variance. For two unit-variance coordinates with correlation ρ, Varq=1−ρ2: at ρ=0.9 the standard deviation is understated by a factor 0.19≈0.44. Kucukelbir et al.’s Fig. 4 reports true variances (0.28,0.31) against mean-field (0.13,0.14), a ratio of about 0.46, which corresponds to ρ≈0.73 under this formula.
Linear regression. With known noise σ2, a flat prior and design columns (1,xi), the posterior precision of (α,β) is Λ=σ−2X⊤X. Hence
Varq(β)=∑ixi2σ2vs.Varp(β)=∑i(xi−xˉ)2σ2,
a ratio of 1−nxˉ2/∑ixi2. For x spread uniformly over [0,10] that ratio is 0.25: 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: μk∼N(0,σ2), ci∼Cat(1/K), xi∣ci,μ∼N(ci⊤μ,1). Family: q(μ,c)=∏kN(μk;mk,sk2)∏iCat(ci;φi), which turns out to be the optimal mean-field form. Updates (Eqs. 26, 34):
The μk update is a “weighted complete conditional, where each data point is weighted by its variational probability of being assigned to component k.”
import numpy as npfrom scipy.special import logsumexpdef 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, K=30) 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.