Variational inference
In this post, I will present a high-level explanation of variational inference: a paradigm for estimating a posterior distribution when computing it explicitly is intractable. Variational inference finds an approximate posterior by solving a specific optimization problem that seeks to minimize the disparity between the true posterior and the approximate posterior.
Introduction
Variational inference is a high-level paradigm for estimating a posterior distribution when computing it explicitly is intractable. More specifically, variational inference is used in situations in which we have a model that involves hidden random variables , observed data , and some posited probabilistic model over the hidden and observed random variables . Our goal is to compute the posterior distribution . Under an ideal situation, we would do so by using Bayes theorem:
where and are realizations of and respectively and are probability mass/density functions for the distributions implied by their arguments.
In practice, it is often difficult to compute via Bayes theorem because the denominator does not have a closed form. Usually, the denominator can be only be expressed as an integral that marginalizes over : . In such scenarios, we’re often forced to approximate rather than compute it directly. Variational inference is one such approximation technique.
Intuition
Instead of computing exactly via Bayes theorem, variational inference attempts to find another distribution that is ``close” to (how we define “closeness” between distributions will be addressed later in this post). Ideally, is easier to evaluate than , and, if and are similar, then we can use as a replacement for for any relevant downstream tasks.
We restrict our search for to a family of surrogate distributions over , called the variational distribution family, denoted by the set of distributions . Our goal then is to find the distribution that makes as ``close” to as possible. When, each member of is characterized by the values of a set of parameters , we call the variational parameters. Our goal is then to find the value for that makes as close to as possible and return as our approximation of the true posterior.
Details
Variational inference uses the KL-divergence from to as a measure of ``closeness” between these two distributions:
Thus, variational inference attempts to find
and then returns as the approximation to the posterior.
Variational inference minimizes the KL-divergence by maximizing a surrogate quantity called the evidence lower bound (ELBO) (For a more in-depth discussion of the evidence lower bound, you can check out my previous blog post):
That is, we can formulate an optimization problem that seeks to maximize the ELBO:
The solution to this optimization problem is equivalent to the solution that minimizes the KL-divergence between and . To see why this works, we can show that the KL-divergence can be formulated as the difference between the marginal log-likelihood of the observed data, (called the evidence) and the ELBO:
Because does not depend on , one can treat the ELBO as a function of and maximize the ELBO.
Conceptually, variational inference allows us to formulate our approximate Bayesian inference problem as an optimization problem. By formulating the problem as such, we can approach this optimization problem using the full toolkit available to us from the field of mathematical optimization!
Why is this method called “variational” inference?
The term “variational” in “variational inference” comes from the mathematical area of the calculus of variations. The calculus of variations is all about optimization problems that optimize functions of functions, called functionals.
More specifically, let’s say we have some set of functions where each maps items from some set to some set . That is,
Let’s say we have some function that maps functions in to real numbers . That is,
Then, we may wish to solve an optimization problem of the form:
This is precisely the problem addressed in the calculus of variations. In the case of variational inference, the functional, , that we are optimzing is the ELBO. The set of functions, , that we are searching over is the set of measureable functions in the variational family, .