Variational Bayesian methods

Short description: Mathematical methods used in Bayesian inference and machine learning

For the method of approximation in quantum mechanics, see Variational method (quantum mechanics).

Part of a series on

Bayesian statistics
Theory

* Admissible decision rule
* Bayesian efficiency
* Bayesian probability
* Probability interpretations
* Bayes' theorem
* Bayes factor
* Bayesian inference
* Bayesian network
* Prior
* Posterior
* Likelihood
* Conjugate prior
* Posterior predictive
* Hyperparameter
* Hyperprior
* Principle of indifference
* Principle of maximum entropy
* Empirical Bayes method
* Cromwell's rule
* Bernstein–von Mises theorem
* Schwarz criterion
* Credible interval
* Maximum a posteriori estimation
* Radical probabilism

Techniques

* Bayesian linear regression
* Bayesian estimator
* Approximate Bayesian computation
* Markov chain Monte Carlo

* v
* t
* e

Variational Bayesian methods are a family of techniques for approximating intractable integrals arising in Bayesian inference and machine learning. They are typically used in complex statistical models consisting of observed variables (usually termed "data") as well as unknown parameters and latent variables, with various sorts of relationships among the three types of random variables, as might be described by a graphical model. As typical in Bayesian inference, the parameters and latent variables are grouped together as "unobserved variables". Variational Bayesian methods are primarily used for two purposes:

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.

## Contents

* 1 Mathematical derivation
* 1.1 Problem
* 1.2 KL divergence
* 1.3 Intractability
* 1.4 Evidence lower bound
* 1.5 Proofs
* 2 Mean field approximation
* 3 A duality formula for variational inference
* 4 A basic example
* 4.1 The mathematical model
* 4.2 The joint probability
* 4.3 Factorized approximation
* 4.4 Derivation of q(μ)
* 4.5 Derivation of q(τ)
* 4.6 Algorithm for computing the parameters
* 5 Further discussion
* 5.1 Step-by-step recipe
* 5.2 Most important points
* 5.3 Compared with expectation–maximization (EM)
* 6 A more complex example
* 7 Exponential-family distributions
* 8 See also
* 9 References
* 10 External links

## Mathematical derivation

### Problem

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

P(𝐙∣𝐗)≈Q(𝐙).

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

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(𝐙) 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)≜∑𝐙Q(𝐙)log⁡Q(𝐙)P(𝐙∣𝐗).

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(𝐙∣𝐗)=P(𝐗∣𝐙)P(𝐙)P(𝐗)=P(𝐗∣𝐙)P(𝐙)∫𝐙P(𝐗,𝐙′)d𝐙′

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

### Evidence lower bound

Main article: Evidence lower bound

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

DKL(Q∥P)=∑𝐙Q(𝐙)[log⁡Q(𝐙)P(𝐙,𝐗)+log⁡P(𝐗)]=∑𝐙Q(𝐙)[log⁡Q(𝐙)−log⁡P(𝐙,𝐗)]+∑𝐙Q(𝐙)[log⁡P(𝐗)]

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

DKL(Q∥P)=∑𝐙Q(𝐙)[log⁡Q(𝐙)−log⁡P(𝐙,𝐗)]+log⁡P(𝐗)

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

DKL(Q∥P)=𝔼𝐐[log⁡Q(𝐙)−log⁡P(𝐙,𝐗)]+log⁡P(𝐗)

which can be rearranged to become

log⁡P(𝐗)=DKL(Q∥P)−𝔼𝐐[log⁡Q(𝐙)−log⁡P(𝐙,𝐗)]=DKL(Q∥P)+ℒ(Q)

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

The lower bound ℒ(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(𝐙,𝐗)] plus the entropy of Q. The term ℒ(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:[1][2]

Generalized Pythagorean theorem for Bregman divergence[2]

DKL(Q∥P)≥DKL(Q∥Q*)+DKL(Q*∥P),∀Q*∈𝒞

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

Q=Q*≜arg⁡minQ∈𝒞DKL(Q∥P).

In this case, the global minimizer Q*(𝐙)=q*(𝐙1∣𝐙2)q*(𝐙2)=q*(𝐙2∣𝐙1)q*(𝐙1), with 𝐙={Z𝟏,Z𝟐}, can be found as follows:[1]

q*(𝐙2)=P(𝐗)ζ(𝐗)P(𝐙2∣𝐗)exp⁡(DKL(q*(𝐙1∣𝐙2)∥P(𝐙1∣𝐙2,𝐗)))=1ζ(𝐗)exp⁡𝔼q*(𝐙1∣𝐙2)(log⁡P(𝐙,𝐗)q*(𝐙1∣𝐙2)),

in which the normalizing constant is:

ζ(𝐗)=P(𝐗)∫𝐙2P(𝐙2∣𝐗)exp⁡(DKL(q*(𝐙1∣𝐙2)∥P(𝐙1∣𝐙2,𝐗)))=∫𝐙2exp⁡𝔼q*(𝐙1∣𝐙2)(log⁡P(𝐙,𝐗)q*(𝐙1∣𝐙2)).

The term ζ(𝐗) is often called the evidence lower bound (ELBO) in practice, since P(𝐗)≥ζ(𝐗)=exp⁡(ℒ(Q*)),[1] as shown above.

By interchanging the roles of 𝐙1 and 𝐙2, we can iteratively compute the approximated q*(𝐙1) and q*(𝐙2) of the true model's marginals P(𝐙1∣𝐗) and P(𝐙2∣𝐗), respectively. Although this iterative scheme is guaranteed to converge monotonically,[1] the converged Q* is only a local minimizer of DKL(Q∥P).

If the constrained space 𝒞 is confined within independent space, i.e. q*(𝐙1∣𝐙2)=q*(Z𝟏),the above iterative scheme will become the so-called mean field approximation Q*(𝐙)=q*(𝐙1)q*(𝐙2),as shown below.

## Mean field approximation

The variational distribution Q(𝐙) is usually assumed to factorize over some partition of the latent variables, i.e. for some partition of the latent variables 𝐙 into 𝐙1…𝐙M,

Q(𝐙)=∏i=1Mqi(𝐙i∣𝐗)

It can be shown using the calculus of variations (hence the name "variational Bayes") that the "best" distribution qj* for each of the factors qj (in terms of the distribution minimizing the KL divergence, as described above) satisfies:[3]

qj*(𝐙j∣𝐗)=eEq−j*[ln⁡p(𝐙,𝐗)]∫eEq−j*[ln⁡p(𝐙,𝐗)]d𝐙j

where Eq−j*[ln⁡p(𝐙,𝐗)] is the expectation of the logarithm of the joint probability of the data and latent variables, taken with respect to q* over all variables not in the partition: refer to Lemma 4.1 of[4] for a derivation of the distribution qj*(𝐙j∣𝐗).

In practice, we usually work in terms of logarithms, i.e.:

ln⁡qj*(𝐙j∣𝐗)=Eq−j*[ln⁡p(𝐙,𝐗)]+constant

The constant in the above expression is related to the normalizing constant (the denominator in the expression above for qj*) and is usually reinstated by inspection, as the rest of the expression can usually be recognized as being a known type of distribution (e.g. Gaussian, gamma, etc.).

Using the properties of expectations, the expression Eq−j*[ln⁡p(𝐙,𝐗)] can usually be simplified into a function of the fixed hyperparameters of the prior distributions over the latent variables and of expectations (and sometimes higher moments such as the variance) of latent variables not in the current partition (i.e. latent variables not included in 𝐙j). This creates circular dependencies between the parameters of the distributions over variables in one partition and the expectations of variables in the other partitions. This naturally suggests an iterative algorithm, much like EM (the expectation–maximization algorithm), in which the expectations (and possibly higher moments) of the latent variables are initialized in some fashion (perhaps randomly), and then the parameters of each distribution are computed in turn using the current values of the expectations, after which the expectation of the newly computed distribution is set appropriately according to the computed parameters. An algorithm of this sort is guaranteed to converge.[5]

In other words, for each of the partitions of variables, by simplifying the expression for the distribution over the partition's variables and examining the distribution's functional dependency on the variables in question, the family of the distribution can usually be determined (which in turn determines the value of the constant). The formula for the distribution's parameters will be expressed in terms of the prior distributions' hyperparameters (which are known constants), but also in terms of expectations of functions of variables in other partitions. Usually these expectations can be simplified into functions of expectations of the variables themselves (i.e. the means); sometimes expectations of squared variables (which can be related to the variance of the variables), or expectations of higher powers (i.e. higher moments) also appear. In most cases, the other variables' distributions will be from known families, and the formulas for the relevant expectations can be looked up. However, those formulas depend on those distributions' parameters, which depend in turn on the expectations about other variables. The result is that the formulas for the parameters of each variable's distributions can be expressed as a series of equations with mutual, nonlinear dependencies among the variables. Usually, it is not possible to solve this system of equations directly. However, as described above, the dependencies suggest a simple iterative algorithm, which in most cases is guaranteed to converge. An example will make this process clearer.

## A duality formula for variational inference

Pictorial illustration of coordinate ascent variational inference algorithm by the duality formula[4]

The following theorem is referred to as a duality formula for variational inference.[4] It explains some important properties of the variational distributions used in variational Bayes methods.

Theorem Consider two probability spaces (Θ,ℱ,P) and (Θ,ℱ,Q) with Q≪P. Assume that there is a common dominating probability measure λ such that P≪λ and Q≪λ. Let h denote any real-valued random variable on (Θ,ℱ,P) that satisfies h∈L1(P). Then the following equality holds

log⁡EP[exp⁡h]=supQ≪P{EQ[h]−DKL(Q∥P)}.

Further, the supremum on the right-hand side is attained if and only if it holds

q(θ)p(θ)=exp⁡h(θ)EP[exp⁡h],

almost surely with respect to probability measure Q, where p(θ)=dP/dλ and q(θ)=dQ/dλ denote the Radon–Nikodym derivatives of the probability measures P and Q with respect to λ, respectively.

## A basic example

Consider a simple non-hierarchical Bayesian model consisting of a set of i.i.d. observations from a Gaussian distribution, with unknown mean and variance.[6] In the following, we work through this model in great detail to illustrate the workings of the variational Bayes method.

For mathematical convenience, in the following example we work in terms of the precision — i.e. the reciprocal of the variance (or in a multivariate Gaussian, the inverse of the covariance matrix) — rather than the variance itself. (From a theoretical standpoint, precision and variance are equivalent since there is a one-to-one correspondence between the two.)

### The mathematical model

We place conjugate prior distributions on the unknown mean μ and precision τ, i.e. the mean also follows a Gaussian distribution while the precision follows a gamma distribution. In other words:

τ∼Gamma⁡(a0,b0)μ|τ∼𝒩(μ0,(λ0τ)−1){x1,…,xN}∼𝒩(μ,τ−1)N=number of data points

The hyperparameters μ0,λ0,a0 and b0 in the prior distributions are fixed, given values. They can be set to small positive numbers to give broad prior distributions indicating ignorance about the prior distributions of μ and τ.

We are given N data points 𝐗={x1,…,xN} and our goal is to infer the posterior distribution q(μ,τ)=p(μ,τ∣x1,…,xN) of the parameters μ and τ.

### The joint probability

The joint probability of all variables can be rewritten as

p(𝐗,μ,τ)=p(𝐗∣μ,τ)p(μ∣τ)p(τ)

where the individual factors are

p(𝐗∣μ,τ)=∏n=1N𝒩(xn∣μ,τ−1)p(μ∣τ)=𝒩(μ∣μ0,(λ0τ)−1)p(τ)=Gamma⁡(τ∣a0,b0)

where

𝒩(x∣μ,σ2)=12πσ2e−(x−μ)22σ2Gamma⁡(τ∣a,b)=1Γ(a)baτa−1e−bτ

### Factorized approximation

Assume that q(μ,τ)=q(μ)q(τ), i.e. that the posterior distribution factorizes into independent factors for μ and τ. This type of assumption underlies the variational Bayesian method. The true posterior distribution does not in fact factor this way (in fact, in this simple case, it is known to be a Gaussian-gamma distribution), and hence the result we obtain will be an approximation.

### Derivation of q(μ)

Then

ln⁡qμ*(μ)=Eτ[ln⁡p(𝐗∣μ,τ)+ln⁡p(μ∣τ)+ln⁡p(τ)]+C=Eτ[ln⁡p(𝐗∣μ,τ)]+Eτ[ln⁡p(μ∣τ)]+Eτ[ln⁡p(τ)]+C=Eτ[ln⁡∏n=1N𝒩(xn∣μ,τ−1)]+Eτ[ln⁡𝒩(μ∣μ0,(λ0τ)−1)]+C2=Eτ[ln⁡∏n=1Nτ2πe−(xn−μ)2τ2]+Eτ[ln⁡λ0τ2πe−(μ−μ0)2λ0τ2]+C2=Eτ[∑n=1N(12(ln⁡τ−ln⁡2π)−(xn−μ)2τ2)]+Eτ[12(ln⁡λ0+ln⁡τ−ln⁡2π)−(μ−μ0)2λ0τ2]+C2=Eτ[∑n=1N−(xn−μ)2τ2]+Eτ[−(μ−μ0)2λ0τ2]+Eτ[∑n=1N12(ln⁡τ−ln⁡2π)]+Eτ[12(ln⁡λ0+ln⁡τ−ln⁡2π)]+C2=Eτ[∑n=1N−(xn−μ)2τ2]+Eτ[−(μ−μ0)2λ0τ2]+C3=−Eτ[τ]2{∑n=1N(xn−μ)2+λ0(μ−μ0)2}+C3

In the above derivation, C, C2 and C3 refer to values that are constant with respect to μ. Note that the term Eτ[ln⁡p(τ)] is not a function of μ and will have the same value regardless of the value of μ. Hence in line 3 we can absorb it into the constant term at the end. We do the same thing in line 7.

The last line is simply a quadratic polynomial in μ. Since this is the logarithm of qμ*(μ), we can see that qμ*(μ) itself is a Gaussian distribution.

With a certain amount of tedious math (expanding the squares inside of the braces, separating out and grouping the terms involving μ and μ2 and completing the square over μ), we can derive the parameters of the Gaussian distribution:

ln⁡qμ*(μ)=−Eτ[τ]2{∑n=1N(xn−μ)2+λ0(μ−μ0)2}+C3=−Eτ[τ]2{∑n=1N(xn2−2xnμ+μ2)+λ0(μ2−2μ0μ+μ02)}+C3=−Eτ[τ]2{(∑n=1Nxn2)−2(∑n=1Nxn)μ+(∑n=1Nμ2)+λ0μ2−2λ0μ0μ+λ0μ02}+C3=−Eτ[τ]2{(λ0+N)μ2−2(λ0μ0+∑n=1Nxn)μ+(∑n=1Nxn2)+λ0μ02}+C3=−Eτ[τ]2{(λ0+N)μ2−2(λ0μ0+∑n=1Nxn)μ}+C4=−Eτ[τ]2{(λ0+N)μ2−2(λ0μ0+∑n=1Nxnλ0+N)(λ0+N)μ}+C4=−Eτ[τ]2{(λ0+N)(μ2−2(λ0μ0+∑n=1Nxnλ0+N)μ)}+C4=−Eτ[τ]2{(λ0+N)(μ2−2(λ0μ0+∑n=1Nxnλ0+N)μ+(λ0μ0+∑n=1Nxnλ0+N)2−(λ0μ0+∑n=1Nxnλ0+N)2)}+C4=−Eτ[τ]2{(λ0+N)(μ2−2(λ0μ0+∑n=1Nxnλ0+N)μ+(λ0μ0+∑n=1Nxnλ0+N)2)}+C5=−Eτ[τ]2{(λ0+N)(μ−λ0μ0+∑n=1Nxnλ0+N)2}+C5=−12(λ0+N)Eτ[τ](μ−λ0μ0+∑n=1Nxnλ0+N)2+C5

Note that all of the above steps can be shortened by using the formula for the sum of two quadratics.

In other words:

qμ*(μ)∼𝒩(μ∣μN,λN−1)μN=λ0μ0+Nx¯λ0+NλN=(λ0+N)Eτ[τ]x¯=1N∑n=1Nxn

### Derivation of q(τ)

The derivation of qτ*(τ) is similar to above, although we omit some of the details for the sake of brevity.

ln⁡qτ*(τ)=Eμ[ln⁡p(𝐗∣μ,τ)+ln⁡p(μ∣τ)]+ln⁡p(τ)+constant=(a0−1)ln⁡τ−b0τ+12ln⁡τ+N2ln⁡τ−τ2Eμ[∑n=1N(xn−μ)2+λ0(μ−μ0)2]+constant

Exponentiating both sides, we can see that qτ*(τ) is a gamma distribution. Specifically:

qτ*(τ)∼Gamma⁡(τ∣aN,bN)aN=a0+N+12bN=b0+12Eμ[∑n=1N(xn−μ)2+λ0(μ−μ0)2]

### Algorithm for computing the parameters

Let us recap the conclusions from the previous sections:

qμ*(μ)∼𝒩(μ∣μN,λN−1)μN=λ0μ0+Nx¯λ0+NλN=(λ0+N)Eτ[τ]x¯=1N∑n=1Nxn

and

qτ*(τ)∼Gamma⁡(τ∣aN,bN)aN=a0+N+12bN=b0+12Eμ[∑n=1N(xn−μ)2+λ0(μ−μ0)2]

In each case, the parameters for the distribution over one of the variables depend on expectations taken with respect to the other variable. We can expand the expectations, using the standard formulas for the expectations of moments of the Gaussian and gamma distributions:

E⁡[τ∣aN,bN]=aNbNE⁡[μ∣μN,λN−1]=μNE⁡[X2]=Var⁡(X)+(E⁡[X])2E⁡[μ2∣μN,λN−1]=λN−1+μN2

Applying these formulas to the above equations is trivial in most cases, but the equation for bN takes more work:

bN=b0+12Eμ[∑n=1N(xn−μ)2+λ0(μ−μ0)2]=b0+12Eμ[(λ0+N)μ2−2(λ0μ0+∑n=1Nxn)μ+(∑n=1Nxn2)+λ0μ02]=b0+12[(λ0+N)Eμ[μ2]−2(λ0μ0+∑n=1Nxn)Eμ[μ]+(∑n=1Nxn2)+λ0μ02]=b0+12[(λ0+N)(λN−1+μN2)−2(λ0μ0+∑n=1Nxn)μN+(∑n=1Nxn2)+λ0μ02]

We can then write the parameter equations as follows, without any expectations:

μN=λ0μ0+Nx¯λ0+NλN=(λ0+N)aNbNx¯=1N∑n=1NxnaN=a0+N+12bN=b0+12[(λ0+N)(λN−1+μN2)−2(λ0μ0+∑n=1Nxn)μN+(∑n=1Nxn2)+λ0μ02]

Note that there are circular dependencies among the formulas for λNand bN. This naturally suggests an EM-like algorithm:

1. Compute ∑n=1Nxn and ∑n=1Nxn2. Use these values to compute μN and aN.
2. Initialize λN to some arbitrary value.
3. Use the current value of λN, along with the known values of the other parameters, to compute bN.
4. Use the current value of bN, along with the known values of the other parameters, to compute λN.
5. Repeat the last two steps until convergence (i.e. until neither value has changed more than some small amount).

We then have values for the hyperparameters of the approximating distributions of the posterior parameters, which we can use to compute any properties we want of the posterior — e.g. its mean and variance, a 95% highest-density region (the smallest interval that includes 95% of the total probability), etc.

It can be shown that this algorithm is guaranteed to converge to a local maximum.

Note also that the posterior distributions have the same form as the corresponding prior distributions. We did not assume this; the only assumption we made was that the distributions factorize, and the form of the distributions followed naturally. It turns out (see below) that the fact that the posterior distributions have the same form as the prior distributions is not a coincidence, but a general result whenever the prior distributions are members of the exponential family, which is the case for most of the standard distributions.

## Further discussion

### Step-by-step recipe

The above example shows the method by which the variational-Bayesian approximation to a posterior probability density in a given Bayesian network is derived:

1. Describe the network with a graphical model, identifying the observed variables (data) 𝐗 and unobserved variables (parameters Θ and latent variables 𝐙) and their conditional probability distributions. Variational Bayes will then construct an approximation to the posterior probability p(𝐙,Θ∣𝐗). The approximation has the basic property that it is a factorized distribution, i.e. a product of two or more independent distributions over disjoint subsets of the unobserved variables.
2. Partition the unobserved variables into two or more subsets, over which the independent factors will be derived. There is no universal procedure for doing this; creating too many subsets yields a poor approximation, while creating too few makes the entire variational Bayes procedure intractable. Typically, the first split is to separate the parameters and latent variables; often, this is enough by itself to produce a tractable result. Assume that the partitions are called 𝐙1,…,𝐙M.
3. For a given partition 𝐙j, write down the formula for the best approximating distribution qj*(𝐙j∣𝐗) using the basic equation ln⁡qj*(𝐙j∣𝐗)=Ei≠j[ln⁡p(𝐙,𝐗)]+constant .
4. Fill in the formula for the joint probability distribution using the graphical model. Any component conditional distributions that don't involve any of the variables in 𝐙j can be ignored; they will be folded into the constant term.
5. Simplify the formula and apply the expectation operator, following the above example. Ideally, this should simplify into expectations of basic functions of variables not in 𝐙j (e.g. first or second raw moments, expectation of a logarithm, etc.). In order for the variational Bayes procedure to work well, these expectations should generally be expressible analytically as functions of the parameters and/or hyperparameters of the distributions of these variables. In all cases, these expectation terms are constants with respect to the variables in the current partition.
6. The functional form of the formula with respect to the variables in the current partition indicates the type of distribution. In particular, exponentiating the formula generates the probability density function (PDF) of the distribution (or at least, something proportional to it, with unknown normalization constant). In order for the overall method to be tractable, it should be possible to recognize the functional form as belonging to a known distribution. Significant mathematical manipulation may be required to convert the formula into a form that matches the PDF of a known distribution. When this can be done, the normalization constant can be reinstated by definition, and equations for the parameters of the known distribution can be derived by extracting the appropriate parts of the formula.
7. When all expectations can be replaced analytically with functions of variables not in the current partition, and the PDF put into a form that allows identification with a known distribution, the result is a set of equations expressing the values of the optimum parameters as functions of the parameters of variables in other partitions.
8. When this procedure can be applied to all partitions, the result is a set of mutually linked equations specifying the optimum values of all parameters.
9. An expectation–maximization (EM) type procedure is then applied, picking an initial value for each parameter and the iterating through a series of steps, where at each step we cycle through the equations, updating each parameter in turn. This is guaranteed to converge.

### Most important points

Due to all of the mathematical manipulations involved, it is easy to lose track of the big picture. The important things are:

1. The idea of variational Bayes is to construct an analytical approximation to the posterior probability of the set of unobserved variables (parameters and latent variables), given the data. This means that the form of the solution is similar to other Bayesian inference methods, such as Gibbs sampling — i.e. a distribution that seeks to describe everything that is known about the variables. As in other Bayesian methods — but unlike e.g. in expectation–maximization (EM) or other maximum likelihood methods — both types of unobserved variables (i.e. parameters and latent variables) are treated the same, i.e. as random variables. Estimates for the variables can then be derived in the standard Bayesian ways, e.g. calculating the mean of the distribution to get a single point estimate or deriving a credible interval, highest density region, etc.
2. "Analytical approximation" means that a formula can be written down for the posterior distribution. The formula generally consists of a product of well-known probability distributions, each of which factorizes over a set of unobserved variables (i.e. it is conditionally independent of the other variables, given the observed data). This formula is not the true posterior distribution, but an approximation to it; in particular, it will generally agree fairly closely in the lowest moments of the unobserved variables, e.g. the mean and variance.
3. The result of all of the mathematical manipulations is (1) the identity of the probability distributions making up the factors, and (2) mutually dependent formulas for the parameters of these distributions. The actual values of these parameters are computed numerically, through an alternating iterative procedure much like EM.

### Compared with expectation–maximization (EM)

Variational Bayes (VB) is often compared with expectation–maximization (EM). The actual numerical procedure is quite similar, in that both are alternating iterative procedures that successively converge on optimum parameter values. The initial steps to derive the respective procedures are also vaguely similar, both starting out with formulas for probability densities and both involving significant amounts of mathematical manipulations.

However, there are a number of differences. Most important is what is being computed.

* EM computes point estimates of posterior distribution of those random variables that can be categorized as "parameters", but only estimates of the actual posterior distributions of the latent variables (at least in "soft EM", and often only when the latent variables are discrete). The point estimates computed are the modes of these parameters; no other information is available.
* VB, on the other hand, computes estimates of the actual posterior distribution of all variables, both parameters and latent variables. When point estimates need to be derived, generally the mean is used rather than the mode, as is normal in Bayesian inference. Concomitant with this, the parameters computed in VB do not have the same significance as those in EM. EM computes optimum values of the parameters of the Bayes network itself. VB computes optimum values of the parameters of the distributions used to approximate the parameters and latent variables of the Bayes network. For example, a typical Gaussian mixture model will have parameters for the mean and variance of each of the mixture components. EM would directly estimate optimum values for these parameters. VB, however, would first fit a distribution to these parameters — typically in the form of a prior distribution, e.g. a normal-scaled inverse gamma distribution — and would then compute values for the parameters of this prior distribution, i.e. essentially hyperparameters. In this case, VB would compute optimum estimates of the four parameters of the normal-scaled inverse gamma distribution that describes the joint distribution of the mean and variance of the component.

## A more complex example

Bayesian Gaussian mixture model using plate notation. Smaller squares indicate fixed parameters; larger circles indicate random variables. Filled-in shapes indicate known values. The indication [K] means a vector of size K; [D,D] means a matrix of size D×D; K alone means a categorical variable with K outcomes. The squiggly line coming from z ending in a crossbar indicates a switch — the value of this variable selects, for the other incoming variables, which value to use out of the size-K array of possible values.

Imagine a Bayesian Gaussian mixture model described as follows:[3]

π∼SymDir⁡(K,α0)Λi=1…K∼𝒲(𝐖0,ν0)μi=1…K∼𝒩(μ0,(β0Λi)−1)𝐳[i=1…N]∼Mult⁡(1,π)𝐱i=1…N∼𝒩(μzi,Λzi−1)K=number of mixing componentsN=number of data points

Note:

* SymDir() is the symmetric Dirichlet distribution of dimension K, with the hyperparameter for each component set to α0. The Dirichlet distribution is the conjugate prior of the categorical distribution or multinomial distribution.
* 𝒲() is the Wishart distribution, which is the conjugate prior of the precision matrix (inverse covariance matrix) for a multivariate Gaussian distribution.
* Mult() is a multinomial distribution over a single observation (equivalent to a categorical distribution). The state space is a "one-of-K" representation, i.e., a K-dimensional vector in which one of the elements is 1 (specifying the identity of the observation) and all other elements are 0.
* 𝒩() is the Gaussian distribution, in this case specifically the multivariate Gaussian distribution.

The interpretation of the above variables is as follows:

* 𝐗={𝐱1,…,𝐱N} is the set of N data points, each of which is a D-dimensional vector distributed according to a multivariate Gaussian distribution.
* 𝐙={𝐳1,…,𝐳N} is a set of latent variables, one per data point, specifying which mixture component the corresponding data point belongs to, using a "one-of-K" vector representation with components znk for k=1…K, as described above.
* π is the mixing proportions for the K mixture components.
* μi=1…K and Λi=1…K specify the parameters (mean and precision) associated with each mixture component.

The joint probability of all variables can be rewritten as

p(𝐗,𝐙,π,μ,Λ)=p(𝐗∣𝐙,μ,Λ)p(𝐙∣π)p(π)p(μ∣Λ)p(Λ)

where the individual factors are

p(𝐗∣𝐙,μ,Λ)=∏n=1N∏k=1K𝒩(𝐱n∣μk,Λk−1)znkp(𝐙∣π)=∏n=1N∏k=1Kπkznkp(π)=Γ(Kα0)Γ(α0)K∏k=1Kπkα0−1p(μ∣Λ)=∏k=1K𝒩(μk∣μ0,(β0Λk)−1)p(Λ)=∏k=1K𝒲(Λk∣𝐖0,ν0)

where

𝒩(𝐱∣μ,Σ)=1(2π)D/21|Σ|1/2exp⁡{−12(𝐱−μ)TΣ−1(𝐱−μ)}𝒲(Λ∣𝐖,ν)=B(𝐖,ν)|Λ|(ν−D−1)/2exp⁡(−12Tr⁡(𝐖−1Λ))B(𝐖,ν)=|𝐖|−ν/2{2νD/2πD(D−1)/4∏i=1DΓ(ν+1−i2)}−1D=dimensionality of each data point

Assume that q(𝐙,π,μ,Λ)=q(𝐙)q(π,μ,Λ).

Then[3]

ln⁡q*(𝐙)=Eπ,μ,Λ[ln⁡p(𝐗,𝐙,π,μ,Λ)]+constant=Eπ[ln⁡p(𝐙∣π)]+Eμ,Λ[ln⁡p(𝐗∣𝐙,μ,Λ)]+constant=∑n=1N∑k=1Kznkln⁡ρnk+constant

where we have defined

ln⁡ρnk=E⁡[ln⁡πk]+12E⁡[ln⁡|Λk|]−D2ln⁡(2π)−12Eμk,Λk[(𝐱n−μk)TΛk(𝐱n−μk)]

Exponentiating both sides of the formula for ln⁡q*(𝐙) yields

q*(𝐙)∝∏n=1N∏k=1Kρnkznk

Requiring that this be normalized ends up requiring that the ρnk sum to 1 over all values of k, yielding

q*(𝐙)=∏n=1N∏k=1Krnkznk

where

rnk=ρnk∑j=1Kρnj

In other words, q*(𝐙) is a product of single-observation multinomial distributions, and factors over each individual 𝐳n, which is distributed as a single-observation multinomial distribution with parameters rnk for k=1…K.

Furthermore, we note that

E⁡[znk]=rnk

which is a standard result for categorical distributions.

Now, considering the factor q(π,μ,Λ), note that it automatically factors into q(π)∏k=1Kq(μk,Λk) due to the structure of the graphical model defining our Gaussian mixture model, which is specified above.

Then,

ln⁡q*(π)=ln⁡p(π)+E𝐙[ln⁡p(𝐙∣π)]+constant=(α0−1)∑k=1Kln⁡πk+∑n=1N∑k=1Krnkln⁡πk+constant

Taking the exponential of both sides, we recognize q*(π) as a Dirichlet distribution

q*(π)∼Dir⁡(α)

where

αk=α0+Nk

where

Nk=∑n=1Nrnk

Finally

ln⁡q*(μk,Λk)=ln⁡p(μk,Λk)+∑n=1NE⁡[znk]ln⁡𝒩(𝐱n∣μk,Λk−1)+constant

Grouping and reading off terms involving μk and Λk, the result is a Gaussian-Wishart distribution given by

q*(μk,Λk)=𝒩(μk∣𝐦k,(βkΛk)−1)𝒲(Λk∣𝐖k,νk)

given the definitions

βk=β0+Nk𝐦k=1βk(β0μ0+Nk𝐱¯k)𝐖k−1=𝐖0−1+Nk𝐒k+β0Nkβ0+Nk(𝐱¯k−μ0)(𝐱¯k−μ0)Tνk=ν0+NkNk=∑n=1Nrnk𝐱¯k=1Nk∑n=1Nrnk𝐱n𝐒k=1Nk∑n=1Nrnk(𝐱n−𝐱¯k)(𝐱n−𝐱¯k)T

Finally, notice that these functions require the values of rnk, which make use of ρnk, which is defined in turn based on E⁡[ln⁡πk], E⁡[ln⁡|Λk|], and Eμk,Λk[(𝐱n−μk)TΛk(𝐱n−μk)]. Now that we have determined the distributions over which these expectations are taken, we can derive formulas for them:

Eμk,Λk[(𝐱n−μk)TΛk(𝐱n−μk)]=Dβk−1+νk(𝐱n−𝐦k)T𝐖k(𝐱n−𝐦k)ln⁡Λ~k≡E⁡[ln⁡|Λk|]=∑i=1Dψ(νk+1−i2)+Dln⁡2+ln⁡|𝐖k|ln⁡π~k≡E⁡[ln⁡|πk|]=ψ(αk)−ψ(∑i=1Kαi)

These results lead to

rnk∝π~kΛ~k1/2exp⁡{−D2βk−νk2(𝐱n−𝐦k)T𝐖k(𝐱n−𝐦k)}

These can be converted from proportional to absolute values by normalizing over k so that the corresponding values sum to 1.

Note that:

1. The update equations for the parameters βk, 𝐦k, 𝐖k and νk of the variables μk and Λk depend on the statistics Nk, 𝐱¯k, and 𝐒k, and these statistics in turn depend on rnk.
2. The update equations for the parameters α1…K of the variable π depend on the statistic Nk, which depends in turn on rnk.
3. The update equation for rnk has a direct circular dependence on βk, 𝐦k, 𝐖k and νk as well as an indirect circular dependence on 𝐖k, νk and α1…K through π~k and Λ~k.

This suggests an iterative procedure that alternates between two steps:

1. An E-step that computes the value of rnk using the current values of all the other parameters.
2. An M-step that uses the new value of rnk to compute new values of all the other parameters.

Note that these steps correspond closely with the standard EM algorithm to derive a maximum likelihood or maximum a posteriori (MAP) solution for the parameters of a Gaussian mixture model. The responsibilities rnk in the E step correspond closely to the posterior probabilities of the latent variables given the data, i.e. p(𝐙∣𝐗); the computation of the statistics Nk, 𝐱¯k, and 𝐒k corresponds closely to the computation of corresponding "soft-count" statistics over the data; and the use of those statistics to compute new values of the parameters corresponds closely to the use of soft counts to compute new parameter values in normal EM over a Gaussian mixture model.

## Exponential-family distributions

Note that in the previous example, once the distribution over unobserved variables was assumed to factorize into distributions over the "parameters" and distributions over the "latent data", the derived "best" distribution for each variable was in the same family as the corresponding prior distribution over the variable. This is a general result that holds true for all prior distributions derived from the exponential family.

## See also

* Variational message passing: a modular algorithm for variational Bayesian inference.
* Variational autoencoder: an artificial neural network belonging to the families of probabilistic graphical models and Variational Bayesian methods.
* Expectation–maximization algorithm: a related approach which corresponds to a special case of variational Bayesian inference.
* Generalized filtering: a variational filtering scheme for nonlinear state space models.
* Calculus of variations: the field of mathematical analysis that deals with maximizing or minimizing functionals.
* Maximum entropy discrimination: This is a variational inference framework that allows for introducing and accounting for additional large-margin constraints[7]

## References

1. ↑ 1.0 1.1 1.2 1.3 Tran, Viet Hung (2018). "Copula Variational Bayes inference via information geometry". arXiv:1803.10998 [cs.IT].
2. ↑ 2.0 2.1 Adamčík, Martin (2014). "The Information Geometry of Bregman Divergences and Some Applications in Multi-Expert Reasoning". Entropy 16 (12): 6338–6381. doi:10.3390/e16126338. Bibcode: 2014Entrp..16.6338A.
3. ↑ 3.0 3.1 3.2 Nguyen, Duy (15 August 2023). "An in Depth Introduction to Variational Bayes Note". doi:10.2139/ssrn.4541076. https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4541076.
4. ↑ 4.0 4.1 4.2 Lee, Se Yoon (2021). "Gibbs sampler and coordinate ascent variational inference: A set-theoretical review". Communications in Statistics - Theory and Methods 51 (6): 1–21. doi:10.1080/03610926.2021.1921214.
5. ↑ Boyd, Stephen P.; Vandenberghe, Lieven (2004). Convex Optimization. Cambridge University Press. ISBN 978-0-521-83378-3. https://web.stanford.edu/~boyd/cvxbook/bv_cvxbook.pdf. Retrieved October 15, 2011.
6. ↑ Bishop, Christopher M. (2006). "Chapter 10". Pattern Recognition and Machine Learning. Springer. ISBN 978-0-387-31073-2.
7. ↑ Sotirios P. Chatzis, “Infinite Markov-Switching Maximum Entropy Discrimination Machines,” Proc. 30th International Conference on Machine Learning (ICML). Journal of Machine Learning Research: Workshop and Conference Proceedings, vol. 28, no. 3, pp. 729–737, June 2013.

## External links

* The on-line textbook: Information Theory, Inference, and Learning Algorithms , by David J.C. MacKay provides an introduction to variational methods (p. 422).
* A Tutorial on Variational Bayes. Fox, C. and Roberts, S. 2012. Artificial Intelligence Review, doi:10.1007/s10462-011-9236-8.
* Variational-Bayes Repository A repository of research papers, software, and links related to the use of variational methods for approximate Bayesian learning up to 2003.
* Variational Algorithms for Approximate Bayesian Inference, by M. J. Beal includes comparisons of EM to Variational Bayesian EM and derivations of several models including Variational Bayesian HMMs.
* High-Level Explanation of Variational Inference by Jason Eisner may be worth reading before a more mathematically detailed treatment.
* Copula Variational Bayes inference via information geometry (pdf) by Tran, V.H. 2018. This paper is primarily written for students. Via Bregman divergence, the paper shows that Variational Bayes is simply a generalized Pythagorean projection of true model onto an arbitrarily correlated (copula) distributional space, of which the independent space is merely a special case.
* An in depth introduction to Variational Bayes note. Nguyen, D. 2023

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Variational Bayesian methods. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Variational_Bayesian_methods&oldid=4150449"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template