Lably
Skip to content

Variational Bayesian methods

Mathematical methods used in Bayesian inference and machine learning

  • 19 min read
  • 7 chapters

Related on Lably

Through Integral, Machine learning and Parameter

  1. To provide an analytical approximation to the posterior probability of the unobserved variables, in order to do statistical inference over these variables.
  2. To derive a lower bound for the marginal likelihood (sometimes called the evidence) of the observed data (i.e. the marginal probability of the data given the model, with marginalization performed over unobserved variables). This is typically used for performing model selection, the general idea being that a higher marginal likelihood for a given model indicates a better fit of the data by that model and hence a greater probability that the model in question was the one that generated the data. (See also the Bayes factor article.)

In the former purpose (that of approximating a posterior probability), variational Bayes is an alternative to Monte Carlo sampling methods—particularly, Markov chain Monte Carlo methods such as Gibbs sampling—for taking a fully Bayesian approach to statistical inference over complex distributions that are difficult to evaluate directly or sample. In particular, whereas Monte Carlo techniques provide a numerical approximation to the exact posterior using a set of samples, variational Bayes provides a locally-optimal, exact analytical solution to an approximation of the posterior.

Variational Bayes can be seen as an extension of the expectation–maximization (EM) algorithm from maximum likelihood (ML) or maximum a posteriori (MAP) estimation of the single most probable value of each parameter to fully Bayesian estimation which computes (an approximation to) the entire posterior distribution of the parameters and latent variables. As in EM, it finds a set of optimal parameter values, and it has the same alternating structure as does EM, based on a set of interlocked (mutually dependent) equations that cannot be solved analytically.

For many applications, variational Bayes produces solutions of comparable accuracy to Gibbs sampling at greater speed. However, deriving the set of equations used to update the parameters iteratively often requires a large amount of work compared with deriving the comparable Gibbs sampling equations. This is the case even for many models that are conceptually quite simple, as is demonstrated below in the case of a basic non-hierarchical model with only two parameters and no latent variables.

Mathematical derivation

Problem

In variational inference, the posterior distribution over a set of unobserved variables Z={Z1…Zn} given some data X is approximated by a so-called variational distribution, Q(Z):

P(Z∣X)≈Q(Z).

The distribution Q(Z) is restricted to belong to a family of distributions of simpler form than P(Z∣X) (e.g. a family of Gaussian distributions), selected with the intention of making Q(Z) similar to the true posterior, P(Z∣X).

The similarity (or dissimilarity) is measured in terms of a dissimilarity function d(Q;P) and hence inference is performed by selecting the distribution Q(Z) that minimizes d(Q;P).

KL divergence

The most common type of variational Bayes uses the Kullback–Leibler divergence (KL-divergence) of Q from P as the choice of dissimilarity function. This choice makes this minimization tractable. The KL-divergence is defined as

DKL(Q∥P)≜∑ZQ(Z)log⁡Q(Z)P(Z∣X).

Note that Q and P are reversed from what one might expect. This use of reversed KL-divergence is conceptually similar to the expectation–maximization algorithm. (Using the KL-divergence in the other way produces the expectation propagation algorithm.)

Intractability

Variational techniques are typically used to form an approximation for:

P(Z∣X)=P(X∣Z)P(Z)P(X)=P(X∣Z)P(Z)∫ZP(X,Z′)dZ′

The marginalization over Z to calculate P(X) in the denominator is typically intractable, because, for example, the search space of Z is combinatorially large. Therefore, we seek an approximation, using Q(Z)≈P(Z∣X).

Evidence lower bound

Given that P(Z∣X)=P(X,Z)P(X), the KL-divergence above can also be written as

DKL(Q∥P)=∑ZQ(Z)[log⁡Q(Z)P(Z,X)+log⁡P(X)]=∑ZQ(Z)[log⁡Q(Z)−log⁡P(Z,X)]+∑ZQ(Z)[log⁡P(X)]

Because P(X) is a constant with respect to Z and ∑ZQ(Z)=1 because Q(Z) is a distribution, we have

DKL(Q∥P)=∑ZQ(Z)[log⁡Q(Z)−log⁡P(Z,X)]+log⁡P(X)

which, according to the definition of expected value (for a discrete random variable), can be written as follows

DKL(Q∥P)=EQ[log⁡Q(Z)−log⁡P(Z,X)]+log⁡P(X)

which can be rearranged to become

log⁡P(X)=DKL(Q∥P)−EQ[log⁡Q(Z)−log⁡P(Z,X)]=DKL(Q∥P)+L(Q)

As the log-evidence log⁡P(X) is fixed with respect to Q, maximizing the final term L(Q) minimizes the KL divergence of Q from P. By appropriate choice of Q, L(Q) becomes tractable to compute and to maximize. Hence we have both an analytical approximation Q for the posterior P(Z∣X), and a lower bound L(Q) for the log-evidence log⁡P(X) (since the KL-divergence is non-negative).

The lower bound L(Q) is known as the (negative) variational free energy in analogy with thermodynamic free energy because it can also be expressed as a negative energy EQ⁡[log⁡P(Z,X)] plus the entropy of Q. The term L(Q) is also known as Evidence Lower Bound, abbreviated as ELBO, to emphasize that it is a lower (worst-case) bound on the log-evidence of the data.

Proofs

By the generalized Pythagorean theorem of Bregman divergence, of which KL-divergence is a special case, it can be shown that:

DKL(Q∥P)≥DKL(Q∥Q∗)+DKL(Q∗∥P),∀Q∗∈C

where C is a convex set and the equality holds if:

Q=Q∗≜arg⁡minQ∈CDKL(Q∥P).

In this case, the global minimizer Q∗(Z)=q∗(Z1∣Z2)q∗(Z2)=q∗(Z2∣Z1)q∗(Z1), with Z={Z1,Z2}, can be found as follows:

q∗(Z2)=P(X)ζ(X)P(Z2∣X)exp⁡(DKL(q∗(Z1∣Z2)∥P(Z1∣Z2,X)))=1ζ(X)exp⁡Eq∗(Z1∣Z2)(log⁡P(Z,X)q∗(Z1∣Z2)),

in which the normalizing constant is:

ζ(X)=P(X)∫Z2P(Z2∣X)exp⁡(DKL(q∗(Z1∣Z2)∥P(Z1∣Z2,X)))=∫Z2exp⁡Eq∗(Z1∣Z2)(log⁡P(Z,X)q∗(Z1∣Z2)).

The term ζ(X) is often called the evidence lower bound (ELBO) in practice, since P(X)≥ζ(X)=exp⁡(L(Q∗)), as shown above.

By interchanging the roles of Z1 and Z2, we can iteratively compute the approximated q∗(Z1) and q∗(Z2) of the true model's marginals P(Z1∣X) and P(Z2∣X), respectively. Although this iterative scheme is guaranteed to converge monotonically, the converged Q∗ is only a local minimizer of DKL(Q∥P).

If the constrained space C is confined within independent space, i.e. q∗(Z1∣Z2)=q∗(Z1),the above iterative scheme will become the so-called mean field approximation Q∗(Z)=q∗(Z1)q∗(Z2),as shown below.

Sign in to keep reading

6 more chapters are free with a Lably account.

More in Statistics