![]() | ||
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 is typical in Bayesian inference, the parameters and latent variables are grouped together as "unobserved variables". Variational Bayesian methods are primarily used for two purposes:
Contents
- Mathematical derivation of the mean field approximation
- In practice
- A basic example
- The mathematical model
- The joint probability
- Factorized approximation
- Derivation of q
- Algorithm for computing the parameters
- Step by step recipe
- Most important points
- Compared with expectation maximization EM
- A more complex example
- Exponential family distributions
- References
- To provide an analytical approximation to the posterior probability of the unobserved variables, in order to do statistical inference over these variables.
- 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 directly evaluate or sample from. 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 EM (expectation-maximization) algorithm from maximum a posteriori estimation (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 iteratively update the parameters 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 of the mean-field approximation
In variational inference, the posterior distribution over a set of unobserved variables
The distribution
The most common type of variational Bayes, known as mean-field variational Bayes, uses the Kullback–Leibler divergence (KL-divergence) of P from Q as the choice of dissimilarity function. This choice makes this minimization tractable. The KL-divergence is defined as
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.)
The KL-divergence can be written as
or
As the log evidence
In practice
The variational distribution
It can be shown using the calculus of variations (hence the name "variational Bayes") that the "best" distribution
where
In practice, we usually work in terms of logarithms, i.e.:
The constant in the above expression is related to the normalizing constant (the denominator in the expression above for
Using the properties of expectations, the expression
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 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. 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 variance, i.e. the mean also follows a Gaussian distribution while the precision follows a gamma distribution. In other words:
We are given
The hyperparameters
The joint probability
The joint probability of all variables can be rewritten as
where the individual factors are
where
Factorized approximation
Assume that
Derivation of q(μ)
Then
In the above derivation,
The last line is simply a quadratic polynomial in
With a certain amount of tedious math (expanding the squares inside of the braces, separating out and grouping the terms involving
Note that all of the above steps can be shortened by using the formula for the sum of two quadratics.
In other words:
Derivation of q(τ)
The derivation of
Exponentiating both sides, we can see that
Algorithm for computing the parameters
Let us recap the conclusions from the previous sections:
and
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:
Applying these formulas to the above equations is trivial in most cases, but the equation for
We can then write the parameter equations as follows, without any expectations:
Note that there are circular dependencies among the formulas for
- Compute
∑ n = 1 N x n ∑ n = 1 N x n 2 . Use these values to computeμ N a N . - Initialize
λ N - Use the current value of
λ N , along with the known values of the other parameters, to computeb N - Use the current value of
b N , along with the known values of the other parameters, to computeλ N - 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.
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:
- Describe the network with a graphical model, identifying the observed variables (data)
X and unobserved variables (parametersΘ and latent variablesZ ) and their conditional probability distributions. Variational Bayes will then construct an approximation to the posterior probabilityp ( Z , Θ ∣ X ) . 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. - 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
Z 1 , … , Z M - For a given partition
Z j q j ∗ ( Z j ∣ X ) using the basic equationln q j ∗ ( Z j ∣ X ) = E i ≠ j [ ln p ( Z , X ) ] + constant . - 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
Z j - 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
Z j - 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.
- 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.
- 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.
- 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:
- 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.
- "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.
- 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.
A more complex example
Imagine a Bayesian Gaussian mixture model described as follows:
Note:
The interpretation of the above variables is as follows:
The joint probability of all variables can be rewritten as
where the individual factors are
where
Assume that
Then
where we have defined
Exponentiating both sides of the formula for
Requiring that this be normalized ends up requiring that the
where
In other words,
Furthermore, we note that
which is a standard result for categorical distributions.
Now, considering the factor
Then,
Taking the exponential of both sides, we recognize
where
where
Finally
Grouping and reading off terms involving
given the definitions
Finally, notice that these functions require the values of
These results lead to
These can be converted from proportional to absolute values by normalizing over
Note that:
- The update equations for the parameters
β k m k W k ν k μ k Λ k N k x ¯ k S k r n k - The update equations for the parameters
α 1 … K π depend on the statisticN k r n k - The update equation for
r n k β k m k W k ν k W k ν k α 1 … K π ~ k Λ ~ k
This suggests an iterative procedure that alternates between two steps:
- An E-step that computes the value of
r n k - An M-step that uses the new value of
r n k
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
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.