Auto-encoding Variational Bayes 阅读笔记

Notation
  • pθ(z|x): intractable posterior
  • pθ(x|z): probabilistic decoder
  • qϕ(z|x): recognition model, variational approximation to pθ(z|x), also regarded as a probabilistic encoder
  • pθ(z)pθ(x|z): generative model
  • ϕ: variational parameters
  • θ: generative parameters
Abbreviation
  • SGVB: Stochastic Gradient Variational Bayes
  • AEVB: auto-encoding VB
  • ML: maximum likelihood
  • MAP: maximum a posteriori

Motivation

  • Problem

    • How to perform efficient inference and learning in directed probabilistic models, in the presence of continuous latent variables with intractable posterior distribution pθ(z|x) and large datasets?
  • Existing Solution and Difficulty

    • VB: involves the optimization of an approximation to the intractable posterior
    • mean-field: requires analytical solutions of expectations w.r.t. the approximate posterior, which are also intractable in the general case

Contribution of this paper

  • (1) SGVB estimator: an estimator of the variational lower bound
    • yielded by a reparameterization of the variational lower bound
    • simple & differentiable & unbiased
    • straightforwad to optimize using standard SG ascent techniques
  • (2) AEVB algorithm
    • using SGVB 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.
    • condition: i.i.d. datasets X={x(i)}i=1N & continuous latent variable z per datapoint

Methodology

assumption
  • directed graphical models with continuous latent variables
  • i.i.d. dataset with latent variables per datapoint
    • where we like to perform
      • ML or MAP inference on the (global) paramters θ
      • variational inference on the latent variable z
  • pθ(z) and pθ(x|z): both PDFs are differentiable almost everywhere w.r.t. both θ and z
target case
  • intractability
    • pθ(x)=pθ(z)pθ(x|z)dz: so we cannot evaluate or differentiate it.
    • pθ(z|x)=pθ(x|z)pθ(z)pθ(x): so the EM algorithm cannot be used.
    • the required integrals for any reasonable mean-field VB algorithm: so the VB algorithm cannot be used.
    • in cases of moderately complicated likelihood function, e.g. in a neural network with a nonlinear hidden layer
  • a large dataset
    • batch optimization is too costly => minibatch or single datapoints
    • sampling bases solutions are too slow, e.g. Monte Carlo EM, since it involves a typically expensive sampling loop per datapoint.
solution and application
  • efficient approximate ML or MAP estimation for θ (Full): Appendix F
    • allow us to mimic the hidden random process and generate artificial data that resemble the real data
  • efficient approximate posterior inference pθ(z|x) for a choice of θ
    • useful for coding or data representation tasks
  • efficient approximate marginal inference of x: Appendix D
    • allow us to perform all kinds of inference tasks where p(x) is required, such as image denoising, inpainting, and super-resolution.

1. derivation of the variational bound

logpθ(x(1),x(N))=i=1Nlogpθ(x(i))

Here we use xi to represent x(i)

logp(xi)=zq(z|xi)logp(xi)dz  (q can be any distribution)=zq(z|xi)logp(z,xi)p(z|xi)dz=zq(z|xi)log[q(z|xi)p(z|xi)p(z,xi)q(z|xi)]dz=zq(z|xi)logq(z|xi)p(z|xi)dz+zq(z|xi)logp(z,xi)q(z|xi)dz=DKL[qϕ(z|xi)pθ(z|xi)]+LB(θ,ϕ;xi)

Becuase DKL0, so LB is called the (variational) lower bound, then we have

logpθ(xi)LB(θ,ϕ;xi)

LB(θ,ϕ;xi)=Eqϕ(z|x)[logpθ(x,z)logqϕ(z|x)]=zq(z|xi)logp(z,xi)q(z|xi)dz=zq(z|xi)logp(xi|z)p(z)q(z|xi)dz=DKL[q(z|xi)p(z)]+zq(z|xi)logp(xi|z)dz=DKL[qϕ(z|xi)pθ(z)]+Eqϕ(z|xi)[logpθ(xi|z)]

  • DKL[qϕ(z|xi)pθ(z)]: act as a regularizer
  • Eqϕ(z|xi)[logpθ(xi|z)]: a an expected negative reconstruction error
  • TARGET: defferentiate and optimize LB w.r.t. both ϕ and θ. However, ϕLB is problematic.

2. Solution-1 Naive Monte Carlo gradient estimator

  • disadvantages: high variance & impractical for this purpose, 原文中出现的公式如下:
    ϕEqϕ(z)[f(z)]=Eqϕ(z)[f(z)qϕ(z)logqϕ(z)]1Ll=1Lf(z)qϕ(zl)logqϕ(zl)where zlqϕ(z|xi)

但由于我还没来得及学Monte Carlo Gradient Estimator的理论,根据VAE这边论文后面的公式,个人觉得…上面的公式应该是(数学功底不够深厚,不确定二者是否等价):

ϕEqϕ(z)[f(z)]=Eqϕ(z)[f(z)qϕ(z)logqϕ(z)]1Ll=1Lf(zl)where zlqϕ(z|xi)

3. Solution-2 SGVB estimator

  • reparamterize z~qϕ(z|x) using a differentiable transformation gϕ(ϵ,x) of an (auxiliary) noise variable ϵ
    • under certain mild conditions for a chosen approximate posterior qϕ(z|x)
      z~=gϕ(ϵ,x) with ϵp(ϵ)
  • form Monte Carlo estimates as follows:
    qϕ(z|x)idzi=p(ϵ)idϵiqϕ(z|x)f(z)dz=p(ϵ)f(z)dϵ=p(ϵ)f(gϕ(ϵ,x))dϵEqϕ(z|xi)[f(z)]=Ep(ϵ)[f(gϕ(ϵ,xi))]1Ll=1Lf(gϕ(ϵl,xi))where ϵlp(ϵ)
  • apply the MC estimator technique to LB(θ,ϕ;xi), yielding 2 SGVB estimator L~A and L~B:
    L~A(θ,ϕ;xi)=1Ll=1Llogpθ(xi,zi,l)logqϕ(zi,l|xi)L~B(θ,ϕ;xi)=DKL(qϕ(z|xi)pθ(z))+1Ll=1Llogpθ(xi|zi,l)where zi,l=gϕ(ϵi,l,xi) and ϵlp(ϵ)
  • minibatch with size M
    LB(θ,ϕ;X)L~M(θ,ϕ;XM)=NMi=1ML~(θ,ϕ;xi)

    • the number of samples L per datapoint can be set to 1 as long as the minibatch size M was large enough, e.g. M=100
3.1 Minibatch version of AEVB algorithm
  • θ,ϕ Initialize parameters
  • repeate
    • XM Random minibatch of M datapoints
    • ϵ Random samples from noise distribution p(ϵ)
    • gθ,ϕL~M(θ,ϕ;XM,ϵ)
    • θ,ϕ Update parameters using gradients g (e.g. SGD or Adagrad)
  • until convergence of parameters θ,ϕ
  • return θ,ϕ

chosen of qϕ(z|x), p(ϵ), and gϕ(ϵ,x)

There are three basic approaches:

  • Tractable inverse CDF. Let ϵU(0,I), gϕ(ϵ,x) be the inverse CDF of qϕ(z|x).
    • Examples: Exponential, Cauchy, Logistic, Rayleigh, Pareto, Weibull, Reciprocal, Gompertz, Gumbel and Erlang distributions.
  • ”location-scale” family of distributions: choose the standard distribution (with location = 0, scale = 1) as the auxiliary variable ϵ, and let g()=location+scaleϵ
    • Examples: Laplace, Elliptical, Student’s t, Logistic, Uniform, Triangular and Gaussian distributions.
    • 下文介绍的VAE即适用于此种情况
  • 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.

Variational Auto-Encoder

  • let pθ(z)=N(z;0,I)
  • pθ(z|x) is intractable
  • use a neural network for qϕ(z|x)
  • ϕ and θ are optimized jointly with the AEVB algorithm
  • params of pθ(x|z) are computed from z with a MLP (multi-layered perceptrons, a fully-connected neural network with a hidden layer)
    • multivariae Gaussian: in case of real-valued data
      logp(x|z)=logN(x;μ,σ2I)where μ=Wμh+bμlogσ2=Wσh+bσh=tanh(Whz+bh)
    • Bernouli: incase of binary data
      logp(x|z)=i=1Dxilogyi+(1xi)log(1yi)where y=fσ(Wytanh(Wh+bh)+by)fσ():elementwise sigmoid activation function

      Auto-encoding Variational Bayes 阅读笔记
      Auto-encoding Variational Bayes 阅读笔记

From what mentioned above, we have:

logqϕ(z|xi)=logN(z;μi,σ2,iI)

where μi and σi are outputs of the encoding MLP.

We sample form zi,lqϕ(z|xi) using zi,l=gϕ(xi,ϵl)=μi+σiϵl, where ϵlN(0,I) and denotes element-wize product.

Here both pθ(z) and qϕ(z|x) are Gaussian, so we can use the estimator L~B, since the KL divergence item is analytical. Then we have:

L(θ,ϕ;xi)DKL(qϕ(z|xi)pθ(z))+1Ll=1Llogpθ(xi|zi,l)12j=1L(1+log(σji2)μji2σji2)+1Ll=1Llogpθ(xi|zi,l)where zil=μi+σiϵl and ϵlN(0,I)

Solution of DKL(qϕ(z)pθ(z)), Gaussian case

Let J be the dimensionality of z, then we have:

qθ(z)logpθ(z)dz=N(z;μ,σ2)logN(z;0,I)dz=J2log(2π)12j=1J(μj2+σj2)

And:

qθ(z)logqθ(z)dz=N(z;μ,σ2)logN(z;μ,σ2)dz=J2log(2π)12j=1J(1+logσj2)

Therefore:

DKL(qϕ(z)pθ(z))=qθ(z)(logpθ(z)logqθ(z))dz=12j=1L(1+log(σji2)μji2σji2)

此处附上相关证明:
Auto-encoding Variational Bayes 阅读笔记

Visulization

Since the prior of the latent space is Gaussian, linearly spaced coordinates on the unit square were transformed through the inverse CDF of the Gaussian to produce values of the latent variables z.