Title: IMPROVING SAMPLING FROM GENERATIVE AUTOENCODERS WITH MARKOV CHAINS

Abstract: We focus on generative autoencoders, such as variational or adversarial autoencoders, which jointly learn a generative model alongside an inference model. Generative autoencoders are those which are trained to softly enforce a prior on the latent distribution learned by the inference model. We call the distribution to which the inference model maps observed samples, the learned latent distribution, which may not be consistent with the prior. We formulate a Markov chain Monte Carlo (MCMC) sampling process, equivalent to iteratively decoding and encoding, which allows us to sample from the learned latent distribution. Since, the generative model learns to map from the learned latent distribution, rather than the prior, we may use MCMC to improve the quality of samples drawn from the generative model, especially when the learned latent distribution is far from the prior. Using MCMC sampling, we are able to reveal previously unseen differences between generative autoencoders trained either with or without a denoising criterion.

1. INTRODUCTION:

Unsupervised learning has benefited greatly from the introduction of deep generative models. In particular, the introduction of generative adversarial networks (GANs) (Goodfellow et al., 2014) and variational autoencoders (VAEs) (Kingma & Welling, 2014; Rezende et al., 2014) has led to a plethora of research into learning latent variable models that are capable of generating data from complex distributions, including the space of natural images (Radford et al., 2015) . Both of these models, and their extensions, operate by placing a prior distribution, P (Z), over a latent space Z ⊆ R b , and learn mappings from the latent space, Z, to the space of the observed data, X ⊆ R a .

We are interested in autoencoding generative models, models which learn not just the generative mapping Z → X, but also the inferential mapping X → Z. Specifically, we define generative autoencoders as autoencoders which softly constrain their latent distribution, to match a specified prior distribution, P (Z). This is achieved by minimising a loss, L prior , between the latent distribution and the prior. This includes VAEs (Kingma & Welling, 2014; Rezende et al., 2014) , extensions of VAEs (Kingma et al., 2016) , and also adversarial autoencoders (AAEs) (Makhzani et al., 2015) . Whilst other autoencoders also learn an encoding function, e : R a → Z, together with a decoding function, d : R b → X, the latent space is not necessarily constrained to conform to a specified probability distribution. This is the key distinction for generative autoencoders; both e and d can still be deterministic functions (Makhzani et al., 2015) .

The functions e and d are defined for any input from R a and R b respectively, however the outputs of the functions may be constrained practically by the type of functions that e and d are, such that e maps to Z ⊆ R b and d maps to X ⊆ R a . During training however, the encoder, e is only fed with training data samples, x ∈ X and the decoder, d is only fed with samples from the encoder, z ∈ Z, and so the encoder and decoder learn mappings between X and Z.

The process of encoding and decoding may be interpreted as sampling the conditional probabilities Q φ (Z|X) and P θ (X|Z) respectively. The conditional distributions may be sampled using the encoding and decoding functions e(X; φ) and d(Z; θ), where φ and θ are learned parameters of the encoding and decoding functions respectively. The decoder of a generative autoencoder may be used to generate new samples that are consistent with the data. There are two traditional approaches for sampling generative autoencoders:

Approach 1 (Bengio et al., 2014) :

x 0 ∼ P (X), z 0 ∼ Q φ (Z|X = x 0 ), x 1 ∼ P θ (X|Z = z 0 )

where P (X) is the data generating distribution. However, this approach is likely to generate samples similar to those in the training data, rather than generating novel samples that are consistent with the training data.

Approach 2 (Kingma & Welling, 2014; Makhzani et al., 2015; Rezende et al., 2014) :

z 0 ∼ P (Z), x 0 ∼ P θ (X|Z = z 0 )

where P (Z) is the prior distribution enforced during training and P θ (X|Z) is the decoder trained to map samples drawn from Q φ (Z|X) to samples consistent with P (X). This approach assumes that Q φ (Z|X)P (X)dX = P (Z), suggesting that the encoder maps all data samples from P (X) to a distribution that matches the prior distribution, P (Z). However, it is not always true that Q φ (Z|X)P (X)dX = P (Z). Rather Q φ (Z|X) maps data samples to a distribution which we call, P (Z):

Q φ (Z|X)P (X)dX = P (Z)

where it is not necessarily true that P (Z) = P (Z) because the prior is only softly enforced. The decoder, on the other hand, is trained to map encoded data samples (i.e. samples from Q φ (Z|X)P (X)dX) to samples from X which have the distribution P (X). If the encoder maps observed samples to latent samples with the distribution P (Z), rather than the desired prior distribution, P (Z), then:

P θ (X|Z)P (Z)dZ = P (X)

This suggests that samples drawn from the decoder, P θ (X|Z), conditioned on samples drawn from the prior, P (Z), may not be consistent with the data generating distribution, P (X). However, by conditioning on P (Z):

P θ (X|Z) P (Z)dZ = P (X)

This suggests that to obtain more realistic generations, latent samples should be drawn via z ∼ P (Z) rather than z ∼ P (Z), followed by x ∼ P θ (X|Z). A limited number of latent samples may be drawn from P (Z) using the first two steps in Approach 1 -however this has the drawbacks discussed in Approach 1. We introduce an alternative method for sampling from P (Z) which does not have the same drawbacks.

Our main contribution is the formulation of a Markov chain Monte Carlo (MCMC) sampling process for generative autoencoders, which allows us to sample from P (Z). By iteratively sampling the chain, starting from an arbitrary z t=0 ∈ R b , the chain converges to z t→∞ ∼ P (Z), allowing us to draw latent samples from P (Z) after several steps of MCMC sampling. From a practical perspective, this is achieved by iteratively decoding and encoding, which may be easily applied to existing generative autoencoders. Because P (Z) is optimised to be close to P (Z), the initial sample, z t=0 can be drawn from P (Z), improving the quality of the samples within a few iterations.

When interpolating between latent encodings, there is no guarantee that z stays within high density regions of P (Z). Previously, this has been addressed by using spherical, rather than linear interpolation of the high dimensional Z space (White, 2016) . However, this approach attempts to keep z Figure 1 : P (X) is the data generating distribution. We may access some samples from P (X) by drawing samples from the training data. Q φ (Z|X) is the conditional distribution, modeled by an encoder, which maps samples from R a to samples in R b . An ideal encoder maps samples from P (X) to a known, prior distribution P (Z): in reality the encoder maps samples from P (X) to an unknown distribution P (Z). P θ (X|Z) is a conditional distribution, modeled by a decoder, which maps samples from R b to R a . During training the decoder learns to map samples drawn from P (Z) to P (X) rather than samples drawn from P (Z) because the decoder only sees samples from P (Z). Regularisation on the latent space only encourages P (Z) to be close to P (Z). Note that if L prior is optimal, then P (Z) overlaps fully with P (Z). (White, 2016) between two faces using a VAE (a, c). In (a), the attempt to gradually generate sunglasses results in visual artifacts around the eyes. In (c), the model fails to properly capture the desired change in orientation of the face, resulting in three partial faces in the middle of the interpolation. This work: (b) and (d) are the result of 5 steps of MCMC sampling applied to the latent samples that were used to generate the original interpolations, (a) and (c). In (b), the discolouration around the eyes disappears, with the model settling on either generating or not generating glasses. In (d), the model moves away from multiple faces in the interpolation by producing new faces with appropriate orientations. within P (Z), rather than trying to sample from P (Z). By instead applying several steps of MCMC sampling to the interpolated z samples before sampling P θ (X|Z), unrealistic artifacts can be reduced (see Figure 2 ). Whilst most methods that aim to generate realistic samples from X rely on adjusting encodings of the observed data (White, 2016) , our use of MCMC allows us to walk any latent sample to more probable regions of the learned latent distribution, resulting in more convincing generations. We demonstrate that the use of MCMC sampling improves generations from both VAEs and AAEs with high-dimensional Z; this is important as previous studies have shown that the dimensionality of Z should be scaled with the intrinsic latent dimensionality of the observed data.

Our second contribution is the modification of the proposed transition operator for the MCMC sampling process to denoising generative autoencoders. These are generative autoencoders trained using a denoising criterion, (Seung, 1997; Vincent et al., 2008) . We reformulate our original MCMC sampling process to incorporate the noising and denoising processes, allowing us to use MCMC sampling on denoising generative autoencoders. We apply this sampling technique to two models. The first is the denoising VAE (DVAE) introduced by Im et al. (2015) . We found that MCMC sampling revealed benefits of the denoising criterion. The second model is a denoising AAE (DAAE), constructed by applying the denoising criterion to the AAE. There were no modifications to the cost function. For both the DVAE and the DAAE, the effects of the denoising crtierion were not immediately obvious from the initial samples. Training generative autoencoders with a denoising criterion reduced visual artefacts found both in generations and in interpolations. The effect of the denoising criterion was revealed when sampling the denoising models using MCMC sampling.

2. BACKGROUND:

One of the main tasks in machine learning is to learn explanatory factors for observed data, commonly known as inference. That is, given a data sample x ∈ X ⊆ R a , we would like to find a corresponding latent encoding z ∈ Z ⊆ R b . Another task is to learn the inverse, generative mapping from a given z to a corresponding x. In general, coming up with a suitable criterion for learning these mappings is difficult. Autoencoders solve both tasks efficiently by jointly learning an inferential mapping e(X; φ) and generative mapping d(Z; θ), using unlabelled data from X in a self-supervised fashion (Kingma & Welling, 2014) . The basic objective of all autoencoders is to minimise a reconstruction cost, L reconstruct , between the original data, X, and its reconstruction, d(e(X; φ); θ). Examples of L reconstruct include the squared error loss, 1 2 N n=1 d(e(x n ; φ); θ) -x n 2 , and the cross-entropy loss, H[P (X) P (d(e(X; φ); θ))] =

- N n=1 x n log(d(e(x n ; φ); θ)) + (1 -x n ) log(1 -d(e(x n ; φ); θ)).

Autoencoders may be cast into a probablistic framework, by considering samples x ∼ P (X) and z ∼ P (Z), and attempting to learn the conditional distributions Q φ (Z|X) and P θ (X|Z) as e(X; φ) and d(Z; θ) respectively, with L reconstruct representing the negative log-likelihood of the reconstruction given the encoding (Bengio, 2009) . With any autoencoder, it is possible to create novel x ∈ X by passing a z ∈ Z through d(Z; θ), but we have no knowledge of appropriate choices of z beyond those obtained via e(X; φ). One solution is to constrain the latent space to which the encoding model maps observed samples. This can be achieved by an additional loss, L prior , that penalises encodings far away from a specified prior distribution, P (Z). We now review two types of generative autoencoders, VAEs (Kingma & Welling, 2014; Rezende et al., 2014) and AAEs (Makhzani et al., 2015) , which each take different approaches to formulating L prior .

2.1. GENERATIVE AUTOENCODERS:

Consider the case where e is constructed with stochastic neurons that can produce outputs from a specified probability distribution, and L prior is used to constrain the distribution of outputs to P (Z). This leaves the problem of estimating the gradient of the autoencoder over the expectation E Q φ (Z|X) , which would typically be addressed with a Monte Carlo method. VAEs sidestep this by constructing latent samples using a deterministic function and a source of noise, moving the source of stochasticity to an input, and leaving the network itself deterministic for standard gradient calculations-a technique commonly known as the reparameterisation trick (Kingma & Welling, 2014 ). e(X; φ) then consists of a deterministic function, e rep (X; φ), that outputs parameters for a probability distribution, plus a source of noise. In the case where P (Z) is a diagonal covariance Gaussian, e rep (X; φ) + , with the noise ∼ N (0, I). Put together, the encoder outputs samples z = µ + σ, where is the Hadamard product. VAEs attempt to make these samples from the encoder match up with P (Z) by using the KL divergence between the parameters for a probability distribution outputted by e rep (X; φ), and the parameters for the prior distribution, giving

L prior = D KL [Q φ (Z|X) P (Z)].

A multivariate Gaussian has an analytical KL divergence that can be further simplified when considering the unit Gaussian, resulting in

L prior = 1 2 N n=1 µ 2 + σ 2 -log(σ 2 ) -1.

Another approach is to deterministically output the encodings z. Rather than minimising a metric between probability distributions using their parameters, we can turn this into a density ratio estimation problem where the goal is to learn a conditional distribution, Q φ (Z|X), such that the distribution of the encoded data samples, P (Z) = Q φ (Z|X)P (X)dX, matches the prior distribution, P (Z). The GAN framework solves this density ratio estimation problem by transforming it into a class estimation problem using two networks (Goodfellow et al., 2014) . The first network in GAN training is the discriminator network, D ψ , which is trained to maximise the log probability of samples from the "real" distribution, z ∼ P (Z), and minimise the log probability of samples from the "fake" distribution, z ∼ Q φ (Z|X). In our case e(X; φ) plays the role of the second network, the generator network, G φ , which generates the "fake" samples. 1 The two networks compete in a minimax game, where G φ receives gradients from D ψ such that it learns to better fool D ψ . The training objective for both networks is given by

L prior = argmin φ argmax ψ E P (Z) [log(D ψ (Z))] + E P (X) [log(1 -D ψ (G φ (X)))] = argmin φ argmax ψ E P (Z) [log(D ψ (Z))] + E Q φ (Z|X)P (X) log[1 - D ψ (Z)]

. This formulation can create problems during training, so instead G φ is trained to minimise -log(D ψ (G φ (X))), which provides the same fixed point of the dynamics of G φ and D ψ . The result of applying the GAN framework to the encoder of an autoencoder is the deterministic AAE (Makhzani et al., 2015) .

2.2. DENOISING AUTOENCODERS:

In a more general viewpoint, generative autoencoders fulfill the purpose of learning useful representations of the observed data. Another widely used class of autoencoders that achieve this are denoising autoencoders (DAEs), which are motivated by the idea that learned features should be robust to "partial destruction of the input" (Vincent et al., 2008) . Not only does this require encoding the inputs, but capturing the statistical dependencies between the inputs so that corrupted data can be recovered (see Figure 3 ). DAEs are presented with a corrupted version of the input, x ∈ X, but must still reconstruct the original input, x ∈ X, where the noisy inputs are created through sampling x ∼ C( X|X), a corruption process. The denoising criterion, L denoise , can be applied to any type of autoencoder by replacing the straightforward reconstruction criterion, L reconstruct (X, d(e(X; φ); θ)), with the reconstruction criterion applied to noisy inputs: L reconstruct (X, d(e( X; φ); θ)). The encoder is now used to model samples drawn from Q φ (Z| X). As such, we can construct denoising generative autoencoders by training autoencoders to minimise L denoise + L prior .

One might expect to see differences in samples drawn from denoising generative autoencoders and their non-denoising counterparts. However, Figures 4 and 6 show that this is not the case. Im et al.

(2015) address the case of DVAEs, claiming that the noise mapping requires adjusting the original VAE objective function. Our work is orthogonal to theirs, and others which adjust the training or model (Kingma et al., 2016) , as we focus purely on sampling from generative autoencoders after training. We claim that the existing practice of drawing samples from generative autoencoders conditioned on z ∼ P (Z) is suboptimal, and the quality of samples can be improved by instead conditioning on z ∼ P (Z) via MCMC sampling.

3. MARKOV SAMPLING:

We now consider the case of sampling from generative autoencoders, where d(Z; θ) is used to draw samples from P θ (X|Z). In Section 1, we showed that it was important, when sampling P θ (X|Z), to condition on z's drawn from P (Z), rather than P (Z) as is often done in practice. However, we now show that for any initial z 0 ∈ Z 0 = R b , Markov sampling can be used to produce a chain of samples z t , such that as t → ∞, produces samples z t that are from the distribution P (Z), which may be used to draw meaningful samples from P θ (X|Z), conditioned on z ∼ P (Z). To speed up convergence we can initialise z 0 from a distribution close to P (Z), by drawing z 0 ∼ P (Z).

3.1. MARKOV SAMPLING PROCESS:

A generative autoencoder can be sampled by the following process:

z 0 ∈ Z 0 = R b , x t+1 ∼ P θ (X|Z t ), z t+1 ∼ Q φ (Z|X t+1 )

This allows us to define a Markov chain with the transition operator

EQUATION

for t ≥ 0.

Drawing samples according to the transition operator T (Z t+1 |Z t ) produces a Markov chain. For the transition operator to be homogeneous, the parameters of the encoding and decoding functions are fixed during sampling.

3.2. CONVERGENCE PROPERTIES:

We now show that the stationary distribution of sampling from the Markov chain is P (Z). Theorem 1. If T (Z t+1 |Z t ) defines an ergodic Markov chain, {Z 1 , Z 2 ...Z t }, then the chain will converge to a stationary distribution, Π(Z), from any arbitrary initial distribution. The stationary distribution Π(Z) = P (Z).

The proof of Theorem 1 can be found in (Rosenthal, 2001) . Lemma 1. T (Z t+1 |Z t ) defines an ergodic Markov chain.

Proof. For a Markov chain to be ergodic it must be both irreducible (it is possible to get from any state to any other state in a finite number of steps) and aperiodic (it is possible to get from any state to any other state without having to pass through a cycle). To satisfy these requirements, it is more than sufficient to show that T (Z t+1 |Z t ) > 0, since every z ∈ Z would be reachable from every other z ∈ Z. We show that P θ (X|Z) > 0 and Q φ (Z|X) > 0, giving T (Z t+1 |Z t ) > 0, providing the proof of this in Section A of the supplementary material.

Lemma 2. The stationary distribution of the chain defined by T (Z t+1 |Z t ) is Π(Z) = P (Z).

Proof. For the transition operator defined in Equation ( 1), the asymptotic distribution to which T (Z t+1 |Z t ) converges to is P (Z), because P (Z) is, by definition, the marginal of the joint distribution Q φ (Z|X)P (X), over which the L prior used to learn the conditional distribution Q φ (Z|X).

Using Lemmas 1 and 2 with Theorem 1, we can say that the Markov chain defined by the transition operator in Equation (1) will produce a Markov chain that converges to the stationary distribution Π(Z) = P (Z).

3.3. EXTENSION TO DENOISING GENERATIVE AUTOENCODERS:

A denoising generative autoencoder can be sampled by the following process:

z 0 ∈ Z 0 = R b , x t+1 ∼ P θ (X|Z t ), xt+1 ∼ C( X|X t+1 ), z t+1 ∼ Q φ (Z| Xt+1 ).

This allows us to define a Markov chain with the transition operator

EQUATION

for t ≥ 0.

The same arguments for the proof of convergence of Equation ( 1) can be applied to Equation (2).

3.4. RELATED WORK:

Our work is inspired by that of Bengio et al. (2013) ; denoising autoencoders are cast into a probabilistic framework, where P θ (X| X) is the denoising (decoder) distribution and C( X|X) is the corruption (encoding) distribution. X represents the space of corrupted samples. Bengio et al. (2013) define a transition operator of a Markov chain -using these conditional distributions -whose stationary distribution is P (X) under the assumption that P θ (X| X) perfectly denoises samples. The chain is initialised with samples from the training data, and used to generate a chain of samples from P (X). This work was generalised to include a corruption process that mapped data samples to latent variables (Bengio et al., 2014) , to create a new type of network called Generative Stochastic Networks (GSNs). However in GSNs (Bengio et al., 2014) the latent space is not regularised with a prior.

Our work is similar to several approaches proposed by Bengio et al. (2013; 2014) (Bengio et al., 2013) or it is not constrained (Bengio et al., 2014) .

Further, Rezende et al. ( 2014) explicitly assume that the distribution of latent samples drawn from Q φ (Z|X) matches the prior, P (Z). Instead, we assume that samples drawn from Q φ (Z|X) have a distribution P (Z) that does not necessarily match the prior, P (Z). We propose an alternative method for sampling P (Z) in order to improve the quality of generated image samples. Our motivation is also different to Rezende et al. ( 2014) since we use sampling to generate improved, novel data samples, while they use sampling to denoise corrupted samples.

3.5. EFFECT OF REGULARISATION METHOD:

The choice of L prior may effect how much improvement can be gained when using MCMC sampling, assuming that the optimisation process converges to a reasonable solution. We first consider the case of VAEs, which minimise D KL [Q φ (Z|X) P (Z)]. Minimising this KL divergence penalises the model P (Z) if it contains samples that are outside the support of the true distribution P (Z), which might mean that P (Z) captures only a part of P (Z). This means that when sampling P (Z), we may draw from a region that is not captured by P (Z). This suggests that MCMC sampling can improve samples from trained VAEs by walking them towards denser regions in P (Z).

Generally speaking, using the reverse KL divergence during training, D KL [P (Z) Q φ (Z|X)], penalises the model Q φ (Z|X) if P (Z) produces samples that are outside of the support of P (Z). By minimising this KL divergence, most samples in P (Z) will likely be in P (Z) as well. AAEs, on the other hand are regularised using the JS entropy, given by 1

2 D KL [P (Z) 1 2 (P (Z) + Q φ (Z|X))] + 1 2 D KL [Q φ (Z|X) 1 2 (P (Z) + Q φ (Z|X))].

Minimising this cost function attempts to find a compromise between the aforementioned extremes. However, this still suggests that some samples from P (Z) may lie outside P (Z), and so we expect AAEs to also benefit from MCMC sampling.

4. EXPERIMENTS:



4.1. MODELS:

We utilise the deep convolutional GAN (DCGAN) (Radford et al., 2015) as a basis for our autoencoder models. Although the recommendations from Radford et al. (2015) are for standard GAN architectures, we adopt them as sensible defaults for an autoencoder, with our encoder mimicking the DCGAN's discriminator, and our decoder mimicking the generator. The encoder uses strided convolutions rather than max-pooling, and the decoder uses fractionally-strided convolutions rather than a fixed upsampling. Each convolutional layer is succeeded by spatial batch normalisation (Ioffe & Szegedy, 2015) and ReLU nonlinearities, except for the top of the decoder which utilises a sigmoid function to constrain the output values between 0 and 1. We minimise the cross-entropy between the original and reconstructed images. Although this results in blurry images in regions which are ambiguous, such as hair detail, we opt not to use extra loss functions that improve the visual quality of generations (Larsen et al., 2015; Dosovitskiy & Brox, 2016; Lamb et al., 2016) to avoid confounding our results.

Although the AAE is capable of approximating complex probabilistic posteriors (Makhzani et al., 2015) , we construct ours to output a deterministic Q φ (Z|X). As such, the final layer of the encoder part of our AAEs is a convolutional layer that deterministically outputs a latent sample, z. The adversary is a fully-connected network with dropout and leaky ReLU nonlinearities. e rep (X; φ) of our VAEs have an output of twice the size, which corresponds to the means, µ, and standard deviations, σ, of a diagonal covariance Gaussian distribution. For all models our prior, P (Z), is a 200D isotropic Gaussian with zero mean and unit variance: N (0, I).

4.2. DATASETS:

Our primary dataset is the (aligned and cropped) CelebA dataset, which consists of 200,000 images of celebrities (Liu et al., 2015) . The DCGAN (Radford et al., 2015) was the first generative neural network model to show convincing novel samples from this dataset, and it has been used ever since as a qualitative benchmark due to the amount and quality of samples. In Figures 7 and 8 of the supplementary material, we also include results on the SVHN dataset, which consists of 100,000 images of house numbers extracted from Google Street view images (Netzer et al., 2011) .

4.3. TRAINING & EVALUATION:

For all datasets we perform the same preprocessing: cropping the centre to create a square image, then resizing to 64 × 64px. We train our generative autoencoders for 20 epochs on the training split of the datasets, using Adam (Kingma & Ba, 2014) with α = 0.0002, β 1 = 0.5 and β 2 = 0.999. The denoising generative autoencoders use the additive Gaussian noise mapping C( X|X) = N (X, 0.25I). All of our experiments were run using the Torch library (Collobert et al., 2011). 2 For evaluation, we generate novel samples from the decoder using z initially sampled from P (Z); we also show spherical interpolations (White, 2016) between four images of the testing split, as depicted in Figure 2 . We then perform several steps of MCMC sampling on the novel samples and interpolations. During this process, we use the training mode of batch normalisation (Ioffe & Szegedy, 2015) , i.e., we normalise the inputs using minibatch rather than population statistics, as the normalisation can partially compensate for poor initial inputs (see Figure 4 ) that are far from the training distribution. We compare novel samples between all models below, and leave further interpolation results to Figures 5 and 6 of the supplementary material. The adversarial criterion for deterministic AAEs is difficult to optimise when the dimensionality of Z is high. We observe that during training our AAEs and DAAEs, the empirical standard deviation of z ∼ Q φ (Z|X) is less than 1, which means that P (Z) fails to approximate P (Z) as closely as was achieved with the VAE and DVAE. However, this means that the effect of MCMC sampling is more pronounced, with the quality of all samples noticeably improving after a few steps. As a side-effect of the suboptimal solution learned by the networks, the denoising properties of the DAAE are more noticeable with the novel samples.

5. CONCLUSION:

Autoencoders consist of a decoder, d(Z; θ) and an encoder, e(X; φ) function, where φ and θ are learned parameters. Functions e(X; φ) and d(Z; θ) may be used to draw samples from the conditional distributions P θ (X|Z) and Q φ (Z|X) (Bengio et al., 2014; 2013; Rezende et al., 2014) , where X refers to the space of observed samples and Z refers to the space of latent samples. The encoder distribution, Q φ (Z|X), maps data samples from the data generating distribution, P (X), to a latent distribution, P (Z). The decoder distribution, P θ (X|Z), maps samples from P (Z) to P (X). We are concerned with generative autoencoders, which we define to be a family of autoencoders where regularisation is used during training to encourage P (Z) to be close to a known prior P (Z). Commonly it is assumed that P (Z) and P (Z) are similar, such that samples from P (Z) may be used to sample a decoder P θ (X|Z); we do not make the assumption that P (Z) and P (Z) are "sufficiently close" (Rezende et al., 2014) . Instead, we derive an MCMC process, whose stationary distribution is P (Z), allowing us to directly draw samples from P (Z). By conditioning on samples from P (Z), samples drawn from x ∼ P θ (X|Z) are more consistent with the training data.

In our experiments, we compare samples x ∼ P θ (X|Z = z 0 ), z 0 ∼ P (Z) to x ∼ P θ (X|Z = z i ) for i = {1, 5, 10}, where z i 's are obtained through MCMC sampling, to show that MCMC sampling improves initially poor samples (see Figure 4 ). We also show that artifacts in x samples induced by interpolations across the latent space can also be corrected by MCMC sampling see (Figure 2 ). We further validate our work by showing that the denoising properties of denoising generative autoencoders are best revealed by the use of MCMC sampling.

Our MCMC sampling process is straightforward, and can be applied easily to existing generative autoencoders. This technique is orthogonal to the use of more powerful posteriors in AAEs (Makhzani et al., 2015) and VAEs (Kingma et al., 2016) , and the combination of both could result in further improvements in generative modeling. Finally, our basic MCMC process opens the doors to apply a large existing body of research on sampling methods to generative autoencoders.

Supplementary Material:

A PROOF THAT T (Z t+1 |Z t ) > 0

For P θ (X|Z) > 0 we require that all possible x ∈ X ⊆ R a may be generated by the network. Assuming that the model P θ (X|Z) is trained using a sufficient number of training samples, x ∈ X train = X, and that the model has infinite capacity to model X train = X, then we should be able to draw any sample x ∈ X train = X from P θ (X|Z). In reality X train ⊆ X and it is not possible to have a model with infinite capacity. However, P θ (X|Z) is modeled using a deep neural network, which we assume has sufficient capacity to capture the training data well. Further, deep neural networks are able to interpolate between samples in very high dimensional spaces (Radford et al., 2015) ; we therefore further assume that if we have a large number of training samples (as well as large model capacity), that almost any x ∈ X can be drawn from P θ (X|Z).

Note that if we wish to generate human faces, we define X all to be the space of all possible faces, with distribution P (X all ), while X train is the space of faces made up by the training data. Then, practically even a well trained model which learns to interpolate well only captures an X, with distribution P θ (X|Z) P (Z)dZ, where X train ⊆ X ⊆ X all , because X additionally contains examples of interpolated versions of x ∼ P (X train ).

For Q φ (Z|X) > 0 it must be possible to generate all possible z ∈ Z ⊆ R b . Q φ (Z|X) is described by the function e(•; φ) : X → Z. To ensure that Q φ (Z|X) > 0, we want to show that the function e(X; φ) allows us to represent all samples of z ∈ Z. VAEs and AAEs each construct e(X; φ) to produce z ∈ Z in different ways.

The output of the encoder of a VAE, e V AE (X; φ) is z = µ + σ, where ∼ N (0, I). The output of a VAE is then always Gaussian, and hence there is no limitation on the z's that e V AE (X; φ) can produce. This ensures that Q φ (Z|X) > 0, provided that σ = 0.

The encoder of our AAE, e AAE (X; φ), is a deep neural network consisting of multiple convolutional and batch normalisation layers. The final layer of the e AAE (X; φ) is a fully connected layer without an activation function. The input to each of the M nodes in the fully connected layer is a function f i=1...M (x). This means that z is given by: z = a 1 f 1 (x) + a 2 f 2 (x) + ... + a M f M (x), where a i=1...M are the learned weights of the fully connected layer. We now consider three cases: Case 1: If a i are a complete set of bases for Z then it is possible to generate any z ∈ Z from an x ∈ X with a one-to-one mapping, provided that f i (x) is not restricted in the values that it can take.

Case 2: If a i are an overcomplete set of bases for Z, then the same holds, provided that f i (x) is not restricted in the values that it can take. Case 3: If a i are an undercomplete set of bases for Z then it is not possible to generate all z ∈ Z from x ∈ X. Instead there is a many (X) to one (Z) mapping.

For Q φ (Z|X) > 0 our network must learn a complete or overcomplete set of bases and f i (x) must not be restricted in the values that it can take ∀i. The network is encouraged to learn an overcomplete set of bases by learning a large number of a i 's-specifically M = 8192 when basing our network on the DCGAN architecture (Radford et al., 2015) -more that 40 times the dimensionality of Z. By using batch normalisation layers throughout the network, we ensure that values of f i (x) are spread out, capturing a close-to-Gaussian distribution (Ioffe & Szegedy, 2015) , encouraging infinite support.

We have now shown that, under certain reasonable assumptions, P θ (X|Z) > 0 and Q φ (Z|X) > 0, which means that T (Z t+1 |Z t ) > 0, and hence we can get from any Z to any another Z in only one step. Therefore the Markov chain described by the transition operator T (Z t+1 |Z t ) defined in Equation ( 1) is both irreducible and aperiodic, which are the necessary conditions for ergodicity. , f) . Interpolation between 1-and 2-digit numbers in an image (c, g) results in a meaningless blur in the middle of the interpolation. After a few steps of MCMC sampling the models instead produce more recognisable 1-or 2-digit numbers (d, h). We note that when the contrast is poor, denoising models in particular can struggle to recover meaningful images (h).

:

We adapt the variables to better fit the conventions used in the context of autoencoders.

Example code is available at https://github.com/Kaixhin/Autoencoders.

Figures and Tables:

Figure 2: Prior work: Spherically interpolating (White, 2016) between two faces using a VAE (a, c). In (a), the attempt to gradually generate sunglasses results in visual artifacts around the eyes. In (c), the model fails to properly capture the desired change in orientation of the face, resulting in three partial faces in the middle of the interpolation. This work: (b) and (d) are the result of 5 steps of MCMC sampling applied to the latent samples that were used to generate the original interpolations, (a) and (c). In (b), the discolouration around the eyes disappears, with the model settling on either generating or not generating glasses. In (d), the model moves away from multiple faces in the interpolation by producing new faces with appropriate orientations.

Figure 3: Reconstructions of faces from a DVAE trained with additive Gaussian noise: Q( X|X) = N (X, 0.25I). The model successfully recovers much of the detail from the noise-corrupted images.

Figure 4: Samples from a VAE (a-d), DVAE (e-h), AAE (i-l) and DAAE (m-p) trained on the CelebA dataset. (a), (e), (i) and (m) show initial samples conditioned on z ∼ P (Z), which mainly result in recognisable faces emerging from noisy backgrounds. After 1 step of MCMC sampling, the more unrealistic generations change noticeably, and continue to do so with further steps. On the other hand, realistic generations, i.e. samples from a region with high probability, do not change as much. The adversarial criterion for deterministic AAEs is difficult to optimise when the dimensionality of Z is high. We observe that during training our AAEs and DAAEs, the empirical standard deviation of z ∼ Q φ (Z|X) is less than 1, which means that P (Z) fails to approximate P (Z) as closely as was achieved with the VAE and DVAE. However, this means that the effect of MCMC sampling is more pronounced, with the quality of all samples noticeably improving after a few steps. As a side-effect of the suboptimal solution learned by the networks, the denoising properties of the DAAE are more noticeable with the novel samples.

Figure 5: Interpolating between two faces using (a-d) a DVAE. The top rows (a, c) for each face is the original interpolation, whilst the second rows (b, d) are the result of 5 steps of MCMC sampling applied to the latent samples that were used to generate the original interpolation. The only qualitative difference when compared to VAEs (see Figure 4) is a desaturation of the generated images.

Figure 6: Interpolating between two faces using (a-d) an AAE and (e-h) a DAAE. The top rows (a, c, e, g) for each face is the original interpolation, whilst the second rows (b, d, f, h) are the result of 5 steps of MCMC sampling applied to the latent samples that were used to generate the original interpolation. Although the AAE performs poorly (b, d), the regularisation effect of denoising can be clearly seen with the DAAE after applying MCMC sampling (f, h).

Figure 8: Interpolating between Google Street View house numbers using (a-d) a VAE and (e-h) a DVAE. The top rows (a, c, e, g) for each house number are the original interpolations, whilst the second rows (b, d, f, h) are the result of 5 steps of MCMC sampling. If the original interpolation produces symbols that do not resemble numbers, as observed in (a) and (e), the models will attempt to move the samples towards more realistic numbers (b, f). Interpolation between 1-and 2-digit numbers in an image (c, g) results in a meaningless blur in the middle of the interpolation. After a few steps of MCMC sampling the models instead produce more recognisable 1-or 2-digit numbers (d, h). We note that when the contrast is poor, denoising models in particular can struggle to recover meaningful images (h).

Peer review (iclr2017):
The authors argues that the standard ancestral sampling from stochastic autoencoders (such as the Variational Autoencoder and the Adversarial Autoencoder) imposes the overly-restrictive constraint that the encoder distribution must marginally match the latent variable prior. They propose, as an alternative, a Markov Chain Monte Carlo approach that avoids the need to specify a simple parametric form for the prior. The paper is not clearly written. Most critically, the notation the authors use is either deeply flawed, or there are simple misunderstanding with respect to the manipulations of probability distributions. For example, the authors seem to suggest that both distributions Q(Z|X) and Q(X|Z) are parametrized. For this to be true the model must either be trivially simple, or an energy-based model. There is no indication that they are speaking of an energy-based model. Another example of possible confusion is the statement that the ratio of distributions Q(Z|X)/P(Z) = 1. I believe this is supposed to be a ratio of marginals: Q(Z)/P(X) = 1. Overall, it seems like there is a confusion of what Q and P represent. The standard notation used in VAEs is to use P to represent the decoder distribution and Q to represent the encoder distribution. This seems not to be how the authors are using these terms. Nor does it seem like there is a single consistent interpretation. The empirical results consist entirely of qualitative results (samples and reconstructions) from a single dataset (CelebA). The samples are also not at all up to the quality of the SOTA models. The interpolations shown in Figures 1 and 3 both seems to look like interpolation in pixel space for both the VAE model and the proposed DVAE.