ArcVisualExplain a paper
stat.MLcs.LGarXiv 1312.6114

Auto-Encoding Variational Bayes

Diederik P Kingma, Max Welling

How can we perform efficient inference and learning in directed probabilistic models, in the presence of continuous latent variables with intractable posterior distributions, and large datasets? We introduce a stochastic variational inference and learning algorithm that scales to large datasets and, under some mild differentiability conditions, even works in the intractable case. Our contributions are two-fold. First, we show that a reparameterization of the variational lower bound yields a lower bound estimator that can be straightforwardly optimized using standard stochastic gradient methods. Second, we show that for i.i.d. datasets with continuous latent variables per datapoint, posterior inference can be made especially efficient by fitting an approximate inference model (also called a recognition model) to the intractable posterior using the proposed lower bound estimator. Theoretical advantages are reflected in experimental results.

Open on arXivPDFFigures stay with the paper; we link to them

Introduction

In the paper
Difficulty 3 of 5

How can we perform efficient approximate inference and learning with directed probabilistic models whose continuous latent variables and/or parameters have intractable posterior distributions? The variational Bayesian (VB) approach involves the optimization of an approximation to the intractable posterior. Unfortunately, the common mean-field approach requires analytical solutions of expectations w.r.t. the approximate posterior, which are also intractable in the general case. We show how a reparameterization of the variational lower bound yields a simple differentiable unbiased estimator of the lower bound; this SGVB (Stochastic Gradient Variational Bayes) estimator can be used for efficient approximate posterior inference in almost any model with continuous latent variables and/or parameters, and is straightforward to optimize using standard stochastic gradient ascent techniques.

For the case of an i.i.d. dataset and continuous latent variables per datapoint, we propose the Auto-Encoding VB (AEVB) algorithm. In the AEVB algorithm we make inference and learning especially efficient by using the SGVB estimator to optimize a recognition model that allows us to perform very efficient approximate posterior inference using simple ancestral sampling, which in turn allows us to efficiently learn the model parameters, without the need of expensive iterative inference schemes (such as MCMC) per datapoint. The learned approximate posterior inference model can also be used for a host of tasks such as recognition, denoising, representation and visualization purposes. When a neural network is used for the recognition model, we arrive at the variational auto-encoder.

Difficulty 3 of 5

The strategy in this section can be used to derive a lower bound estimator (a stochastic objective function) for a variety of directed graphical models with continuous latent variables. We will restrict ourselves here to the common case where we have an i.i.d. dataset with latent variables per datapoint, and where we like to perform maximum likelihood (ML) or maximum a posteriori (MAP) inference on the (global) parameters, and variational inference on the latent variables. It is, for example, straightforward to extend this scenario to the case where we also perform variational inference on the global parameters; that algorithm is put in the appendix, but experiments with that case are left to future work. Note that our method can be applied to online, non-stationary settings, e.g. streaming data, but here we assume a fixed dataset for simplicity.

Problem scenario

In the paper
Difficulty 3 of 5

Let us consider some dataset X={x(i)}i=1N\bX = \{\bx^{(i)}\}_{i=1}^N consisting of NN i.i.d. samples of some continuous or discrete variable x\bx. We assume that the data are generated by some random process, involving an unobserved continuous random variable z\bz. The process consists of two steps: (1) a value z(i)\bzi is generated from some prior distribution pθ∗(z)p_{\bT^*}(\bz); (2) a value x(i)\bxi is generated from some conditional distribution pθ∗(x∣z)p_{\bT^*}(\bx|\bz). We assume that the prior pθ∗(z)p_{\bT^*}(\bz) and likelihood pθ∗(x∣z)p_{\bT^*}(\bx|\bz) come from parametric families of distributions pθ(z)\pT(\bz) and pθ(x∣z)\pT(\bx|\bz), and that their PDFs are differentiable almost everywhere w.r.t. both θ\bT and z\bz. Unfortunately, a lot of this process is hidden from our view: the true parameters θ∗\bT^* as well as the values of the latent variables z(i)\bzi are unknown to us.

Very importantly, we do not make the common simplifying assumptions about the marginal or posterior probabilities. Conversely, we are here interested in a general algorithm that even works efficiently in the case of:

Intractability: the case where the integral of the marginal likelihood pθ(x)=∫pθ(z)pθ(x∣z) dz\pT(\bx) = \int \pT(\bz) \pT(\bx|\bz) \,d\bz is intractable (so we cannot evaluate or differentiate the marginal likelihood), where the true posterior density pθ(z∣x)=pθ(x∣z)pθ(z)/pθ(x)\pT(\bz|\bx) = \pT(\bx|\bz)\pT(\bz)/\pT(\bx) is intractable (so the EM algorithm cannot be used), and where the required integrals for any reasonable mean-field VB algorithm are also intractable. These intractabilities are quite common and appear in cases of moderately complicated likelihood functions pθ(x∣z)\pT(\bx|\bz), e.g. a neural network with a nonlinear hidden layer. A large dataset: we have so much data that batch optimization is too costly; we would like to make parameter updates using small minibatches or even single datapoints. Sampling-based solutions, e.g. Monte Carlo EM, would in general be too slow, since it involves a typically expensive sampling loop per datapoint.

We are interested in, and propose a solution to, three related problems in the above scenario:

Efficient approximate ML or MAP estimation for the parameters θ\bT. The parameters can be of interest themselves, e.g. if we are analyzing some natural process. They also allow us to mimic the hidden random process and generate artificial data that resembles the real data. Efficient approximate posterior inference of the latent variable z\bz given an observed value x\bx for a choice of parameters θ\bT. This is useful for coding or data representation tasks. Efficient approximate marginal inference of the variable x\bx. This allows us to perform all kinds of inference tasks where a prior over x\bx is required. Common applications in computer vision include image denoising, inpainting and super-resolution.

For the purpose of solving the above problems, let us introduce a recognition model qϕ(z∣x)\qPhi(\bz|\bx): an approximation to the intractable true posterior pθ(z∣x)\pT(\bz|\bx). Note that in contrast with the approximate posterior in mean-field variational inference, it is not necessarily factorial and its parameters ϕ\bphi are not computed from some closed-form expectation. Instead, we'll introduce a method for learning the recognition model parameters ϕ\bphi jointly with the generative model parameters θ\bT.

From a coding theory perspective, the unobserved variables z\bz have an interpretation as a latent representation or code. In this paper we will therefore also refer to the recognition model qϕ(z∣x)\qPhi(\bz|\bx) as a probabilistic encoder, since given a datapoint x\bx it produces a distribution (e.g. a Gaussian) over the possible values of the code z\bz from which the datapoint x\bx could have been generated. In a similar vein we will refer to pθ(x∣z)\pT(\bx|\bz) as a probabilistic decoder, since given a code z\bz it produces a distribution over the possible corresponding values of x\bx.

The variational bound

In the paper
Difficulty 4 of 5Variational Lower BoundReparameterization Trick

The marginal likelihood is composed of a sum over the marginal likelihoods of individual datapoints log⁡pθ(x(1),⋯ ,x(N))=∑i=1Nlog⁡pθ(x(i))\log \pT(\bx^{(1)}, \cdots, \bx^{(N)}) = \sum_{i=1}^N \log \pT(\bxi), which can each be rewritten as:

log⁡pθ(x(i))=DKL(qϕ(z∣x(i))∣∣pθ(z∣x(i)))+L(θ,ϕ;x(i))\log \pT(\bxi) = D_{KL}(\qPhi(\bz|\bxi)||\pT(\bz|\bxi)) + \LB{}{\bxi} \eqnr

The first RHS term is the KL divergence of the approximate from the true posterior. Since this KL-divergence is non-negative, the second RHS term L(θ,ϕ;x(i))\LB{}{\bxi} is called the (variational) lower bound on the marginal likelihood of datapoint ii, and can be written as:

log⁡pθ(x(i))≥L(θ,ϕ;x(i))=Eqϕ(z∣x)[−log⁡qϕ(z∣x)+log⁡pθ(x,z)]\begin{aligned}\log \pT(\bxi) \geq \LB{}{\bxi} &= \Exp{\qPhi(\bz|\bx)}{- \log \qPhi(\bz|\bx) + \log \pT(\bx,\bz)} \eqnr\end{aligned}

which can also be written as:

L(θ,ϕ;x(i))=−DKL(qϕ(z∣x(i))∣∣pθ(z))+Eqϕ(z∣x(i))[log⁡pθ(x(i)∣z)]\LB{}{\bxi} = - D_{KL}(\qPhi(\bz|\bxi) || \pT(\bz)) + \Exp{\qPhi(\bz|\bxi)}{\log \pT(\bxi | \bz)} \eqnr

We want to differentiate and optimize the lower bound L(θ,ϕ;x(i))\LB{}{\bxi} w.r.t. both the variational parameters ϕ\bphi and generative parameters θ\bT. However, the gradient of the lower bound w.r.t. ϕ\bphi is a bit problematic. The usual (na\"ive) Monte Carlo gradient estimator for this type of problem is: ∇ϕEqϕ(z)[f(z)]=Eqϕ(z)[f(z)∇qϕ(z)log⁡qϕ(z)]≃1L∑l=1Lf(z)∇qϕ(z(l))log⁡qϕ(z(l))\nabla_{\bphi} \Exp{\qPhi(\bz)}{f(\bz)} = \Exp{\qPhi(\bz)}{f(\bz) \nabla_{\qPhi(\bz)} \log \qPhi(\bz) } \simeq \frac{1}{L} \sum_{l=1}^L f(\bz) \nabla_{\qPhi(\bzl)} \log \qPhi(\bzl) where z(l)∼qϕ(z∣x(i))\bzl \sim \qPhi(\bz|\bxi). This gradient estimator exhibits exhibits very high variance (see e.g. [cite]) and is impractical for our purposes.

We want to optimize the lower bound L(ξ) w.r.t. φ and θ.

0:00 / 0:22

Gradients can flow through a stochastic sampling node by reparameterizing the sample as a deterministic function of a fixed noise variable and the network parameters, rather than sampling directly from the parameterized distribution.

From the section “The variational bound”

Gradients can flow through a stochastic sampling node by reparameterizing the sample as a deterministic function of a fixed noise variable and the network parameters, rather than sampling directly from the parameterized distribution.

The SGVB estimator and AEVB algorithm

In the paper
Difficulty 4 of 5

In this section we introduce a practical estimator of the lower bound and its derivatives w.r.t. the parameters. We assume an approximate posterior in the form qϕ(z∣x)\qPhi(\bz|\bx), but please note that the technique can be applied to the case qϕ(z)\qPhi(\bz), i.e. where we do not condition on x\bx, as well. The fully variational Bayesian method for inferring a posterior over the parameters is given in the appendix.

Under certain mild conditions outlined in section [ref] for a chosen approximate posterior qϕ(z∣x)\qPhi(\bz|\bx) we can reparameterize the random variable z~∼qϕ(z∣x)\btz \sim \qPhi(\bz|\bx) using a differentiable transformation gϕ(ϵ,x)\gPhi(\beps,\bx) of an (auxiliary) noise variable ϵ\beps:

z~=gϕ(ϵ,x)with ϵ∼p(ϵ)\btz = \gPhi(\beps,\bx) \text{\quad with \quad} \beps \sim p(\beps) \eqnr

See section [ref] for general strategies for chosing such an approriate distribution p(ϵ)p(\beps) and function gϕ(ϵ,x)\gPhi(\beps,\bx). We can now form Monte Carlo estimates of expectations of some function f(z)f(\bz) w.r.t. qϕ(z∣x)\qPhi(\bz|\bx) as follows:

Eqϕ(z∣x(i))[f(z)]=Ep(ϵ)[f(gϕ(ϵ,x(i)))]≃1L∑l=1Lf(gϕ(ϵ(l),x(i)))where ϵ(l)∼p(ϵ)\begin{aligned}\Exp{\qPhi(\bz|\bxi)}{f(\bz)} = \Exp{p(\beps)}{f(\gPhi(\beps,\bxi))} &\simeq \frac{1}{L} \sum_{l=1}^L {f(\gPhi(\bepsl,\bxi))} \text{\quad where \quad} \bepsl \sim p(\beps)\end{aligned}

We apply this technique to the variational lower bound (eq. [ref]), yielding our generic Stochastic Gradient Variational Bayes (SGVB) estimator L~A(θ,ϕ;x(i))≃L(θ,ϕ;x(i))\LBT{A}{\bxi} \simeq \LB{}{\bxi}:

L~A(θ,ϕ;x(i))=1L∑l=1Llog⁡pθ(x(i),z(i,l))−log⁡qϕ(z(i,l)∣x(i))where z(i,l)=gϕ(ϵ(i,l),x(i))and ϵ(l)∼p(ϵ)\begin{aligned}\LBT{A}{\bxi} &= \frac{1}{L} \sum_{l=1}^L \log \pT(\bxi, \bzil) - \log \qPhi(\bzil|\bxi) \\ \text{where \quad} \bzil &= \gPhi(\bepsil,\bxi) \text{\quad and \quad} \bepsl \sim p(\beps) \eqnr\end{aligned}

Often, the KL-divergence DKL(qϕ(z∣x(i))∣∣pθ(z))D_{KL}(\qPhi(\bz|\bxi) || \pT(\bz)) of eq. [ref] can be integrated analytically (see appendix [ref]), such that only the expected reconstruction error Eqϕ(z∣x(i))[log⁡pθ(x(i)∣z)]\Exp{\qPhi(\bz|\bxi)}{\log \pT(\bxi | \bz)} requires estimation by sampling. The KL-divergence term can then be interpreted as regularizing ϕ\bphi, encouraging the approximate posterior to be close to the prior pθ(z)\pT(\bz). This yields a second version of the SGVB estimator L~B(θ,ϕ;x(i))≃L(θ,ϕ;x(i))\LBT{B}{\bxi} \simeq \LB{}{\bxi}, corresponding to eq. [ref], which typically has less variance than the generic estimator:

L~B(θ,ϕ;x(i))=−DKL(qϕ(z∣x(i))∣∣pθ(z))+1L∑l=1L(log⁡pθ(x(i)∣z(i,l)))where z(i,l)=gϕ(ϵ(i,l),x(i))and ϵ(l)∼p(ϵ)\begin{aligned}\LBT{B}{\bxi} &= - D_{KL}(\qPhi(\bz|\bxi) || \pT(\bz)) + \frac{1}{L} \sum_{l=1}^L (\log \pT(\bxi|\bzil)) \\ \text{where \quad} \bzil &= \gPhi(\bepsil,\bxi) \text{\quad and \quad} \bepsl \sim p(\beps) \eqnr\end{aligned}

Given multiple datapoints from a dataset X\bX with NN datapoints, we can construct an estimator of the marginal likelihood lower bound of the full dataset, based on minibatches:

L(θ,ϕ;X)≃L~M(θ,ϕ;XM)=NM∑i=1ML~(θ,ϕ;x(i))\LB{}{\bX} \simeq \LBT{M}{\bX^M} = \frac{N}{M} \sum_{i=1}^M \LBT{}{\bxi} \eqnr

where the minibatch XM={x(i)}i=1M\bX^M = \{\bxi\}_{i=1}^M is a randomly drawn sample of MM datapoints from the full dataset X\bX with NN datapoints. In our experiments we found that the number of samples LL per datapoint can be set to 11 as long as the minibatch size MM was large enough, e.g. M=100M=100. Derivatives ∇θ,ϕL~(θ;XM)\nabla_{\bT,\bphi} \widetilde{\mathcal{L}}(\bT;\bX^M) can be taken, and the resulting gradients can be used in conjunction with stochastic optimization methods such as SGD or Adagrad [cite]. See algorithm [ref] for a basic approach to compute the stochastic gradients.

A connection with auto-encoders becomes clear when looking at the objective function given at eq. [ref]. The first term is (the KL divergence of the approximate posterior from the prior) acts as a regularizer, while the second term is a an expected negative reconstruction error.

The function gϕ(.)\gPhi(.) is chosen such that it maps a datapoint x(i)\bxi and a random noise vector ϵ(l)\bepsl to a sample from the approximate posterior for that datapoint: z(i,l)=gϕ(ϵ(l),x(i))\bzil = \gPhi(\bepsl, \bxi) where z(i,l)∼qϕ(z∣x(i))\bzil \sim \qPhi(\bz|\bxi). Subsequently, the sample z(i,l)\bzil is then input to function log⁡pθ(x(i)∣z(i,l))\log \pT(\bxi|\bzil), which equals the probability density (or mass) of datapoint x(i)\bxi under the generative model, given z(i,l)\bzil. This term is a negative reconstruction error in auto-encoder parlance.

The reparameterization trick

In the paper
Difficulty 3 of 5

In order to solve our problem we invoked an alternative method for generating samples from qϕ(z∣x)\qPhi(\bz|\bx). The essential parameterization trick is quite simple. Let z\bz be a continuous random variable, and z∼qϕ(z∣x)\bz \sim \qPhi(\bz|\bx) be some conditional distribution. It is then often possible to express the random variable z\bz as a deterministic variable z=gϕ(ϵ,x)\bz = \gPhi(\beps, \bx), where ϵ\beps is an auxiliary variable with independent marginal p(ϵ)p(\beps), and gϕ(.)\gPhi(.) is some vector-valued function parameterized by ϕ\bphi.

This reparameterization is useful for our case since it can be used to rewrite an expectation w.r.t qϕ(z∣x)\qPhi(\bz|\bx) such that the Monte Carlo estimate of the expectation is differentiable w.r.t. ϕ\bphi. A proof is as follows. Given the deterministic mapping z=gϕ(ϵ,x)\bz = \gPhi(\beps, \bx) we know that qϕ(z∣x)∏idzi=p(ϵ)∏idϵi\qPhi(\bz|\bx) \prod_i d z_i = p(\beps) \prod_i d \epsilon_i. Therefore, ∫qϕ(z∣x)f(z) dz=∫p(ϵ)f(z) dϵ=∫p(ϵ)f(gϕ(ϵ,x)) dϵ\int \qPhi(\bz|\bx) f(\bz) \,d\bz = \int p(\beps) f(\bz) \,d\beps = \int p(\beps) f(\gPhi(\beps, \bx)) \,d\beps. It follows that a differentiable estimator can be constructed: ∫qϕ(z∣x)f(z) dz≃1L∑l=1Lf(gϕ(x,ϵ(l)))\int \qPhi(\bz|\bx) f(\bz) \,d\bz \simeq \frac{1}{L} \sum_{l=1}^L f(\gPhi(\bx, \bepsl)) where ϵ(l)∼p(ϵ)\bepsl \sim p(\beps). In section [ref] we applied this trick to obtain a differentiable estimator of the variational lower bound.

Take, for example, the univariate Gaussian case: let z∼p(z∣x)=N(μ,σ2)z \sim p(z|x) = \mathcal{N}(\mu, \sigma^2). In this case, a valid reparameterization is z=μ+σϵz = \mu + \sigma \epsilon, where ϵ\epsilon is an auxiliary noise variable ϵ∼N(0,1)\epsilon \sim \mathcal{N}(0,1). Therefore, EN(z;μ,σ2)[f(z)]=EN(ϵ;0,1)[f(μ+σϵ)]≃1L∑l=1Lf(μ+σϵ(l))\Exp{\mathcal{N}(z; \mu, \sigma^2)}{f(z)} = \Exp{\mathcal{N}(\epsilon; 0, 1)}{f(\mu + \sigma \epsilon)} \simeq \frac{1}{L} \sum_{l=1}^L f(\mu + \sigma \epsilon^{(l)}) where ϵ(l)∼N(0,1)\epsilon^{(l)} \sim \mathcal{N}(0,1).

For which qϕ(z∣x)\qPhi(\bz|\bx) can we choose such a differentiable transformation gϕ(.)\gPhi(.) and auxiliary variable ϵ∼p(ϵ)\beps \sim p(\beps)? Three basic approaches are:

Tractable inverse CDF. In this case, let ϵ∼U(0,I)\beps \sim \mathcal{U}(\bzero,\bI), and let gϕ(ϵ,x)\gPhi(\beps,\bx) be the inverse CDF of qϕ(z∣x)\qPhi(\bz|\bx). Examples: Exponential, Cauchy, Logistic, Rayleigh, Pareto, Weibull, Reciprocal, Gompertz, Gumbel and Erlang distributions.

Analogous to the Gaussian example, for any "location-scale" family of distributions we can choose the standard distribution (with location=0\text{location} =0, scale=1\text{scale} =1) as the auxiliary variable ϵ\beps, and let g(.)=location+scale⋅ϵg(.)=\text{location}+\text{scale} \cdot \beps. Examples: Laplace, Elliptical, Student's t, Logistic, Uniform, Triangular and Gaussian distributions.

Composition: It is often possible to express random variables as different transformations of auxiliary variables. Examples: Log-Normal (exponentiation of normally distributed variable), Gamma (a sum over exponentially distributed variables), Dirichlet (weighted sum of Gamma variates), Beta, Chi-Squared, and F distributions.

When all three approaches fail, good approximations to the inverse CDF exist requiring computations with time complexity comparable to the PDF (see e.g. [cite] for some methods).

Example: Variational Auto-Encoder

In the paper
Difficulty 3 of 5

In this section we'll give an example where we use a neural network for the probabilistic encoder qϕ(z∣x)\qPhi(\bz|\bx) (the approximation to the posterior of the generative model pθ(x,z)\pT(\bx, \bz)) and where the parameters ϕ\bphi and θ\bT are optimized jointly with the AEVB algorithm.

Let the prior over the latent variables be the centered isotropic multivariate Gaussian pθ(z)=N(z;0,I)\pT(\bz) = \mathcal{N}(\bz; \bzero, \bI). Note that in this case, the prior lacks parameters. We let pθ(x∣z)\pT(\bx|\bz) be a multivariate Gaussian (in case of real-valued data) or Bernoulli (in case of binary data) whose distribution parameters are computed from z\bz with a MLP (a fully-connected neural network with a single hidden layer, see appendix [ref]). Note the true posterior pθ(z∣x)\pT(\bz|\bx) is in this case intractable. While there is much freedom in the form qϕ(z∣x)\qPhi(\bz|\bx), we'll assume the true (but intractable) posterior takes on a approximate Gaussian form with an approximately diagonal covariance. In this case, we can let the variational approximate posterior be a multivariate Gaussian with a diagonal covariance structure:

log⁡qϕ(z∣x(i))=log⁡N(z;μ(i),σ2(i)I)\begin{aligned}\log \qPhi(\bz|\bxi) &= \log \mathcal{N}(\bz; \bmu^{(i)}, \bsigma^{2 (i)} \bI) \eqnr\end{aligned}

where the mean and s.d. of the approximate posterior, μ(i)\bmu^{(i)} and σ(i)\bsigma^{(i)}, are outputs of the encoding MLP, i.e. nonlinear functions of datapoint x(i)\bx^{(i)} and the variational parameters ϕ\bphi (see appendix [ref]).

As explained in section [ref], we sample from the posterior z(i,l)∼qϕ(z∣x(i))\bzil \sim \qPhi(\bz|\bxi) using z(i,l)=gϕ(x(i),ϵ(l))=μ(i)+σ(i)⊙ϵ(l)\bzil = \gPhi(\bxi, \bepsl) = \bmu^{(i)} + \bsigma^{(i)} \odot \bepsl where ϵ(l)∼N(0,I)\bepsl \sim \mathcal{N}(\bzero,\bI). With ⊙\odot we signify an element-wise product. In this model both pθ(z)\pT(\bz) (the prior) and qϕ(z∣x)\qPhi(\bz|\bx) are Gaussian; in this case, we can use the estimator of eq. [ref] where the KL divergence can be computed and differentiated without estimation (see appendix [ref]). The resulting estimator for this model and datapoint x(i)\bxi is:

L(θ,ϕ;x(i))≃12∑j=1J(1+log⁡((σj(i))2)−(μj(i))2−(σj(i))2)+1L∑l=1Llog⁡pθ(x(i)∣z(i,l))wherez(i,l)=μ(i)+σ(i)⊙ϵ(l)and ϵ(l)∼N(0,I)\begin{aligned}\LB{}{\bxi} &\simeq \frac{1}{2} \sum_{j=1}^J \left(1 + \log ((\sigma_j^{(i)})^2) - (\mu_j^{(i)})^2 - (\sigma_j^{(i)})^2 \right) + \frac{1}{L} \sum_{l=1}^L \log \pT(\bxi|\bzil) \\ \text{where\quad} \bzil &= \bmu^{(i)} + \bsigma^{(i)} \odot \beps^{(l)} \text{\quad and \quad} \bepsl \sim \mathcal{N}(0,\bI) \eqnr\end{aligned}

As explained above and in appendix [ref], the decoding term log⁡pθ(x(i)∣z(i,l))\log \pT(\bxi|\bzil) is a Bernoulli or Gaussian MLP, depending on the type of data we are modelling.

Related work

In the paper
Difficulty 3 of 5

The wake-sleep algorithm [cite] is, to the best of our knowledge, the only other on-line learning method in the literature that is applicable to the same general class of continuous latent variable models. Like our method, the wake-sleep algorithm employs a recognition model that approximates the true posterior. A drawback of the wake-sleep algorithm is that it requires a concurrent optimization of two objective functions, which together do not correspond to optimization of (a bound of) the marginal likelihood.

An advantage of wake-sleep is that it also applies to models with discrete latent variables. Wake-Sleep has the same computational complexity as AEVB per datapoint.

Stochastic variational inference [cite] has recently received increasing interest. Recently, [cite] introduced a control variate schemes to reduce the high variance of the na\"ive gradient estimator discussed in section [ref], and applied to exponential family approximations of the posterior. In [cite] some general methods, i.e. a control variate scheme, were introduced for reducing the variance of the original gradient estimator. In [cite], a similar reparameterization as in this paper was used in an efficient version of a stochastic variational inference algorithm for learning the natural parameters of exponential-family approximating distributions.

The AEVB algorithm exposes a connection between directed probabilistic models (trained with a variational objective) and auto-encoders. A connection between linear auto-encoders and a certain class of generative linear-Gaussian models has long been known. In [cite] it was shown that PCA corresponds to the maximum-likelihood (ML) solution of a special case of the linear-Gaussian model with a prior p(z)=N(0,I)p(\bz) = \mathcal{N}(0,\bI) and a conditional distribution p(x∣z)=N(x;Wz,ϵI)p(\bx|\bz) = \mathcal{N}(\bx; \bW \bz, \epsilon \bI), specifically the case with infinitesimally small ϵ\epsilon.

In relevant recent work on autoencoders [cite] it was shown that the training criterion of unregularized autoencoders corresponds to maximization of a lower bound (see the infomax principle [cite]) of the mutual information between input XX and latent representation ZZ. Maximizing (w.r.t. parameters) of the mutual information is equivalent to maximizing the conditional entropy, which is lower bounded by the expected loglikelihood of the data under the autoencoding model [cite], i.e. the negative reconstrution error.

However, it is well known that this reconstruction criterion is in itself not sufficient for learning useful representations [cite].

Regularization techniques have been proposed to make autoencoders learn useful representations, such as denoising, contractive and sparse autoencoder variants [cite]. The SGVB objective contains a regularization term dictated by the variational bound (e.g. eq. [ref]), lacking the usual nuisance regularization hyperparameter required to learn useful representations. Related are also encoder-decoder architectures such as the predictive sparse decomposition (PSD) [cite], from which we drew some inspiration. Also relevant are the recently introduced Generative Stochastic Networks [cite] where noisy auto-encoders learn the transition operator of a Markov chain that samples from the data distribution. In [cite] a recognition model was employed for efficient learning with Deep Boltzmann Machines. These methods are targeted at either unnormalized models (i.e. undirected models like Boltzmann machines) or limited to sparse coding models, in contrast to our proposed algorithm for learning a general class of directed probabilistic models.

The recently proposed DARN method [cite], also learns a directed probabilistic model using an auto-encoding structure, however their method applies to binary latent variables. Even more recently, [cite] also make the connection between auto-encoders, directed proabilistic models and stochastic variational inference using the reparameterization trick we describe in this paper. Their work was developed independently of ours and provides an additional perspective on AEVB.

Experiments

In the paper
Difficulty 3 of 5ELBO EstimatorEncoder-Decoder ArchitectureSigmoidal ActivationStochastic Gradient Ascent

We trained generative models of images from the MNIST and Frey Face datasets and compared learning algorithms in terms of the variational lower bound, and the estimated marginal likelihood.

The generative model (encoder) and variational approximation (decoder) from section [ref] were used, where the described encoder and decoder have an equal number of hidden units. Since the Frey Face data are continuous, we used a decoder with Gaussian outputs, identical to the encoder, except that the means were constrained to the interval (0,1)(0,1) using a sigmoidal activation function at the decoder output. Note that with hidden units we refer to the hidden layer of the neural networks of the encoder and decoder.

Parameters are updated using stochastic gradient ascent where gradients are computed by differentiating the lower bound estimator ∇θ,ϕL(θ,ϕ;X)\nabla_{\bT,\bphi} \LB{}{\bX} (see algorithm [ref]), plus a small weight decay term corresponding to a prior p(θ)=N(0,I)p(\bT) = \mathcal{N}(0,\bI). Optimization of this objective is equivalent to approximate MAP estimation, where the likelihood gradient is approximated by the gradient of the lower bound.

We compared performance of AEVB to the wake-sleep algorithm [cite]. We employed the same encoder (also called recognition model) for the wake-sleep algorithm and the variational auto-encoder. All parameters, both variational and generative, were initialized by random sampling from N(0,0.01)\mathcal{N}(0,0.01), and were jointly stochastically optimized using the MAP criterion. Stepsizes were adapted with Adagrad [cite]; the Adagrad global stepsize parameters were chosen from \0.01, 0.02, 0.1\ based on performance on the training set in the first few iterations. Minibatches of size M=100M=100 were used, with L=1L=1 samples per datapoint.

Likelihood lower bound We trained generative models (decoders) and corresponding encoders (a.k.a. recognition models) having 500500 hidden units in case of MNIST, and 200200 hidden units in case of the Frey Face dataset (to prevent overfitting, since it is a considerably smaller dataset). The chosen number of hidden units is based on prior literature on auto-encoders, and the relative performance of different algorithms was not very sensitive to these choices. Figure [ref] shows the results when comparing the lower bounds. Interestingly, superfluous latent variables did not result in overfitting, which is explained by the regularizing nature of the variational bound.

Marginal likelihood For very low-dimensional latent space it is possible to estimate the marginal likelihood of the learned generative models using an MCMC estimator. More information about the marginal likelihood estimator is available in the appendix. For the encoder and decoder we again used neural networks, this time with 100 hidden units, and 3 latent variables; for higher dimensional latent space the estimates became unreliable. Again, the MNIST dataset was used. The AEVB and Wake-Sleep methods were compared to Monte Carlo EM (MCEM) with a Hybrid Monte Carlo (HMC) [cite] sampler; details are in the appendix. We compared the convergence speed for the three algorithms, for a small and large training set size. Results are in figure [ref].

Visualisation of high-dimensional data If we choose a low-dimensional latent space (e.g. 2D), we can use the learned encoders (recognition model) to project high-dimensional data to a low-dimensional manifold. See appendix [ref] for visualisations of the 2D latent manifolds for the MNIST and Frey Face datasets.

00.20.40.60.8100.20.40.60.81IterationLower bound valueELBO gives a scalable, differentiable lower bound

ELBO estimator lower bounds marginal likelihood

0:00 / 0:07

The ELBO estimator provides a lower bound on the marginal likelihood that can be optimized via stochastic gradients, improving over wake-sleep.

From the section “Experiments”

The ELBO estimator provides a lower bound on the marginal likelihood that can be optimized via stochastic gradients, improving over wake-sleep.

Data enters the model.

0:00 / 0:22

Data flows through the encoder to produce latent parameters, which are then sampled and passed to the decoder for reconstruction, with gradients flowing backward through both.

From the section “Experiments”

Data flows through the encoder to produce latent parameters, which are then sampled and passed to the decoder for reconstruction, with gradients flowing backward through both.

Conclusion

In the paper
Difficulty 3 of 5

We have introduced a novel estimator of the variational lower bound, Stochastic Gradient VB (SGVB), for efficient approximate inference with continuous latent variables. The proposed estimator can be straightforwardly differentiated and optimized using standard stochastic gradient methods. For the case of i.i.d. datasets and continuous latent variables per datapoint we introduce an efficient algorithm for efficient inference and learning, Auto-Encoding VB (AEVB), that learns an approximate inference model using the SGVB estimator. The theoretical advantages are reflected in experimental results.

Future work

In the paper
Difficulty 3 of 5

Since the SGVB estimator and the AEVB algorithm can be applied to almost any inference and learning problem with continuous latent variables, there are plenty of future directions: (i) learning hierarchical generative architectures with deep neural networks (e.g. convolutional networks) used for the encoders and decoders, trained jointly with AEVB; (ii) time-series models (i.e. dynamic Bayesian networks); (iii) application of SGVB to the global parameters; (iv) supervised models with latent variables, useful for learning complicated noise distributions.

bib

alpha

Visualisations

In the paper
Difficulty 1 of 5

See figures [ref] and [ref] for visualisations of latent space and corresponding observed space of models learned with SGVB.

Solution of −DKL(qϕ(z)∣∣pθ(z))- D_{KL}(\qPhi(\bz) || \pT(\bz)), Gaussian case

In the paper
Difficulty 4 of 5Analytic KL TermGaussian Latent SpaceClosed-Form KL Solution

The variational lower bound (the objective to be maximized) contains a KL term that can often be integrated analytically. Here we give the solution when both the prior pθ(z)=N(0,I)\pT(\bz) = \mathcal{N}(0,\bI) and the posterior approximation qϕ(z∣x(i))\qPhi(\bz|\bxi) are Gaussian. Let JJ be the dimensionality of z\bz. Let μ\bmu and σ\bsigma denote the variational mean and s.d. evaluated at datapoint ii, and let μj\mu_j and σj\sigma_j simply denote the jj-th element of these vectors. Then:

∫qθ(z)log⁡p(z) dz=∫N(z;μ,σ2)log⁡N(z;0,I) dz=−J2log⁡(2π)−12∑j=1J(μj2+σj2)\begin{aligned}\int \qT(\bz) \log p(\bz) \,d\bz &= \int \mathcal{N}(\bz;\bmu,\bsigma^2) \log \mathcal{N}(\bz;\bzero,\bI) \,d\bz \\ &= - \frac{J}{2} \log (2 \pi) - \frac{1}{2} \sum_{j=1}^J (\mu_j^2 + \sigma_j^2)\end{aligned}

And:

∫qθ(z)log⁡qθ(z) dz=∫N(z;μ,σ2)log⁡N(z;μ,σ2) dz=−J2log⁡(2π)−12∑j=1J(1+log⁡σj2)\begin{aligned}\int \qT(\bz) \log \qT(\bz) \,d\bz &= \int \mathcal{N}(\bz;\bmu,\bsigma^2) \log \mathcal{N}(\bz;\bmu,\bsigma^2) \,d\bz \\ &= - \frac{J}{2} \log (2 \pi) - \frac{1}{2} \sum_{j=1}^J ( 1 + \log \sigma^2_j )\end{aligned}

Therefore:

−DKL((qϕ(z)∣∣pθ(z))=∫qθ(z)(log⁡pθ(z)−log⁡qθ(z)) dz=12∑j=1J(1+log⁡((σj)2)−(μj)2−(σj)2)\begin{aligned}- D_{KL}((\qPhi(\bz) || \pT(\bz)) &= \int \qT(\bz) \left(\log \pT(\bz) - \log \qT(\bz)\right) \,d\bz \\ &= \frac{1}{2} \sum_{j=1}^J \left(1 + \log ((\sigma_j)^2) - (\mu_j)^2 - (\sigma_j)^2 \right)\end{aligned}

When using a recognition model qϕ(z∣x)\qPhi(\bz|\bx) then μ\bmu and s.d. σ\bsigma are simply functions of x\bx and the variational parameters ϕ\bphi, as exemplified in the text.

Analytic KL term

∫qθ(z)log⁡p(z) dz=−J2log⁡(2π)−12∑j=1J(μj2+σj2)\int \qT(\bz) \log p(\bz) \,d\bz = - \frac{J}{2} \log (2 \pi) - \frac{1}{2} \sum_{j=1}^J (\mu_j^2 + \sigma_j^2)
step 1 of 3

Integrate the prior log‑density under a Gaussian posterior

0:00 / 0:15

The KL divergence between two Gaussians simplifies to a simple sum of squares and logs, eliminating the need for numerical integration or Monte Carlo sampling for this specific term in the loss.

From the section “Solution of −DKL(qϕ(z)∣∣pθ(z))- D_{KL}(\qPhi(\bz) || \pT(\bz)), Gaussian case”

The KL divergence between two Gaussians simplifies to a simple sum of squares and logs, eliminating the need for numerical integration or Monte Carlo sampling for this specific term in the loss.

Closed-Form KL Term

∫qθ(z)log⁡p(z) dz=∫N(z;μ,σ2)log⁡N(z;0,I) dz=−J2log⁡(2π)−12∑j=1J(μj2+σj2)\int \qT(\bz) \log p(\bz) \,d\bz = \int \mathcal{N}(\bz;\bmu,\bsigma^2) \log \mathcal{N}(\bz;\bzero,\bI) \,d\bz = - \frac{J}{2} \log (2 \pi) - \frac{1}{2} \sum_{j=1}^J (\mu_j^2 + \sigma_j^2)
step 1 of 3

Reconstruction term expectation

0:00 / 0:13

The final loss function is a sum of a reconstruction term (expectation of log likelihood) and a regularization term (KL divergence), where the latter penalizes the latent distribution for deviating from the standard normal prior.

From the section “Solution of −DKL(qϕ(z)∣∣pθ(z))- D_{KL}(\qPhi(\bz) || \pT(\bz)), Gaussian case”

The final loss function is a sum of a reconstruction term (expectation of log likelihood) and a regularization term (KL divergence), where the latter penalizes the latent distribution for deviating from the standard normal prior.

MLP's as probabilistic encoders and decoders

In the paper
Difficulty 3 of 5

In variational auto-encoders, neural networks are used as probabilistic encoders and decoders. There are many possible choices of encoders and decoders, depending on the type of data and model. In our example we used relatively simple neural networks, namely multi-layered perceptrons (MLPs). For the encoder we used a MLP with Gaussian output, while for the decoder we used MLPs with either Gaussian or Bernoulli outputs, depending on the type of data.

Bernoulli MLP as decoder

In the paper
Difficulty 4 of 5Bernoulli Decoder

In this case let pθ(x∣z)\pT(\bx|\bz) be a multivariate Bernoulli whose probabilities are computed from z\bz with a fully-connected neural network with a single hidden layer:

log⁡p(x∣z)=∑i=1Dxilog⁡yi+(1−xi)⋅log⁡(1−yi)where   y=fσ(W2tanh⁡(W1z+b1)+b2)\begin{aligned}\log p(\bx|\bz) &= \sum_{i=1}^D x_i \log y_i + (1-x_i) \cdot \log(1-y_i) \\ \text{where\,\,\,} \by &= f_\sigma(\bW_2 \tanh(\bW_1 \bz + \bbb_1) + \bbb_2) \eqnr\end{aligned}

where fσ(.)f_\sigma(.) is the elementwise sigmoid activation function, and where θ={W1,W2,b1,b2}\bT = \{\bW_1, \bW_2, \bbb_1, \bbb_2\} are the weights and biases of the MLP.

Bernoulli Decoder likelihood

pθ(x∣z)\pT(\bx|\bz) is a multivariate Bernoulli whose probabilities are computed from z\bz with a fully-connected neural network with a single hidden layer
step 1 of 4

Bernoulli decoder defined by a neural network

0:00 / 0:19

The Bernoulli likelihood term decomposes into a sum over pixels, where each pixel's contribution depends on the network's sigmoidal output.

From the section “Bernoulli MLP as decoder”

The Bernoulli likelihood term decomposes into a sum over pixels, where each pixel's contribution depends on the network's sigmoidal output.

Gaussian MLP as encoder or decoder

In the paper
Difficulty 3 of 5

In this case let encoder or decoder be a multivariate Gaussian with a diagonal covariance structure:

log⁡p(x∣z)=log⁡N(x;μ,σ2I)where   μ=W4h+b4log⁡σ2=W5h+b5h=tanh⁡(W3z+b3)\begin{aligned}\log p(\bx|\bz) &= \log \mathcal{N}(\bx; \bmu, \bsigma^2 \bI) \\ \text{where\,\,\,} \bmu &= \bW_4 \bh +\bbb_4 \\ \log \bsigma^2 &= \bW_5 \bh + \bbb_5 \\ \bh &= \tanh(\bW_3 \bz + \bbb_3) \eqnr\end{aligned}

where {W3,W4,W5,b3,b4,b5}\{\bW_3, \bW_4, \bW_5, \bbb_3, \bbb_4, \bbb_5 \} are the weights and biases of the MLP and part of θ\bT when used as decoder. Note that when this network is used as an encoder qϕ(z∣x)\qPhi(\bz|\bx), then z\bz and x\bx are swapped, and the weights and biases are variational parameters ϕ\bphi.

Marginal likelihood estimator

In the paper
Difficulty 3 of 5

We derived the following marginal likelihood estimator that produces good estimates of the marginal likelihood as long as the dimensionality of the sampled space is low (less then 5 dimensions), and sufficient samples are taken. Let pθ(x,z)=pθ(z)pθ(x∣z)\pT(\bx, \bz) = \pT(\bz) \pT(\bx|\bz) be the generative model we are sampling from, and for a given datapoint x(i)\bxi we would like to estimate the marginal likelihood pθ(x(i))\pT(\bxi).

The estimation process consists of three stages:

Sample LL values {z(l)}\{\bzl\} from the posterior using gradient-based MCMC, e.g. Hybrid Monte Carlo, using ∇zlog⁡pθ(z∣x)=∇zlog⁡pθ(z)+∇zlog⁡pθ(x∣z)\nabla_{\bz} \log \pT(\bz|\bx) = \nabla_{\bz} \log \pT(\bz) + \nabla_{\bz} \log \pT(\bx|\bz). Fit a density estimator q(z)q(\bz) to these samples {z(l)}\{\bzl\}. Again, sample LL new values from the posterior. Plug these samples, as well as the fitted q(z)q(\bz), into the following estimator:

pθ(x(i))≃(1L∑l=1Lq(z(l))pθ(z)pθ(x(i)∣z(l)))−1where z(l)∼pθ(z∣x(i))\pT(\bxi) \simeq \left( \frac{1}{L} \sum_{l=1}^L \frac{q(\bzl)}{\pT(\bz) \pT(\bxi|\bzl)} \right)^{-1} \text{\quad where \quad} \bzl \sim \pT(\bz|\bxi)

Derivation of the estimator:

1pθ(x(i))=∫q(z) dzpθ(x(i))=∫q(z)pθ(x(i),z)pθ(x(i),z) dzpθ(x(i))=∫pθ(x(i),z)pθ(x(i))q(z)pθ(x(i),z) dz=∫pθ(z∣x(i))q(z)pθ(x(i),z) dz≃1L∑l=1Lq(z(l))pθ(z)pθ(x(i)∣z(l))where z(l)∼pθ(z∣x(i))\begin{aligned}\frac{1}{\pT(\bxi)} &= \frac{\int q(\bz) \,d\bz}{\pT(\bxi)} = \frac{\int q(\bz) \frac{\pT(\bxi, \bz) }{\pT(\bxi, \bz)} \,d\bz}{\pT(\bxi)} \\ &= \int \frac{\pT(\bxi, \bz)}{\pT(\bxi)} \frac{q(\bz)}{\pT(\bxi, \bz)} \,d\bz \\ &= \int \pT(\bz|\bxi) \frac{q(\bz)}{\pT(\bxi, \bz)} \,d\bz \\ &\simeq \frac{1}{L} \sum_{l=1}^L \frac{q(\bzl)}{\pT(\bz) \pT(\bxi|\bzl)} \text{\quad where \quad} \bzl \sim \pT(\bz|\bxi)\end{aligned}

Monte Carlo EM

In the paper
Difficulty 3 of 5

The Monte Carlo EM algorithm does not employ an encoder, instead it samples from the posterior of the latent variables using gradients of the posterior computed with ∇zlog⁡pθ(z∣x)=∇zlog⁡pθ(z)+∇zlog⁡pθ(x∣z)\nabla_{\bz} \log \pT(\bz|\bx) = \nabla_{\bz} \log \pT(\bz) + \nabla_{\bz} \log \pT(\bx|\bz). The Monte Carlo EM procedure consists of 10 HMC leapfrog steps with an automatically tuned stepsize such that the acceptance rate was 90\%, followed by 5 weight updates steps using the acquired sample. For all algorithms the parameters were updated using the Adagrad stepsizes (with accompanying annealing schedule).

The marginal likelihood was estimated with the first 1000 datapoints from the train and test sets, for each datapoint sampling 50 values from the posterior of the latent variables using Hybrid Monte Carlo with 4 leapfrog steps.

Difficulty 3 of 5

As written in the paper, it is possible to perform variational inference on both the parameters θ\bT and the latent variables z\bz, as opposed to just the latent variables as we did in the paper. Here, we'll derive our estimator for that case.

Let pα(θ)\pA(\bT) be some hyperprior for the parameters introduced above, parameterized by α\balpha. The marginal likelihood can be written as:

log⁡pα(X)=DKL(qϕ(θ)∣∣pα(θ∣X))+L(ϕ;X)\log \pA(\bX) = D_{KL}(\qPhi(\bT)||\pA(\bT|\bX)) + \mathcal{L}(\bphi;\bX) \eqnr

where the first RHS term denotes a KL divergence of the approximate from the true posterior, and where L(ϕ;X)\mathcal{L}(\bphi;\bX) denotes the variational lower bound to the marginal likelihood:

L(ϕ;X)=∫qϕ(θ)(log⁡pθ(X)+log⁡pα(θ)−log⁡qϕ(θ)) dθ\mathcal{L}(\bphi;\bX) = \int \qPhi(\bT) \left( \log \pT(\bX) + \log \pA(\bT) - \log \qPhi(\bT) \right) \,d\bT \eqnr

Note that this is a lower bound since the KL divergence is non-negative; the bound equals the true marginal when the approximate and true posteriors match exactly. The term log⁡pθ(X)\log \pT(\bX) is composed of a sum over the marginal likelihoods of individual datapoints log⁡pθ(X)=∑i=1Nlog⁡pθ(x(i))\log \pT(\bX) = \sum_{i=1}^N \log \pT(\bxi), which can each be rewritten as:

log⁡pθ(x(i))=DKL(qϕ(z∣x(i))∣∣pθ(z∣x(i)))+L(θ,ϕ;x(i))\log \pT(\bxi) = D_{KL}(\qPhi(\bz|\bxi)||\pT(\bz|\bxi)) + \mathcal{L}(\bT,\bphi;\bxi) \eqnr

where again the first RHS term is the KL divergence of the approximate from the true posterior, and L(θ,ϕ;x)\mathcal{L}(\bT,\bphi;\bx) is the variational lower bound of the marginal likelihood of datapoint ii:

L(θ,ϕ;x(i))=∫qϕ(z∣x)(log⁡pθ(x(i)∣z)+log⁡pθ(z)−log⁡qϕ(z∣x)) dz\begin{aligned}\mathcal{L}(\bT,\bphi;\bxi) &= \int \qPhi(\bz|\bx) \left(\log \pT(\bxi | \bz) + \log \pT(\bz) - \log \qPhi(\bz|\bx)\right) \,d\bz \eqnr\end{aligned}

The expectations on the RHS of eqs [ref] and [ref] can obviously be written as a sum of three separate expectations, of which the second and third component can sometimes be analytically solved, e.g. when both pθ(x)\pT(\bx) and qϕ(z∣x)\qPhi(\bz|\bx) are Gaussian. For generality we will here assume that each of these expectations is intractable.

Under certain mild conditions outlined in section (see paper) for chosen approximate posteriors qϕ(θ)\qPhi(\bT) and qϕ(z∣x)\qPhi(\bz|\bx) we can reparameterize conditional samples z~∼qϕ(z∣x)\btz \sim \qPhi(\bz|\bx) as

z~=gϕ(ϵ,x)with ϵ∼p(ϵ)\btz = \gPhi(\beps,\bx) \text{\quad with \quad} \beps \sim p(\beps) \eqnr

where we choose a prior p(ϵ)p(\beps) and a function gϕ(ϵ,x)\gPhi(\beps,\bx) such that the following holds:

L(θ,ϕ;x(i))=∫qϕ(z∣x)(log⁡pθ(x(i)∣z)+log⁡pθ(z)−log⁡qϕ(z∣x)) dz=∫p(ϵ)(log⁡pθ(x(i)∣z)+log⁡pθ(z)−log⁡qϕ(z∣x))∣z=gϕ(ϵ,x(i)) dϵ\begin{aligned}\mathcal{L}(\bT,\bphi;\bxi) &= \int \qPhi(\bz|\bx) \left(\log \pT(\bxi | \bz) + \log \pT(\bz) - \log \qPhi(\bz|\bx)\right) \,d\bz \\ &= \int p(\beps) \left(\log \pT(\bxi | \bz) + \log \pT(\bz) - \log \qPhi(\bz|\bx)\right) \bigg|_{\bz=\gPhi(\beps,\bxi)} \,d\beps \eqnr\end{aligned}

The same can be done for the approximate posterior qϕ(θ)\qPhi(\bT):

θ~=hϕ(ζ)with ζ∼p(ζ)\btT = \hPhi(\bzeta) \text{\quad with \quad} \bzeta \sim p(\bzeta) \eqnr

where we, similarly as above, choose a prior p(ζ)p(\bzeta) and a function hϕ(ζ)\hPhi(\bzeta) such that the following holds:

L(ϕ;X)=∫qϕ(θ)(log⁡pθ(X)+log⁡pα(θ)−log⁡qϕ(θ)) dθ=∫p(ζ)(log⁡pθ(X)+log⁡pα(θ)−log⁡qϕ(θ))∣θ=hϕ(ζ) dζ\begin{aligned}\mathcal{L}(\bphi;\bX) &= \int \qPhi(\bT) \left( \log \pT(\bX) + \log \pA(\bT) - \log \qPhi(\bT) \right) \,d\bT \\ &= \int p(\bzeta) \left( \log \pT(\bX) + \log \pA(\bT) - \log \qPhi(\bT) \right) \bigg|_{\bT=\hPhi(\bzeta)} \,d\bzeta \eqnr\end{aligned}

For notational conciseness we introduce a shorthand notation fϕ(x,z,θ)\fPhi(\bx, \bz, \bT):

fϕ(x,z,θ)=N⋅(log⁡pθ(x∣z)+log⁡pθ(z)−log⁡qϕ(z∣x))+log⁡pα(θ)−log⁡qϕ(θ)\fPhi(\bx, \bz, \bT) = N \cdot (\log \pT(\bx | \bz) + \log \pT(\bz) - \log \qPhi(\bz|\bx)) + \log \pA(\bT) - \log \qPhi(\bT)

Using equations [ref] and [ref], the Monte Carlo estimate of the variational lower bound, given datapoint x(i)\bxi, is:

L(ϕ;X)≃1L∑l=1Lfϕ(x(l),gϕ(ϵ(l),x(l)),hϕ(ζ(l)))\begin{aligned}\mathcal{L}(\bphi;\bX) &\simeq \frac{1}{L} \sum_{l=1}^L \fPhi(\bxl, \gPhi(\bepsl,\bxl), \hPhi(\bzetal)) \eqnr\end{aligned}

where ϵ(l)∼p(ϵ)\bepsl \sim p(\beps) and ζ(l)∼p(ζ)\bzetal \sim p(\bzeta). The estimator only depends on samples from p(ϵ)p(\beps) and p(ζ)p(\bzeta) which are obviously not influenced by ϕ\bphi, therefore the estimator can be differentiated w.r.t. ϕ\bphi. The resulting stochastic gradients can be used in conjunction with stochastic optimization methods such as SGD or Adagrad [cite]. See algorithm [ref] for a basic approach to computing stochastic gradients.

Difficulty 3 of 5

Let the prior over the parameters and latent variables be the centered isotropic Gaussian pα(θ)=N(z;0,I)\pA(\bT) = \mathcal{N}(\bz; \bzero, \bI) and pθ(z)=N(z;0,I)\pT(\bz) = \mathcal{N}(\bz; \bzero, \bI). Note that in this case, the prior lacks parameters. Let's also assume that the true posteriors are approximatily Gaussian with an approximately diagonal covariance. In this case, we can let the variational approximate posteriors be multivariate Gaussians with a diagonal covariance structure:

log⁡qϕ(θ)=log⁡N(θ;μθ,σθ2I)log⁡qϕ(z∣x)=log⁡N(z;μz,σz2I)\begin{aligned}\log \qPhi(\bT) &= \log \mathcal{N}(\bT; \bmu_{\bT}, \bsigma_{\bT}^2 \bI) \\ \log \qPhi(\bz|\bx) &= \log \mathcal{N}(\bz; \bmu_{\bz}, \bsigma_{\bz}^2 \bI) \eqnr\end{aligned}

where μz\bmu_{\bz} and σz\bsigma_{\bz} are yet unspecified functions of x\bx. Since they are Gaussian, we can parameterize the variational approximate posteriors:

qϕ(θ)as θ~=μθ+σθ⊙ζwhere ζ∼N(0,I)qϕ(z∣x)as z~=μz+σz⊙ϵwhere ϵ∼N(0,I)\begin{aligned}\qPhi(\bT) &\text{\quad as \quad} \btT = \bmu_{\bT} + \bsigma_{\bT} \odot \bzeta &\text{\quad where \quad} \bzeta \sim \mathcal{N}(\bzero,\bI) \\ \qPhi(\bz|\bx) &\text{\quad as \quad} \btz = \bmu_{\bz} + \bsigma_{\bz} \odot \beps &\text{\quad where \quad} \beps \sim \mathcal{N}(\bzero,\bI)\end{aligned}

With ⊙\odot we signify an element-wise product. These can be plugged into the lower bound defined above (eqs [ref] and [ref]).

In this case it is possible to construct an alternative estimator with a lower variance, since in this model pα(θ)\pA(\bT), pθ(z)\pT(\bz), qϕ(θ)\qPhi(\bT) and qϕ(z∣x)\qPhi(\bz|\bx) are Gaussian, and therefore four terms of fϕ\fPhi can be solved analytically. The resulting estimator is:

L(ϕ;X)≃1L∑l=1LN⋅(12∑j=1J(1+log⁡((σz,j(l))2)−(μz,j(l))2−(σz,j(l))2)+log⁡pθ(x(i)z(i)))+12∑j=1J(1+log⁡((σθ,j(l))2)−(μθ,j(l))2−(σθ,j(l))2)\begin{aligned}\mathcal{L}(\bphi;\bX) &\simeq \frac{1}{L} \sum_{l=1}^L N \cdot \left( \frac{1}{2} \sum_{j=1}^J \left(1 + \log ((\sigma_{\bz,j}^{(l)})^2) - (\mu_{\bz,j}^{(l)})^2 - (\sigma_{\bz,j}^{(l)})^2 \right) + \log \pT(\bxi\bzi) \right) \\ &+ \frac{1}{2} \sum_{j=1}^J \left(1 + \log ((\sigma_{\bT,j}^{(l)})^2) - (\mu_{\bT,j}^{(l)})^2 - (\sigma_{\bT,j}^{(l)})^2 \right) \eqnr\end{aligned}

μj(i)\mu_j^{(i)} and σj(i)\sigma_j^{(i)} simply denote the jj-th element of vectors μ(i)\bmu^{(i)} and σ(i)\bsigma^{(i)}.

Auto-Encoding Variational Bayes · ArcVisual