Evidence lower bound

From HandWiki
Short description: Lower bound on the log-likelihood of some observed data

In variational Bayesian methods, the evidence lower bound (often abbreviated ELBO, also sometimes called the variational lower bound[1] or negative variational free energy) is a useful lower bound on the log-likelihood of some observed data.

Definition

Let [math]\displaystyle{ X }[/math] and [math]\displaystyle{ Z }[/math] be random variables, jointly distributed with distribution [math]\displaystyle{ p_\theta }[/math]. For example, [math]\displaystyle{ p_\theta( X) }[/math] is the marginal distribution of [math]\displaystyle{ X }[/math], and [math]\displaystyle{ p_\theta( Z \mid X) }[/math] is the conditional distribution of [math]\displaystyle{ Z }[/math] given [math]\displaystyle{ X }[/math]. Then, for a sample [math]\displaystyle{ x\sim p_\theta }[/math], and any distribution [math]\displaystyle{ q_\phi }[/math], the ELBO is defined as[math]\displaystyle{ L(\phi, \theta; x) := \mathbb E_{z\sim q_\phi(\cdot | x)} \left[ \ln\frac{p_\theta(x, z)}{q_\phi(z|x)} \right] . }[/math]The ELBO can equivalently be written as[2]

[math]\displaystyle{ \begin{align} L(\phi, \theta; x) = & \mathbb E_{z\sim q_\phi(\cdot | x)}\left[ \ln{} p_\theta(x, z) \right] + H[ q_\phi(z|x) ] \\ = & \mathbb \ln{} \,p_\theta(x) - D_{KL}( q_\phi(z|x) || p_\theta(z|x) ) . \\ \end{align} }[/math]

In the first line, [math]\displaystyle{ H[ q_\phi(z|x) ] }[/math] is the entropy of [math]\displaystyle{ q_\phi }[/math], which relates the ELBO to the Helmholtz free energy.[3] In the second line, [math]\displaystyle{ \ln p_\theta(x) }[/math] is called the evidence for [math]\displaystyle{ x }[/math], and [math]\displaystyle{ D_{KL}( q_\phi(z|x) || p_\theta(z|x) ) }[/math] is the Kullback-Leibler divergence between [math]\displaystyle{ q_\phi }[/math] and [math]\displaystyle{ p_\theta }[/math]. Since the Kullback-Leibler divergence is non-negative, [math]\displaystyle{ L(\phi, \theta; x) }[/math] forms a lower bound on the evidence (ELBO inequality)[math]\displaystyle{ \ln p_\theta(x) \ge \mathbb \mathbb E_{z\sim q_\phi(\cdot|x)}\left[ \ln\frac{p_\theta(x, z)}{q_\phi(z\vert x)} \right]. }[/math]

Motivation

Variational Bayesian inference

Suppose we have an observable random variable [math]\displaystyle{ X }[/math], and we want to find its true distribution [math]\displaystyle{ p^* }[/math]. This would allow us to generate data by sampling, and estimate probabilities of future events. In general, it is impossible to find [math]\displaystyle{ p^* }[/math] exactly, forcing us to search for a good approximation.

That is, we define a sufficiently large parametric family [math]\displaystyle{ \{p_\theta\}_{\theta\in\Theta} }[/math] of distributions, then solve for [math]\displaystyle{ \min_\theta L(p_\theta, p^*) }[/math] for some loss function [math]\displaystyle{ L }[/math]. One possible way to solve this is by considering small variation from [math]\displaystyle{ p_\theta }[/math] to [math]\displaystyle{ p_{\theta + \delta \theta} }[/math], and solve for [math]\displaystyle{ L(p_\theta, p^*) - L(p_{\theta+\delta \theta}, p^*) =0 }[/math]. This is a problem in the calculus of variations, thus it is called the variational method.

Since there are not many explicitly parametrized distribution families (all the classical distribution families, such as the normal distribution, the Gumbel distribution, etc, are far too simplistic to model the true distribution), we consider implicitly parametrized probability distributions:

  • First, define a simple distribution [math]\displaystyle{ p(z) }[/math] over a latent random variable [math]\displaystyle{ Z }[/math]. Usually a normal distribution or a uniform distribution suffices.
  • Next, define a family of complicated functions [math]\displaystyle{ f_\theta }[/math] (such as a deep neural network) parametrized by [math]\displaystyle{ \theta }[/math].
  • Finally, define a way to convert any [math]\displaystyle{ f_\theta(z) }[/math] into a simple distribution over the observable random variable [math]\displaystyle{ X }[/math]. For example, let [math]\displaystyle{ f_\theta(z) = (f_1(z), f_2(z)) }[/math] have two outputs, then we can define the corresponding distribution over [math]\displaystyle{ X }[/math] to be the normal distribution [math]\displaystyle{ \mathcal N(f_1(z), e^{f_2(z)}) }[/math].

This defines a family of joint distributions [math]\displaystyle{ p_\theta }[/math] over [math]\displaystyle{ (X, Z) }[/math]. It is very easy to sample [math]\displaystyle{ (x, z) \sim p_\theta }[/math]: simply sample [math]\displaystyle{ z\sim p }[/math], then compute [math]\displaystyle{ f_\theta(z) }[/math], and finally sample [math]\displaystyle{ x \sim p_\theta(\cdot | z) }[/math] using [math]\displaystyle{ f_\theta(z) }[/math].

In other words, we have a generative model for both the observable and the latent. Now, we consider a distribution [math]\displaystyle{ p_\theta }[/math] good, if it is a close approximation of [math]\displaystyle{ p^* }[/math]:[math]\displaystyle{ p_\theta(X) \approx p^*(X) }[/math]since the distribution on the right side is over [math]\displaystyle{ X }[/math] only, the distribution on the left side must marginalize the latent variable [math]\displaystyle{ Z }[/math] away.
In general, it's impossible to perform the integral [math]\displaystyle{ p_\theta(x) = \int p_\theta(x|z)p(z)dz }[/math], forcing us to perform another approximation.

Since [math]\displaystyle{ p_\theta(x) = \frac{p_\theta(x|z)p(z)}{p_\theta(z|x)} }[/math], it suffices to find a good approximation of [math]\displaystyle{ p_\theta(z|x) }[/math]. So define another distribution family [math]\displaystyle{ q_\phi(z|x) }[/math] and use it to approximate [math]\displaystyle{ p_\theta(z|x) }[/math]. This is a discriminative model for the latent.

The entire situation is summarized in the following table:

[math]\displaystyle{ X }[/math]: observable [math]\displaystyle{ X, Z }[/math] [math]\displaystyle{ Z }[/math]: latent
[math]\displaystyle{ p^*(x)\approx p_\theta(x) \approx \frac{p_\theta(x|z)p(z)}{q_\phi(z|x)} }[/math] approximable [math]\displaystyle{ p(z) }[/math], easy
[math]\displaystyle{ p_\theta(x|z)p(z) }[/math], easy
[math]\displaystyle{ p_\theta(z|x) \approx q_\phi(z|x) }[/math] approximable [math]\displaystyle{ p_\theta(x|z) }[/math], easy

In Bayesian language, [math]\displaystyle{ X }[/math] is the observed evidence, and [math]\displaystyle{ Z }[/math] is the latent/unobserved. The distribution [math]\displaystyle{ p }[/math] over [math]\displaystyle{ Z }[/math] is the prior distribution over [math]\displaystyle{ Z }[/math], [math]\displaystyle{ p_\theta(x|z) }[/math] is the likelihood function, and [math]\displaystyle{ p_\theta(z|x) }[/math] is the posterior distribution over [math]\displaystyle{ Z }[/math].

Given an observation [math]\displaystyle{ x }[/math], we can infer what [math]\displaystyle{ z }[/math] likely gave rise to [math]\displaystyle{ x }[/math] by computing [math]\displaystyle{ p_\theta(z|x) }[/math]. The usual Bayesian method is to estimate the integral [math]\displaystyle{ p_\theta(x) = \int p_\theta(x|z)p(z)dz }[/math], then compute by Bayes' rule [math]\displaystyle{ p_\theta(z|x) = \frac{p_\theta(x|z)p(z)}{p_\theta(x)} }[/math]. This is expensive to perform in general, but if we can simply find a good approximation [math]\displaystyle{ q_\phi(z|x) \approx p_\theta(z|x) }[/math] for most [math]\displaystyle{ x, z }[/math], then we can infer [math]\displaystyle{ z }[/math] from [math]\displaystyle{ x }[/math] cheaply. Thus, the search for a good [math]\displaystyle{ q_\phi }[/math] is also called amortized inference.

All in all, we have found a problem of variational Bayesian inference.

Deriving the ELBO

A basic result in variational inference is that minimizing the Kullback–Leibler divergence (KL-divergence) is equivalent to maximizing the log-likelihood:[math]\displaystyle{ \mathbb{E}_{x\sim p^*(x)}[\ln p_\theta (x)] = -H(p^*) - D_{\mathit{KL}}(p^*(x) \| p_\theta(x)) }[/math]where [math]\displaystyle{ H(p^*) = -\mathbb \mathbb E_{x\sim p^*}[\ln p^*(x)] }[/math] is the entropy of the true distribution. So if we can maximize [math]\displaystyle{ \mathbb{E}_{x\sim p^*(x)}[\ln p_\theta (x)] }[/math], we can minimize [math]\displaystyle{ D_{\mathit{KL}}(p^*(x) \| p_\theta(x)) }[/math], and consequently find an accurate approximation [math]\displaystyle{ p_\theta \approx p^* }[/math].

To maximize [math]\displaystyle{ \mathbb{E}_{x\sim p^*(x)}[\ln p_\theta (x)] }[/math], we simply sample many [math]\displaystyle{ x_i\sim p^*(x) }[/math], i.e. use Importance sampling[math]\displaystyle{ N\max_\theta \mathbb{E}_{x\sim p^*(x)}[\ln p_\theta (x)]\approx \max_\theta \sum_i \ln p_\theta (x_i) }[/math][note 1]

In order to maximize [math]\displaystyle{ \sum_i \ln p_\theta (x_i) }[/math], it's necessary to find [math]\displaystyle{ \ln p_\theta(x) }[/math]:[math]\displaystyle{ \ln p_\theta(x) = \ln \int p_\theta(x|z) p(z)dz }[/math]This usually has no closed form and must be estimated. The usual way to estimate integrals is Monte Carlo integration with importance sampling:[math]\displaystyle{ \int p_\theta(x|z) p(z)dz = \mathbb E_{z\sim q_\phi(\cdot|x)}\left[\frac{p_\theta (x, z)}{q_\phi(z|x)}\right] }[/math]where [math]\displaystyle{ q_\phi(z|x) }[/math] is a sampling distribution over [math]\displaystyle{ z }[/math] that we use to perform the Monte Carlo integration.

So we see that if we sample [math]\displaystyle{ z\sim q_\phi(\cdot|x) }[/math], then [math]\displaystyle{ \frac{p_\theta (x, z)}{q_\phi(z|x)} }[/math] is an unbiased estimator of [math]\displaystyle{ p_\theta(x) }[/math]. Unfortunately, this does not give us an unbiased estimator of [math]\displaystyle{ \ln p_\theta(x) }[/math], because [math]\displaystyle{ \ln }[/math] is nonlinear. Indeed, we have by Jensen's inequality, [math]\displaystyle{ \ln p_\theta(x)= \ln \mathbb E_{z\sim q_\phi(\cdot|x)}\left[\frac{p_\theta (x, z)}{q_\phi(z|x)}\right] \geq \mathbb E_{z\sim q_\phi(\cdot|x)}\left[\ln\frac{p_\theta (x, z)}{q_\phi(z|x)}\right] }[/math]In fact, all the obvious estimators of [math]\displaystyle{ \ln p_\theta(x) }[/math] are biased downwards, because no matter how many samples of [math]\displaystyle{ z_i\sim q_\phi(\cdot | x) }[/math] we take, we have by Jensen's inequality:[math]\displaystyle{ \mathbb E_{z_i \sim q_\phi(\cdot|x)}\left[ \ln \left(\frac 1N \sum_i \frac{p_\theta (x, z_i)}{q_\phi(z_i|x)}\right) \right] \leq \ln \mathbb E_{z_i \sim q_\phi(\cdot|x)}\left[ \frac 1N \sum_i \frac{p_\theta (x, z_i)}{q_\phi(z_i|x)} \right] = \ln p_\theta(x) }[/math]Subtracting the right side, we see that the problem comes down to a biased estimator of zero:[math]\displaystyle{ \mathbb E_{z_i \sim q_\phi(\cdot|x)}\left[ \ln \left(\frac 1N \sum_i \frac{p_\theta (z_i|x)}{q_\phi(z_i|x)}\right) \right] \leq 0 }[/math]By the delta method, we have[math]\displaystyle{ \mathbb E_{z_i \sim q_\phi(\cdot|x)}\left[ \ln \left(\frac 1N \sum_i \frac{p_\theta (z_i|x)}{q_\phi(z_i|x)}\right) \right] \approx -\frac{1}{2N} \mathbb V_{z \sim q_\phi(\cdot|x)}\left[\frac{p_\theta (z|x)}{q_\phi(z|x)}\right] = O(N^{-1}) }[/math]If we continue with this, we would obtain the importance-weighted autoencoder.[4] But we return to the simplest case with [math]\displaystyle{ N=1 }[/math]:[math]\displaystyle{ \ln p_\theta(x)= \ln \mathbb E_{z\sim q_\phi(\cdot|x)}\left[\frac{p_\theta (x, z)}{q_\phi(z|x)}\right] \geq \mathbb E_{z\sim q_\phi(\cdot|x)}\left[\ln\frac{p_\theta (x, z)}{q_\phi(z|x)}\right] }[/math]The tightness of the inequality has a closed form:[math]\displaystyle{ \ln p_\theta(x)- \mathbb E_{z\sim q_\phi(\cdot|x)}\left[\ln\frac{p_\theta (x, z)}{q_\phi(z|x)}\right] = D_{\mathit{KL}}(q_\phi(\cdot | x)\| p_\theta(\cdot | x))\geq 0 }[/math]We have thus obtained the ELBO function:[math]\displaystyle{ L(\phi, \theta; x) := \ln p_\theta(x) - D_{\mathit{KL}}(q_\phi(\cdot | x)\| p_\theta(\cdot | x)) }[/math]

Maximizing the ELBO

For fixed [math]\displaystyle{ x }[/math], the optimization [math]\displaystyle{ \max_{\theta, \phi} L(\phi, \theta; x) }[/math] simultaneously attempts to maximize [math]\displaystyle{ \ln p_\theta(x) }[/math] and minimize [math]\displaystyle{ D_{\mathit{KL}}(q_\phi(\cdot | x)\| p_\theta(\cdot | x)) }[/math]. If the parametrization for [math]\displaystyle{ p_\theta }[/math] and [math]\displaystyle{ q_\phi }[/math] are flexible enough, we would obtain some [math]\displaystyle{ \hat\phi, \hat \theta }[/math], such that we have simultaneously

[math]\displaystyle{ \ln p_{\hat \theta}(x) \approx \max_\theta \ln p_\theta(x); \quad q_{\hat\phi}(\cdot | x)\approx p_{\hat\theta}(\cdot | x) }[/math]Since[math]\displaystyle{ \mathbb{E}_{x\sim p^*(x)}[\ln p_\theta (x)] = -H(p^*) - D_{\mathit{KL}}(p^*(x) \| p_\theta(x)) }[/math]we have[math]\displaystyle{ \ln p_{\hat \theta}(x) \approx \max_\theta -H(p^*) - D_{\mathit{KL}}(p^*(x) \| p_\theta(x)) }[/math]and so[math]\displaystyle{ \hat\theta \approx \arg\min D_{\mathit{KL}}(p^*(x) \| p_\theta(x)) }[/math]In other words, maximizing the ELBO would simultaneously allow us to obtain an accurate generative model [math]\displaystyle{ p_{\hat\theta} \approx p^* }[/math] and an accurate discriminative model [math]\displaystyle{ q_{\hat\phi}(\cdot | x)\approx p_{\hat\theta}(\cdot | x) }[/math].[5]

Main forms

The ELBO has many possible expressions, each with some different emphasis.

[math]\displaystyle{ \mathbb{E}_{z\sim q_\phi(\cdot | x)}\left[\ln\frac{p_\theta(x, z)}{q_\phi(z|x)}\right] = \int q_\phi(z|x)\ln\frac{p_\theta(x, z)}{q_\phi(z|x)}dz }[/math]

This form shows that if we sample [math]\displaystyle{ z\sim q_\phi(\cdot | x) }[/math], then [math]\displaystyle{ \ln\frac{p_\theta(x, z)}{q_\phi(z|x)} }[/math] is an unbiased estimator of the ELBO.

[math]\displaystyle{ \ln p_\theta(x) - D_{\mathit{KL}}(q_\phi(\cdot | x) \;\|\; p_\theta(\cdot | x)) }[/math]

This form shows that the ELBO is a lower bound on the evidence [math]\displaystyle{ \ln p_\theta(x) }[/math], and that maximizing the ELBO with respect to [math]\displaystyle{ \phi }[/math] is equivalent to minimizing the KL-divergence from [math]\displaystyle{ p_\theta(\cdot | x) }[/math] to [math]\displaystyle{ q_\phi(\cdot | x) }[/math].

[math]\displaystyle{ \mathbb{E}_{z\sim q_\phi(\cdot | x)}[\ln p_\theta(x|z)] - D_{\mathit{KL}}(q_\phi(\cdot | x) \;\|\; p) }[/math]

This form shows that maximizing the ELBO simultaneously attempts to keep [math]\displaystyle{ q_\phi(\cdot | x) }[/math] close to [math]\displaystyle{ p }[/math] and concentrate [math]\displaystyle{ q_\phi(\cdot | x) }[/math] on those [math]\displaystyle{ z }[/math] that maximizes [math]\displaystyle{ \ln p_\theta (x|z) }[/math]. That is, the approximate posterior [math]\displaystyle{ q_\phi(\cdot | x) }[/math] balances between staying close to the prior [math]\displaystyle{ p }[/math] and moving towards the maximum likelihood [math]\displaystyle{ \arg\max_z \ln p_\theta (x|z) }[/math].

[math]\displaystyle{ H(q_\phi(\cdot | x)) + \mathbb{E}_{z\sim q(\cdot | x)}[\ln p_\theta(z|x)] + \ln p_\theta(x) }[/math]

This form shows that maximizing the ELBO simultaneously attempts to keep the entropy of [math]\displaystyle{ q_\phi(\cdot | x) }[/math] high, and concentrate [math]\displaystyle{ q_\phi(\cdot | x) }[/math] on those [math]\displaystyle{ z }[/math] that maximizes [math]\displaystyle{ \ln p_\theta (z|x) }[/math]. That is, the approximate posterior [math]\displaystyle{ q_\phi(\cdot | x) }[/math] balances between being a uniform distribution and moving towards the maximum a posteriori [math]\displaystyle{ \arg\max_z \ln p_\theta (z|x) }[/math].

Data-processing inequality

Suppose we take [math]\displaystyle{ N }[/math] independent samples from [math]\displaystyle{ p^* }[/math], and collect them in the dataset [math]\displaystyle{ D = \{x_1, ..., x_N\} }[/math], then we have empirical distribution [math]\displaystyle{ q_D(x) = \frac 1N \sum_i \delta_{x_i} }[/math].


Fitting [math]\displaystyle{ p_\theta(x) }[/math] to [math]\displaystyle{ q_D(x) }[/math] can be done, as usual, by maximizing the loglikelihood [math]\displaystyle{ \ln p_\theta(D) }[/math]:[math]\displaystyle{ D_{\mathit{KL}}(q_D(x) \| p_\theta(x)) = -\frac 1N \sum_i \ln p_\theta(x_i) - H(q_D)= -\frac 1N \ln p_\theta(D) - H(q_D) }[/math]Now, by the ELBO inequality, we can bound [math]\displaystyle{ \ln p_\theta(D) }[/math], and thus[math]\displaystyle{ D_{\mathit{KL}}(q_D(x) \| p_\theta(x)) \leq -\frac 1N L(\phi, \theta; D) - H(q_D) }[/math]The right-hand-side simplifies to a KL-divergence, and so we get:[math]\displaystyle{ D_{\mathit{KL}}(q_D(x) \| p_\theta(x)) \leq -\frac 1N \sum_i L(\phi, \theta; x_i) - H(q_D)= D_{\mathit{KL}}(q_{D, \phi}(x, z); p_\theta(x, z)) }[/math]This result can be interpreted as a special case of the data processing inequality.

In this interpretation, maximizing [math]\displaystyle{ L(\phi, \theta; D)= \sum_i L(\phi, \theta; x_i) }[/math] is minimizing [math]\displaystyle{ D_{\mathit{KL}}(q_{D, \phi}(x, z); p_\theta(x, z)) }[/math], which upper-bounds the real quantity of interest [math]\displaystyle{ D_{\mathit{KL}}(q_{D}(x); p_\theta(x)) }[/math] via the data-processing inequality. That is, we append a latent space to the observable space, paying the price of a weaker inequality for the sake of more computationally efficient minimization of the KL-divergence.[6]

References

  1. Kingma, Diederik P.; Welling, Max (2014-05-01). "Auto-Encoding Variational Bayes". arXiv:1312.6114 [stat.ML].
  2. Goodfellow, Ian; Bengio, Yoshua; Courville, Aaron (2016). "Chapter 19". Deep learning. Adaptive computation and machine learning. Cambridge, Mass: The MIT press. ISBN 978-0-262-03561-3. 
  3. Hinton, Geoffrey E; Zemel, Richard (1993). "Autoencoders, Minimum Description Length and Helmholtz Free Energy". Advances in Neural Information Processing Systems (Morgan-Kaufmann) 6. https://proceedings.neurips.cc/paper/1993/hash/9e3cfc48eccf81a0d57663e129aef3cb-Abstract.html. 
  4. Burda, Yuri; Grosse, Roger; Salakhutdinov, Ruslan (2015-09-01). "Importance Weighted Autoencoders". arXiv:1509.00519 [stat.ML].
  5. Neal, Radford M.; Hinton, Geoffrey E. (1998), "A View of the Em Algorithm that Justifies Incremental, Sparse, and other Variants", Learning in Graphical Models (Dordrecht: Springer Netherlands): pp. 355–368, doi:10.1007/978-94-011-5014-9_12, ISBN 978-94-010-6104-9, http://dx.doi.org/10.1007/978-94-011-5014-9_12 
  6. Kingma, Diederik P.; Welling, Max (2019-11-27). "An Introduction to Variational Autoencoders" (in English). Foundations and Trends in Machine Learning 12 (4): Section 2.7. doi:10.1561/2200000056. ISSN 1935-8237. https://www.nowpublishers.com/article/Details/MAL-056. 

Notes

  1. In fact, by Jensen's inequality, [math]\displaystyle{ \mathbb E_{x\sim p^{*}(x)}\left[\max _{\theta }\sum _{i}\ln p_{\theta }(x_{i})\right]\geq \max _{\theta }\mathbb E_{x\sim p^{*}(x)}\left[\sum _{i}\ln p_{\theta }(x_{i})\right]=N\max _{\theta }\mathbb {E} _{x\sim p^{*}(x)}[\ln p_{\theta }(x)] }[/math] The estimator is biased upwards. This can be seen as overfitting: for some finite set of sampled data [math]\displaystyle{ x_{i} }[/math] , there is usually some [math]\displaystyle{ \theta }[/math] that fits them better than the entire [math]\displaystyle{ p^{*} }[/math] distribution.