Diagnosing Variational Inference (PSIS k-hat and VSBC)

Summary

“While it’s always possible to compute a variational approximation to a posterior distribution, it can be difficult to discover problems with this approximation” (Yao, Vehtari, Simpson & Gelman 2018). The ELBO cannot tell you: it lives on an uninterpretable, parameterization-dependent scale. The paper proposes two complementary checks. PSIS : treat as an importance-sampling proposal for the posterior, fit a generalized Pareto distribution to the largest ratios , and read the shape as a measure of joint discrepancy; good, - usable, unreliable. When is small, the same smoothed weights correct the VI estimate. VSBC: a simulation-based-calibration variant that tests whether VI point estimates are unbiased on average over the prior, via the symmetry of calibration-probability histograms.

Overview

There are two levels of VI diagnostics (Sec. 1). The first is convergence of the optimizer to a local optimum, assessed by monitoring ELBO changes or held-out predictive density. The second, the subject of this note, is whether the converged “is close enough to the true posterior to be used in its place.” VI can be flawed through “slow convergence of the optimization problem, the inability of the approximation family to capture the true posterior, the asymmetry of the true distribution, the fact that the direction of the KL divergence under-penalizes approximation with too-light tails, or all these reasons.”

The two diagnostics answer different questions:

PSIS VSBC
Targetthe joint approximation, for the observed data setmarginal point estimates, averaged over data sets from the prior predictive
Costone VI fit + joint-density evaluations simulated data sets and VI fits
Passing means is a usable importance proposal; VI estimates can be correctedcentre of is unbiased on average (if model is well specified)
Blind tomodes that never visitsfailures specific to the realized data; model misspecification

Main Content

PSIS as a diagnostic

With draws , define ratios and a family of estimators

(Eqs. 2-3). is the plain VI estimate: low variance, biased “to an unknown extent and inconsistent.” is importance sampling: consistent, but with possibly infinite variance, because a reverse-KL “has a lighter tail than as a result of entropy penalization, which lead[s] to a heavy right tail of .”

Pareto smoothed importance sampling ^def-psis

Fit a generalized Pareto distribution to the largest ratios, report the estimated shape , replace those ratios “by their expected value under the fitted generalized Pareto distribution,” leave the rest unchanged, and truncate all weights at the raw maximum. The smoothed weights give lower mean squared error than plain or truncated IS (Sec. 2.1; Vehtari et al. 2017). This is the same PSIS used for leave-one-out cross-validation in Cross Validation Checking, with the variational in place of the full-data posterior as the proposal.

What measures

A generalized Pareto with shape has finite moments up to order , so estimates

where is the Renyi divergence (Eq. 4). Hence:

  • : the divergence is infinite (IS variance infinite);
  • : , “indicating a disastrous VI approximation, despite the fact that is always minimized among the variational family”;
  • : Berry-Esseen gives an even faster approach to normality.

Theoretically always (since is finite), but finite-sample can exceed 1. is invariant to multiplicative constants, which is why the unnormalized suffices.

PSIS diagnostic (Yao et al., Algorithm 1) ^alg-psis-diagnostic

  1. Run VI to obtain ; draw , .
  2. Compute (in practice ).
  3. Fit the generalized Pareto to the largest ; report .
  4. If : is close to the posterior; use PSIS weights to refine estimates. If : “not perfect but still useful”; use PSIS weights. If : unreliable; tune VI (reparameterize, more iterations, larger minibatch, smaller learning rate) or use MCMC.

Invariance (Sec. 2.3). Under a smooth bijection the Jacobians cancel in , so does not depend on the coordinates it is computed in. But a reparameterization that changes the family (e.g. centered vs non-centered, or a different ADVI transform) changes and hence , so “can guide the choice of re-parametrization.”

Marginal is misleading (Proposition 1)

If for some , then for every margin : marginal joint . So joint grows with dimension, which “accurately reflects the quality of the variational approximation to the joint posterior.” Marginal should nonetheless not be used: the true marginal density is unknown, and when VI over-disperses a margin, is small even though the estimate is bad (Sec. 2.4).

VSBC

VSBC marginal diagnostic (Yao et al., Algorithm 2) ^alg-vsbc

For : draw ; simulate of the same size as the real data; run VI to get ; for each margin compute

For each , test whether is symmetric about (histogram, or a Kolmogorov-Smirnov test comparing with ). Rejection means the VI approximation is biased in margin .

This adapts Cook, Gelman & Rubin (2006), the precursor of SBC. Full SBC demands uniform histograms, a test that an approximate method like VI will essentially always fail, as ADVI does in SBC Case Studies. VSBC deliberately weakens the requirement to symmetry, asking only whether the centre is right.

Proposition 2 ^thm-vsbc-symmetry

For a one-dimensional parameter, if both the VI approximation and the true posterior are symmetric and VI is unbiased, , then the distribution of VSBC -values is symmetric. If VI is positively (negatively) biased, the distribution is right (left) skewed.

Reading shape as in Interpreting SBC Histograms: skew indicates bias; a symmetric U-shape indicates under-dispersion; a symmetric hump indicates over-dispersion.

Interpret conservatively: failing VSBC means VI “will not perform well on the model in question”; passing does not guarantee good behaviour on the actual data, and says nothing under misspecification (Sec. 3.2).

Experiments (all mean-field ADVI in Stan)

Four case studies (Sec. 4) ^ex-yao-cases

  1. Linear regression, , , , , VSBC replications. KS test not rejected for (), (); rejected for , which is over-estimated. “The under-estimation of posterior variance is reflected by the U-shaped distributions.” On one data set with relative tolerance , but at the default : “a fake convergence” that catches and the ELBO rule does not (Figs. 1-2).
  2. Logistic regression with design correlation . Posterior correlation rises with , mean-field fits worse, rises. Held-out log predictive density of VI improves with , “misleadingly suggesting better fit”; the discrepancy between VI and true lpd jumps sharply near . First- and second-moment RMSE grow with , and “PSIS adjustment always shrinks the VI estimation errors” (Figs. 3-4).
  3. Eight schools (Hierarchical Models). Centered: joint ; the Gaussian family cannot capture the funnel between and . Here ADVI over-estimates the posterior sd of every : the posterior mode is at , entropy pushes away from it, is over-estimated, and that inflates the . Marginal are “misleadingly small.” Non-centered (): joint , smaller bias in means and sds. VSBC: symmetric; right-skewed (over-estimated) when centered and left-skewed (under-estimated) when non-centered (Figs. 5-6). “VI posteriors can be both over-dispersed and under-dispersed, depending crucially on the true parameter dependencies.”
  4. Regularized-horseshoe logistic regression, leukemia microarray, , . ADVI runs in minutes versus hours for MCMC, but : “not even close.” The Gaussian family misses the right-hand mode of , collapsing the corresponding to a spike at zero; VSBC shows biased down and the global scale biased up to compensate (Figs. 7-8). Compare Regularized Horseshoe (Finnish Horseshoe) and The Horseshoe Prior.

Limitations (Sec. 5)

Both diagnostics are local. If the posterior is and sits on one mode, the ratio is the constant or on the sampled region and : “any divergence measure based on samples from the approximation such as is local.” Remedies: multiple over-dispersed initializations; estimating through PSIS with ; and VSBC itself, which draws truths from the prior and so can land in the missed mode. In practice “a marginal missing mode will typically lead to large joint discrepancy that is still detectable by ,” as in the horseshoe example.

Examples

Computing for a PyMC or Stan VI fit

import numpy as np, arviz as az
 
# theta: (S, K) draws from q in the UNCONSTRAINED space
# logp_joint(theta_s): log p(theta_s, y) incl. Jacobian; logq(theta_s): log q density
log_r = np.array([logp_joint(t) - logq(t) for t in theta])
log_w, khat = az.psislw(log_r)                  # smoothed log weights, Pareto shape
print(f"k-hat = {float(khat):.2f}")
 
if khat < 0.7:                                   # PSIS-corrected posterior mean
    w = np.exp(log_w - log_w.max()); w /= w.sum()
    post_mean = (w[:, None] * theta).sum(0)

Both densities must be evaluated in the same coordinates; by the invariance result either space is fine as long as the Jacobian is included consistently. CmdStan’s variational output includes log_p__ (log joint) and log_g__ (log approximation) columns that can be differenced to form .

A decision rule for applied work. For a media mix or geo-hierarchical model fitted by ADVI: (i) rerun with tolerance and several seeds; (ii) compute joint ; (iii) if , non-center, centre and scale predictors, try full-rank, then fall back to NUTS; (iv) never infer interval quality from good out-of-sample prediction, which case 2 shows can improve while the posterior approximation degrades. If the production system must use VI for speed, run VSBC once per model structure offline to learn which parameters (typically scales such as and ) are systematically biased.

Connections

See Also