Stochastic Backpropagation and Approximate Inference in Deep Generative Models

Danilo Jimenez Rezende, Shakir Mohamed, Daan Wierstra

Appendix A Additional Model Details

In equation (LABEL:eq:LogLike) we showed an alternative form of the joint log likelihood that explicitly separates the deterministic and stochastic parts of the generative model and corroborates the view that the generative model works by applying a complex non-linear transformation to a spherical Gaussian distribution \mathcal{N}(\mbox{\mbox{ξ\boldsymbol{\xi}}}|\mbox{\mbox{0\boldsymbol{0}}},\mbox{\mbox{I\mathbf{I}}}) such that the transformed distribution best matches the empirical distribution. We provide more details on this view here for clarity.

From the model description in equations (LABEL:eq:HiddenGen) and (LABEL:eq:Visible), we can interpret the variables hl\mathbf{h}_{l} as deterministic functions of the noise variables \mbox{\mbox{ξ\boldsymbol{\xi}}}_{l}. This can be formally introduced as a coordinate transformation of the probability density in equation (LABEL:eq:LogLikeStandard): we perform a change of coordinates \mathbf{h}_{l}\rightarrow\mbox{\mbox{ξ\boldsymbol{\xi}}}_{l}. The density of the transformed variables \mbox{\mbox{ξ\boldsymbol{\xi}}}_{l} can be expressed in terms of the density (LABEL:eq:LogLikeStandard) times the determinant of the Jacobian of the transformation p(\mbox{\mbox{ξ\boldsymbol{\xi}}}_{l})=p(\mathbf{h}_{l}(\mbox{\mbox{ξ\boldsymbol{\xi}}}_{l}))|\frac{\partial\mathbf{h}_{l}}{\partial\mbox{\mbox{ξ\boldsymbol{\xi}}}_{l}}|. Since the co-ordinate transformation is linear we have |\frac{\partial\mathbf{h}_{l}}{\partial\mbox{\mbox{ξ\boldsymbol{\xi}}}_{l}}|=|\mbox{\mbox{G\mathbf{G}}}_{l}| and the distribution of \mbox{\mbox{ξ\boldsymbol{\xi}}}_{l} is obtained as follows:

Combining this equation with the distribution of the visible layer we obtain equation (LABEL:eq:LogLike).

Below we provide simple, explicit examples of generative and recognition models.

In the case of a two-layer model the activation \mathbf{h}_{1}(\mbox{\mbox{ξ\boldsymbol{\xi}}}_{1,2}) in equation (LABEL:eq:LogLike) can be explicitly written as

Similarly, a simple recognition model consists of a single deterministic layer and a stochastic Gaussian layer with the rank-one covariance structure and is constructed as:

where the function ff is a rectified linearity (but other non-linearities such as tanh can be used).

Appendix B Proofs for the Gaussian Gradient Identities

Here we review the derivations of Bonnet’s and Price’s theorems that were presented in section LABEL:sec:stochBP.

Let f(\mbox{\mbox{ξ\boldsymbol{\xi}}}):R^{d}\mapsto R be a integrable and twice differentiable function. The gradient of the expectation of f(\mbox{\mbox{ξ\boldsymbol{\xi}}}) under a Gaussian distribution \mathcal{N}(\mbox{\mbox{ξ\boldsymbol{\xi}}}|\mbox{\mbox{μ\boldsymbol{\mu}}},\mbox{\mbox{C\mathbf{C}}}) with respect to the mean μ\boldsymbol{\mu} can be expressed as the expectation of the gradient of f(\mbox{\mbox{ξ\boldsymbol{\xi}}}).

in moving from step 1 to 2. From step 2 to 3 we have used the product rule for integrals with the first term evaluating to zero. ∎

Under the same conditions as before. The gradient of the expectation of f(\mbox{\mbox{ξ\boldsymbol{\xi}}}) under a Gaussian distribution \mathcal{N}(\mbox{\mbox{ξ\boldsymbol{\xi}}}|\mbox{\mbox{0\boldsymbol{0}}},\mbox{\mbox{C\mathbf{C}}}) with respect to the covariance C\mathbf{C} can be expressed in terms of the expectation of the Hessian of f(\mbox{\mbox{ξ\boldsymbol{\xi}}}) as

In moving from steps 1 to 2, we have used the identity

which can be verified by taking the derivatives on both sides and comparing the resulting expressions. From step 2 to 3 we have used the product rule for integrals twice. ∎

Appendix C Deriving Stochastic Back-propagation Rules

In section LABEL:sec:stochBP we described two ways in which to derive stochastic back-propagation rules. We show specific examples and provide some more discussion in this section.

We can derive rules for stochastic back-propagation for many distributions by finding a appropriate non-linear function B(x;θ)B(x;\theta) that allows us to express the gradient with respect to the parameters of the distribution as a gradient with respect to the random variable directly. The approach we described in the main text was:

where we have introduced the non-linear function B(x;θ)B(x;\theta) to allow for the transformation of the gradients and have applied the product rule for integrals (rule for integration by parts) to rewrite the integral in two parts in the second line, and the supp(x)(x) indicates that the term is evaluated at the boundaries of the support. To use this approach, we require that the density we are analysing be zero at the boundaries of the support to ensure that the first term in the second line is zero.

As an alternative, we can also write this differently and find an non-linear function of the form:

Consider general exponential family distributions of the form:

where h(x)h(x) is the base measure, θ\theta is the set of mean parameters of the distribution, η\eta is the set of natural parameters, and A(θ)A(\theta) is the log-partition function. We can express the non-linear function in (9) using these quantities as:

This can be derived for a number of distributions such as the Gaussian, inverse Gamma, Log-Normal, Wald (inverse Gaussian) and other distributions. We show some of these below:

The B(x;θ)B(x;\theta) corresponding to the second formulation can also be derived and may be useful in certain situations, requiring the solution of a first order differential equation. This approach of searching for non-linear transformations leads us to the second approach for deriving stochastic back-propagation rules.

C.2 Using Alternative Coordinate Transformations

There are many distributions outside the exponential family that we would like to consider using. A simpler approach is to search for a co-ordinate transformation that allows us to separate the deterministic and stochastic parts of the distribution. We described the case of the Gaussian in section LABEL:sec:stochBP. Other distributions also have this property. As an example, consider the Levy distribution (which is a special case of the inverse Gamma considered above). Due to the self-similarity property of this distribution, if we draw XX from a Levy distribution with known parameters X∼Levy(μ,λ)X\sim\textrm{Levy}(\mu,\lambda), we can obtain any other Levy distribution by rescaling and shifting this base distribution: kX+b∼Levy(kμ+b,kc)kX+b\sim\textrm{Levy}(k\mu+b,kc).

Many other distributions hold this property, allowing stochastic back-propagation rules to be determined for distributions such as the Student’s t-distribution, Logistic distribution, the class of stable distributions and the class of generalised extreme value distributions (GEV). Examples of co-ordinate transformations T(⋅)T(\cdot) and the resulsting distributions are shown below for variates XX drawn from the standard distribution listed in the first column.

Appendix D Variance Reduction using Control Variates

An alternative approach for stochastic gradient computation is commonly based on the method of control variates. We analyse the variance properties of various estimators in a simple example using univariate function. We then show the correspondence of the widely-known REINFORCE algorithm to the general control variate framework.

where bb is a baseline typically chosen to reduce the variance of the estimator.

The assumption of weakly correlated terms is relevant for variational learning in larger generative models where independence assumptions and structure in the variational distribution result in free energies that are summations over weakly correlated or independent terms.

D.2 Univariate variance analysis

In analysing the variance properties of many estimators, we discuss the general scaling of likelihood ratio approaches in appendix D. As an example to further emphasise the high-variance nature of these alternative approaches, we present a short analysis in the univariate case.

Consider a random variable p(ξ)=N(ξ∣μ,σ2)p(\xi)=\mathcal{N}(\xi|\mu,\sigma^{2}) and a simple quadratic function of the form

For this function we immediately obtain the following variances

Equations (15), (16) and (17) correspond to the variance of the estimators based on (LABEL:eq:bonnet), (LABEL:eq:price), (LABEL:eq:gradR) respectively whereas equation (18) corresponds to the variance of the REINFORCE algorithm for the gradient with respect to μ\mu.

From these relations we see that, for any parameter configuration, the variance of the REINFORCE estimator is strictly larger than the variance of the estimator based on (LABEL:eq:bonnet). Additionally, the ratio between the variances of the former and later estimators is lower-bounded by 5/25/2. We can also see that the variance of the estimator based on equation (LABEL:eq:price) is zero for this specific function whereas the variance of the estimator based on equation (LABEL:eq:gradR) is not.

Appendix E Estimating the Marginal Likelihood

We compute the marginal likelihood by importance sampling by generating SS samples from the recognition model and using the following estimator:

Appendix F Missing Data Imputation

Image completion can be approximatively achieved by a simple iterative procedure which consists of (i) initializing the non-observed pixels with random values; (ii) sampling from the recognition distribution given the resulting image; (iii) reconstruct the image given the sample from the recognition model; (iv) iterate the procedure.

We denote the observed and missing entries in an observation as vo,vm\mathbf{v}_{o},\mathbf{v}_{m}, respectively. The observed vo\mathbf{v}_{o} is fixed throughout, therefore all the computations in this section will be conditioned on vo\mathbf{v}_{o}. The imputation procedure can be written formally as a Markov chain on the space of missing entries vm\mathbf{v}_{m} with transition kernel Tq(vm′∣vm,vo)T^{q}(\mathbf{v}^{\prime}_{m}|\mathbf{v}_{m},\mathbf{v}_{o}) given by

where v=(vm,vo)\mathbf{v}=(\mathbf{v}_{m},\mathbf{v}_{o}).

Provided that the recognition model q(ξ∣v)q(\xi|\mathbf{v}) constitutes a good approximation of the true posterior p(ξ∣v)p(\xi|\mathbf{v}), (20) can be seen as an approximation of the kernel

The kernel (21) has two important properties: (i) it has as its eigen-distribution the marginal p(vm∣vo)p(\mathbf{v}_{m}|\mathbf{v}_{o}); (ii) T(vm′∣vm,vo)>0 ∀vo,vm,vm′T(\mathbf{v}^{\prime}_{m}|\mathbf{v}_{m},\mathbf{v}_{o})>0~{}\forall\mathbf{v}_{o},\mathbf{v}_{m},\mathbf{v}^{\prime}_{m}. The property (i) can be derived by applying the kernel (21) to the marginal p(vm∣vo)p(\mathbf{v}_{m}|\mathbf{v}_{o}) and noting that it is a fixed point. Property (ii) is an immediate consequence of the smoothness of the model.

We apply the fundamental theorem for Markov chains (Neal, 1993, pp. 38) and conclude that given the above properties, a Markov chain generated by (21) is guaranteed to generate samples from the correct marginal p(vm∣vo)p(\mathbf{v}_{m}|\mathbf{v}_{o}).

In practice, the stationary distribution of the completed pixels will not be exactly the marginal p(vm∣vo)p(\mathbf{v}_{m}|\mathbf{v}_{o}), since we use the approximated kernel (20). Even in this setting we can provide a bound on the L1L_{1} norm of the difference between the resulting stationary marginal and the target marginal p(vm∣vo)p(\mathbf{v}_{m}|\mathbf{v}_{o})

If the recognition model q(ξ∣v)q(\xi|\mathbf{v}) is such that for all ξ\xi

then the marginal p(vm∣vo)p(\mathbf{v}_{m}|\mathbf{v}_{o}) is a weak fixed point of the kernel (20) in the following sense:

where we apply the condition (22) to obtain the last statement. ∎

That is, if the recognition model is sufficiently close to the true posterior to guarantee that (22) holds for some acceptable error ε\varepsilon than (23) guarantees that the fixed-point of the Markov chain induced by the kernel (20) is no further than ε\varepsilon from the true marginal with respect to the L1L_{1} norm.

Appendix G Variational Bayes for Deep Directed Models

In the main test we focussed on the variational problem of specifying an posterior on the latent variables only. It is natural to consider the variational Bayes problem in which we specify an approximate posterior for both the latent variables and model parameters.

Following the same construction and considering an Gaussian approximate distribution on the model parameters \mbox{\mbox{θ\boldsymbol{\theta}}}^{g}, the free energy becomes:

which now includes an additional term for the cost of using parameters and their regularisation. We must now compute the additional set of gradients with respect to the parameter’s mean mjm_{j} and variance τj\tau_{j} are:

Appendix H Additional Simulation Details

We use training data of various types including binary and real-valued data sets. In all cases, we train using mini-batches, which requires the introduction of scaling terms in the free energy objective function (LABEL:eq:FEsimp) in order to maintain the correct scale between the prior over the parameters and the remaining terms (Ahn et al., 2012; Welling & Teh, 2011). We make use of the objective:

where nn is an index over observations in the mini-batch and λ\lambda is equal to the ratio of the data-set and the mini-batch size. At each iteration, a random mini-batch of size 200 observations is chosen.

All parameters of the model were initialized using samples from a Gaussian distribution with mean zero and variance 1×1061\times 10^{6}; the prior variance of the parameters was κ=1×106\kappa=1\times 10^{6}. We compute the marginal likelihood on the test data by importance sampling using samples from the recognition model; we describe our estimator in appendix E.

References