A G EOMETRIC P ERSPECTIVE ON V ARIATIONAL A UTOENCODERS
Anonymous authors
Paper under double-blind review
A BSTRACT
In this paper, we propose a geometrical interpretation of the Variational Autoencoder framework.
We show that VAEs naturally unveil a Riemannian structure of the learned latent space.
Moreover, we show that using these geometrical considerations can significantly improve the generation from the vanilla VAE which can now compete with more advanced VAE models on four benchmark datasets.
In particular, we propose a new way to generate samples consisting in sampling from the uniform distribution deriving intrinsically from the Riemannian manifold learned by a VAE.
We also stress the proposed method’s robustness in the low data regime which is known as very challenging for deep generative models.
Finally, we validate the method on a complex neuroimaging dataset combining both high dimensional data and low sample sizes.
I NTRODUCTION
Variational Autoencoders (VAE) (Kingma & Welling, 2014; Rezende et al., 2014) are powerful generative models that map complex input data into a much lower dimensional space referred to as the latent space while driving the latent variables to follow a given prior distribution.
Their simplicity to use in practice has made them very attractive models to perform various tasks such as high-fidelity image generation (Razavi et al., 2020), speech modeling (Blaauw & Bonada, 2016), clustering (Yang et al., 2019) or data augmentation (Chadebec et al., 2021).
Nonetheless, when taken in their simplest version, it was noted that these models produce most of the time blurry samples.
This undesired behavior may be due to several limitations of the VAE framework.
First, the training of a VAE aims at maximizing the Evidence Lower BOund (ELBO) which is only a lower bound on the true likelihood and so does not ensure that we are always actually improving the true objective (Burda et al., 2016;
Alemi et al., 2016; Higgins et al., 2017;
Cremer et al., 2018; Zhang et al., 2018).
Second, the prior distribution used as regularization and for sampling may be too simplistic (Dai & Wipf, 2018) leading to poor data generation and there exists no guarantee that the actual distribution of the latent code will match a given prior distribution inducing over-regularization (Connor et al., 2021).
Hence, trying to tackle those limitations through richer posterior distributions (Salimans et al., 2015; Rezende & Mohamed, 2015) or better priors (Tomczak & Welling, 2018) represents a major part of the proposed improvements over the past few years.
However, the tractability of the ELBO constrains the choice in distributions and so finding a trade-off between model expressiveness and tractability remains crucial.
In this paper, we take a rather different approach and focus on the geometrical aspects a vanilla VAE is able to capture in its latent space.
In particular, we propose the following contributions:
• We show that VAEs unveil naturally a latent space with a structure that can be modeled as a Riemannian manifold through the learned covariance matrices in the posterior distributions.
• We propose a natural sampling scheme consisting in sampling from a uniform distribution defined on the learned manifold and given by the metric.
We show that this procedure improves significantly the generation process from a vanilla VAE and makes it able to perform as well as more advanced VAE models in terms of Frechet Inception Distance (Heusel et al., 2017) and Precision and Recall (Sajjadi et al., 2019) scores on four benchmark datasets.
• We also show that the propose method appears more robust to dataset size changes and outperforms even more strongly peers when only smaller sample sizes are considered.
V ARIATIONAL A UTOENCODERS
Considering that we are given x ∈ X a set of data points deriving from an unknown distribution p ( x ) , a VAE aims at inferring such a distribution with a parametric model { p θ , θ ∈ Θ } using a maximum likelihood estimator.
A key assumption behind the VAE is to assume that the generation process also involves latent variables
z living in a lower dimensional space such that the generative model writes
[Equation]
where q prior is a prior distribution over the latent variables often taken as a standard Gaussian and p θ ( x | z ) is referred to as the decoder and is most of the time taken as a parametric distribution the parameters of which are estimated using neural networks.
Hence, the likelihood p θ writes:
[Equation]
As this integral is most of the time intractable so is p θ ( z | x ) , the posterior distribution.
Hence,
Variational Inference (Jordan et al., 1999) is used and a simple parametrized variational distribution q ϕ ( z | x ) is introduced to approximate the posterior p θ ( z | x ) .
q ϕ ( z | x ) is referred to as the encoder and, in the vanilla VAE, q ϕ is chosen as a multivariate Gaussian whose parameters µ ϕ and Σ ϕ are again given by neural networks.
An unbiased estimate of the likelihood p θ ( x ) can then be derived using importance sampling with q ϕ ( z | x ) and the ELBO objective follows using Jensen’s inequality:
[Equation]
The Evidence Lower BOund (ELBO) is now tractable since both p θ ( x | z ) and q ϕ ( z | x ) are parametrized and so can be optimized with respect to the encoder and decoder parameters.
Remark
In practice, p θ ( x | z ) is chosen depending on the modeling of the input data but is often taken as a simple distribution ( e.g multivariate Gaussian, Bernoulli ...).
Hence, the ELBO can also be seen as a two terms objective (Ghosh et al., 2020).
The first one is a reconstruction term given by p θ ( x | z ) while the second one is a regularizer corresponding to the KL divergence between the posterior and the prior. For instance, in the case of a multivariate Gaussian we have
[Equation]
R ELATED W ORK
A natural way to improve the generation from VAEs consists in trying to use more complex priors (Hoffman & Johnson, 2016) than the standard Gaussian distribution used in the initial version such that they better match the true distribution of the latent codes.
For instance, using a Mixture of
Gaussian (Nalisnick et al., 2016; Dilokthanakul et al., 2017) or a Variational Mixture of Posterior (VAMP) (Tomczak & Welling, 2018) as priors was proposed.
In the same vein, hierarchical latent variable models (Sønderby et al., 2016; Klushyn et al., 2019) or prior learning (Chen et al., 2016;
Aneja et al., 2020) have recently emerged and aimed at finding the best suited prior distribution for a given dataset.
Acceptance/rejection sampling method was also proposed to try to improve the expressiveness of the prior distribution (Bauer & Mnih, 2019).
Some recent works linking energybased models (EBM) and VAEs (Xiao et al., 2020) or modeling the prior as an EBM (Pang et al., 2020) have demonstrated promising results and are also worth citing .
On the ground that the latent space must adapt to the data as well, geometry-aware latent space modelings as hypershpere (Davidson et al., 2018), torus (Falorsi et al., 2018) or Poincar´e disk (Mathieu et al., 2019) or discrete latent representations (Razavi et al., 2020) were proposed.
Other recent contributions proposed to see the latent space as a Riemannian manifold where the Riemannian metric is given by the Jacobian of the generator function (Arvanitidis et al., 2018;
Chen et al., 2018; Shao et al., 2018). This metric was then used directly within the prior modeled by Brownian motions (Kalatzis et al., 2020). Others proposed to learn the metric directly from the data throughout training thanks to geometry-aware normalizing flows (Chadebec et al., 2020) or learn the latent structure of the data using transport operators (Connor et al., 2021).
While these geometry-based methods show interesting properties of the learned latent space they either require the computation of a time consuming model-dependent function, the Jacobian, or add further parameters to the model to learn the metric or transport operators adding some computational burden to the method.
Arguing that VAEs are essentially autoencoders regularized with a Gaussian noise, Ghosh et al.
(2020) proposed another interesting interpretation of the VAE framework and showed that other types of regularization may be of interest as well.
Since the generation process from these autoencoders is no longer relying on the prior distribution, the authors proposed to use ex-post density estimation by fitting simple distributions such a Gaussian mixture in the latent space.
While this paves the way for consideration of other ways to generate data, it mainly reduces the VAE framework to an autoencoder while we believe that it can also unveil interesting geometrical aspects.
Another widely discussed improvement of the model consists in trying to tweak the approximate posterior in the ELBO so that it better matches the true posterior using MCMC methods (Salimans et al., 2015) or normalizing flows (Rezende & Mohamed, 2015).
For instance, methods using
Hamiltonian equations in the flows to target the true posterior (Caterini et al., 2018) were proposed.
Finally, while discussing the potential link between PCA and autoencoders some intuitions arose on the impact of both the intrinsic structure of the variance of the data (Rakowski & Lippert, 2021) and the shape of covariance matrices in the posterior distributions (Rolinek et al., 2019) on disentanglement in the latent space.
We also believe that these covariance matrices indeed play a crucial role in the modeling of the latent space but in this paper, we instead propose to see their inverse as the value of a Riemannian metric evaluated at the embedding points µ i .
P ROPOSED M ETHOD
In this section, we argue that a vanilla VAE shows naturally a Riemannian structure of the latent space through the learned covariance matrices in the posterior distributions.
We then propose a new natural generation scheme guided by this estimated geometry and consisting in sampling from a uniform distribution deriving intrinsically from the learned Riemannian manifold.
4. A W ORD ON R IEMANNIAN G EOMETRY
First, we briefly recall some basic elements of Riemannian geometry needed in the rest of the paper.
A more detailed discussion on integration and probability densities on manifolds may be found in
Appendix A. A d -dimensional manifold M is a manifold which is locally homeomorphic to a ddimensional Euclidean space.
If the manifold M is further connected and differentiable it possesses a tangent space T z at any z ∈ M composed of the tangent vectors of the curves passing by z .
If M is equipped with a smooth inner product g = ⟨·|·⟩ z defined on its tangent space T z for any z ∈ M then
M it is called a Riemannian manifold and g is the associated Riemannian metric.
Since g is an inner product, a local representation of g at any z ∈ M is given by the positive definite matrix
G ( z ) .
The notion of length of curves γ : R → M traveling in M can be defined as follows
[Equation]
Curves minimizing L are geodesics and a Riemannian distance between z 1 , z 2 ∈ M can be defined
[Equation]
The manifold M is said to be geodesically complete if all geodesic curves can be extended to R .
In an Euclidean space, G reduces to the I d and the distance becomes the classic Euclidean one.
Remark
A simple extension of this Euclidean framework consists in assuming that the metric is given by a constant positive definite matrix Σ different from I d .
In such a case the induced
Riemannian distance is the well-known Mahalanobis distance which writes
[Equation]
4. T HE R IEMANNIAN G AUSSIAN D ISTRIBUTION
The notion of measure and so of probability distribution can be extended to geodesically complete
Riemannian manifolds as well (Pennec, 2006).
Given the Riemannian manifold M endowed with the Riemannian metric G and a chart z , an infinitesimal volume element may be defined on each tangent space T z of the manifold M as follows
[Equation]
with dz being the Lebesgue measure.
Hence, a Riemannian Gaussian distribution on M can be defined and consists in using the Riemannian distance defined in Eq.
4 instead of the Euclidean one
[Equation]
where d M z is the volume element defined by Eq. 5.
Hence, the multivariate normal distribution is only a specific case of the Riemannian distribution with σ = 1 , defined on the manifold M = R d endowed with the constant Riemannian metric G ( z ) =
Σ − 1 , ∀ z ∈ M .
4. G EOMETRICAL I NTERPRETATION OF THE VAE F RAMEWORK
Within the VAE framework, the variational distribution q ϕ ( z | x ) is voluntarily chosen as a simple multivariate Gaussian distribution defined on R d with d being the latent space dimension.
Hence, as explained in the previous section, given an input data point x i , the posterior q ϕ ( z | x ) =
N ( µ ( x i ) , Σ ( x i )) can also be seen as a Riemannian Gaussian distribution where the Riemannian distance is simply the distance with respect to the metric tensor Σ − 1 ( x i ) .
Hence, the VAE framework can be seen as follows.
As with an autoencoder, the VAE provides a code µ ( x i ) which is a lower dimensional representation of an input data point x i .
However, it also gives a tensor Σ − 1 ( x i ) depending on x i which can be seen as the value of a Riemannian metric G at µ ( x i ) i.e. G [Equation] µ
[Equation]
x [Equation] = Σ − 1 ( x i ) . This metric is crucial since it impacts the notion of distance in the latent space now seen as the Riemannian manifold M
=
( R d , G ) and so changes the directions that are favored in the sampling from the posterior distribution q ϕ ( z | x ) .
Then, a sample z is drawn from a standard ( i.e. σ = 1 in Eq. 6)
Riemannian Gaussian distribution and fed to the decoder.
As first approximation and since we only have access to a finite number of metric tensors Σ − 1 ( x i ) , the VAE model assumes that the metric is locally constant close to µ ( x i ) and so the Riemannian distance reduces to the Mahalanobis distance in the posterior distribution.
This simplified drastically the training process since now Riemannian distances have closed form and so are easily computable.
Interestingly, the VAE framework will impose through the ELBO expression given in Eq.
3, that z gives a sample x ∼ p θ ( x | z ) close to x i when decoded.
Since z has a probability density function imposing higher probability for samples having the smallest Riemannian distance to µ , the VAE imposes in a way that latent variables that are close in the latent space with respect to the metric G will also provide samples that are close in the data space X in terms of L2 distance as noticed in Remark.
Noteworthy is that the latter distance can be amended through the choice of the decoder p θ ( x | z ) .
This is a an interesting property since it allows the VAE to directly link the learned Riemannian distance in the latent space to the distance in the data space.
The regularization term in Eq. 3 ensures that the covariance matrices do not collapse to 0 d and constraints the latent codes to remain close to the origin easing optimization.
Finally, at the end of training, we have a lower dimensional representation of the training data given by the means of the posteriors µ ( x i ) and a family of metric tensors ( G i =
Σ − 1 ( x i ) )
corresponding to the value of a Riemannian metric defined locally on the latent space.
Inspired from Hauberg et al.
(2012), we propose to build a smooth continuous Riemannian metric defined on the entire latent space by performing the following interpolation:
[Equation]
where dist Σ − 1 ( x i ) ( z , µ i ) = ( z − µ i ) ⊤ Σ − 1 ( x i )( z − µ i ) is the Riemannian distance between z and µ i with respect to the locally constant metric G ( µ ( x i ))
=
Σ − 1 ( x i ) .
Since the sum in Eq.
is made on the total number of training samples N , the number of reference metric tensors can be decreased for huge datasets by selecting only k < N metric tensors 1 and increasing ρ to reduce memory usage. We provide an ablation study on the impact of λ , the number of centroids k and their choice along with a discussion on the choice for ρ in Appendix G.
Then, we have:
Proposition 1 The Riemannian manifold M =
( R d , G ) is geodesically complete.
Prop. 1 (proved in Appendix B) allows now to refer to probability densities on M .
Rigorously, the metric defined in Eq.
7 should have been used during the training process.
Nonetheless, this would have made the training longer and trickier since it would involve i) the computation of Riemannian distances that have no longer close form and so make the resolution of the optimization problem in Eq.
4 needed, ii) the sampling from Eq. 6 which is not trivial and iii) the computation of the regularization term.
Instead, by approximating the value of the metric during training by its value at µ i ( i.e. Σ − 1 i ( x i ) ), the VAE training remains unchanged, stable and computationally reasonable since Riemannian Gaussians become multivariate Gaussians in q ϕ ( z | x ) .
Noteworthy is the fact that, likewise (Ghosh et al., 2020), in our vision of the VAE, the prior distribution is only seen as a regularizer though the KL term and other latent space regularization schemes may have been also envisioned.
In the following, we keep the proposed vision and do not amend the training process.
4. G EOMETRY -A WARE S AMPLING
Assuming that the VAE has learned a latent representation of the data in a space seen as a Riemannian manifold, we propose to exploit this strong property to enhance the generation procedure.
A natural way to sample from such a latent space would consist in sampling from the uniform distribution intrinsically defined on the learned manifold.
Similar to the Gaussian distribution presented in Sec.
4.2, the notion of uniform distribution can indeed be extended to Riemannian manifolds.
Given a bounded set A ⊂ M , the uniform distribution writes (Pennec, 2006)
[Equation]
This density is taken with respect to d M z , the Riemannian measure but using Eq.
5 and a coordinate system z allows to obtain a pdf now defined with respect to the Lebesgue measure:
[Equation]
Since the Riemannian metric has a closed form expression given by Eq. 7, sampling from this distribution is quite easy and may be performed using the HMC sampler (Neal, 2005) for instance.
Now we are able to sample from the intrinsic uniform distribution which is a natural way of exploring the estimated manifold and the sampling is guided by the geometry of the latent space. A discussion on practical outcomes can be found in Appendix.
C. 4. I LLUSTRATION ON A T OY D ATASET
The usefulness of such sampling procedure may be easily appended in Figure 1 where a vanilla VAE was trained with a toy dataset composed of binary images of disks and rings of different size and thickness (example inspired by Chadebec et al.
On the left is presented the learned latent space along with the embedded training points given by the colored dots.
The log of the metric volume element is given in gray scale.
In this example, we clearly see a geometrical structure appearing since the disks and rings seem to wrap around each other.
Obviously, sampling using the prior (taken as a N (0 , I d ) ) in such a case is far from being optimal since the sampling will be performed regardless of the underlying distribution of the latent variables and so will create irrelevant samples.
To further illustrate this, we propose to interpolate between points in the latent space using different cost functions.
Dashed lines represent affine interpolations while the solid ones show interpolation aiming at minimizing the potential V ( z )
= ( (cid:112) det G ( z )) − 1 all along the curve i.e. solving the minimization problem
[Equation]
− 3 − 2 −   3 −−−
CirclesRings −    (a) −−−   3 −−−
Ours Afﬁne Circles Rings      (b) −−−   3 −−−
Ours Afﬁne Circles Rings
[Figure]
Below are presented the decoded samples all along the interpolation curves.
Thanks to those interpolations we can see that i) the latent space seems to really have a specific geometrical structure since decoding all along the interpolation curves obtained by solving Eq.
8 leads to qualitatively satisfying results, ii) certain locations of the latent space must be avoided since sampling there will produce irrelevant samples (see red frames and corresponding red dashes).
Using the proposed sampling scheme will allow to sample in the white areas and so ensure that the sampling remains close to the data i.e. where information is available and so does not produce irrelevant images when decoded.
E XPERIMENTS
In this section, we conduct a comparison with other VAE models using other regularization schemes, more complex priors, richer posteriors, ex-post density estimation or trying to take into account geometrical aspects including our method.
In the following and to ensure a fair comparison, all the models share the same auto-encoding neural network architectures described in Appendix E.
5. G ENERATION WITH B ENCHMARK D ATASETS
First, we compare the proposed sampling method to several VAE variants such as a Wasserstein Autoencoder (WAE) (Tolstikhin et al., 2018), Regularized Autoencoders (Ghosh et al., 2020) with either L2 decoder’s parameters regularization (RAE-L2), gradient penalty (RAE-GP), spectral normalization (RAE-SN) or simple L2 latent code regularization (RAE), a vamp-prior VAE (VAMP) (Tomczak & Welling, 2018), a Hamiltonian VAE (HVAE) (Caterini et al., 2018), a geometry-aware
VAE (RHVAE) (Chadebec et al., 2020) and an Autoencoder (AE).
We elect these models since they use different ways to generate the data using either the prior or ex-post density estimation.
For the latter, we use the approach of Ghosh et al.
and fit a 10-component mixture of Gaussian in the latent space after training.
The models are trained on MNIST (LeCun, 1998), SVHN (Netzer et al., 2011), CIFAR 10 (Krizhevsky et al., 2009) and CELEBA (Liu et al., 2015) and we keep the model achieving the best validation loss.
See Appendix E for the comprehensive experimental setup.
Figure 2 shows a qualitative comparison between the resulting generated samples for MNIST and CELEBA, the same plots are made available in Appendix D for SVHN and CIFAR 10.
Interest- [Figure] [Figure] ingly, using the non-prior based methods seems to produce qualitatively better samples (rows 7 to end).
Nonetheless, the resulting samples seem even sharper when the sampling takes into account geometrical aspect of the latent space as we propose (last row).
Additionally, even though the exact same model is used, we clearly see that using the proposed method represents a strong improvement of the generation process from a vanilla VAE when compared to the samples coming from a normal prior (second row).
This insists on the fact that even the simplest VAE model actually contains a lot of information in its latent space but the limited expressiveness of the prior impedes to access to it.
Hence, using more complex prior such as the VAMP may be a tempting idea.
However, one must keep in mind that the ELBO objective in Eq. 2 must remain tractable and so using more expressive priors may be impossible.
These observations are even more supported by Table 1 where we report the Frechet Inception Distance (FID) and the precision and recall (PRD) score against the test set to assess the sampling quality and diversity.
Again, fitting a mixture of Gaussian (GMM) in the latent space appears to be an interesting idea since it allows for a better expressiveness and latent space prospecting.
For instance, on MNIST the FID falls from 40.7 with the prior to 13.1 when using a GMM.
Nonetheless, with the proposed method we are able to make it even smaller (8.5) and PRD scores higher without changing the model and performing post processing.
This can also be observed on the 3 other datasets.
Impressively, in almost all cases, the proposed generation method
In the first section are presented results using the prior distribution while in the second one, we use ex-post density estimation by fitting a 10-component mixture of Gaussian in the latent space.
[Table]
can either compete or outperform peers both in terms of FID and PRD scores.
Finally, we check if the proposed method does not overfit the training data and is able to produce diverse samples by showing the nearest neighbor in the train set and the nearest image in all the reconstructions of the train images to a generated image in Figure 3.
This experiment shows that the generated samples are not only resampled train images and that the sampling prospects quite well the manifold. To support even more this claim we provide in Appendix G an analysis in a case where only two centroids are selected in the metric.
This also shows that the generated samples are not only an interpolation between the k selected centroids since some generated images contain attributes that are not present in the images of the decoded centroids.
The outcome of such an experiment is that using post training latent space processing such as ex-post density estimation or adding some geometrical consideration to the model allows to strongly improve the sampling without adding more complexity to the model. Generating 1000 samples on CELEBA takes approx. 5.5 min for our method vs. 4 min for a 10-component GMM and 0.6s for prior based methods on a single GPU V100-16GB. [Figure]
5. I NVESTIGATING G ENERATION R OBUSTNESS IN L OW D ATA R EGIME
We perform a comparison using the same models and datasets as before but we decide to progressively decrease the size of the training set to see the robustness of the different sampling methods according to the number of samples.
This experiment is rarely performed in most generative models related papers even though it is well known that such a context may be very challenging for these models.
Nonetheless, it appears to us very important since in day-to-day applications collecting such large databases may reveal costly if not impossible (think of medicine for instance).
Hence, we consider MNIST, CIFAR10 and SVHN and use either the full dataset size, 10k, 5k or 1k training samples.
For each experiment, the best retained model is again the one achieving the best ELBO [Table] on the validation set the size of which is set as 20% of the train size.
See Appendix E for further details about experiments set-up.
Then, we report the evolution of the FID against the test set in Figure 4.
Results obtained on SVHN are presented in Appendix F. Again, the proposed sampling method appears quite robust to the dataset size since it outperforms the other models’ FID even when the number of training samples is smaller.
This is made possible thanks to the proposed metric that allows to avoid regions of the latent space having poor information.
Finally, our study shows that although using more complex generation procedures such as ex-post density estimation seems to still enhance the generation capability of the model when the number of training samples remains quite high ( ≥ 5k), this gain seems to worsen when the dataset size reduces as illustrated on CIFAR.
5. G ENERATION WITH C OMPLEX D ATA
Finally, we also propose to stress the proposed generation procedure in a day-to-day scenario where the limited data regime is more than common.
To stress the model in such condition, we consider the publicly available OASIS database composed of 416 MRI of patients, 100 of whom were diagnosed with Alzheimer disease (AD).
Since both FID and PRD scores are not relevant and reliable in such low data regime due to the lack of a large test set, we propose to assess quantitatively the generation quality with a data augmentation task.
Hence, we split the dataset into a train set (70%), a validation set (10%) and a test set (20%).
Each model is trained on each label of the train set and used to generate 2k new samples per class.
Then a simple CNN classifier is trained on i) the original train set and ii) the 4k generated samples from the generative models and tested on the test set.
Tableshows the mean balanced accuracy and F1 scores across 20 runs.
These metrics provide a good way to assess i) if the generative model can generate data that are not too far from the test set and add information to the data that is relevant for classification and ii) allows to quantify the amount of overfitting.
The proposed method is the only one to be able to outperform the original (unbalanced) data both in terms of balanced accuracy and F1 scores for both labels meaning that generated samples are relevant to the classifier.
This is also the sign of a good generalization power since the classifier achieves classification results that outperform the one observed on the original data.
C ONCLUSION
In this paper, we provided a geometric understanding of the latent space learned by a VAE and showed that it can actually be seen as a Riemannian manifold.
Then, we proposed a new natural generation process consisting in sampling from the intrinsic uniform distribution defined on this learned manifold.
It showed to be competitive with more advanced versions of the VAEs using either more complex priors, ex-post density estimation, normalizing flows or other regularization schemes.
Interestingly, the proposed method revealed good robustness properties in complex settings such as high dimensional data or low sample sizes.
Future work would consist in trying to use this method to perform data augmentation in those challenging contexts and compare its reliability for such a task with state of the art augmentation methods. R EPRODUCIBILITY S TATEMENT In order to make the method and the proposed experiments reproducible, we provide in Appendix
E the complete experimental set-up and in Appendix C pseudo-code algorithms detailing the implementation from a practical point of view.
We also provide an implementation in the supplementary material.
A F URTHER E LEMENTS ON R IEMANNIAN G EOMETRY
In the field of differential geometry, a Riemannian manifold M can be defined as a connected and differentiable manifold endowed with a Riemannian metric g .
The metric g is a smooth inner product g : p → ⟨·|·⟩ p defined on each tangent space T p M of the manifold with p ∈ M .
A chart (or coordinate system) ( U, x ) is a homeomorphism mapping an open set U of the manifold to an open set V of an Euclidean space.
The manifold M is further called a d − dimensional manifold if for each chart V ⊂ R d .
This means that there exists a neighborhood U of each point
p ∈ M such that U is homeomorphic to R d .
Given p ∈ U , a chart ϕ : ( x 1 , . . .
, x d ) induces a basis (cid:16) ∂∂x 1 , . .
, ∂∂x d (cid:17) p on the tangent space T p M .
Hence, the metric of a Riemannian manifold can be locally represented in the chart ϕ as a positive definite matrix G ( p ) =
( g i,j ) p, 0 ≤ i,j ≤ d = ( ⟨ ∂∂x i | ∂∂x j ⟩ p ) 0 ≤ i,j ≤ d for each point p of the manifold.
That is for v, w ∈ T p M and p ∈ M , the inner product writes ⟨ u | w ⟩ p =
u ⊤ G ( p ) w .
Two ways of apprehending manifolds exist.
The first one is the extrinsic view and it assumes that the manifold is embedded within a higher dimensional Euclidean space.
A simple example is the 2-dimensional sphere S 2 seen as a subspace of R 3 .
The second one which is adopted in this paper is the intrinsic view.
In the intrinsic view the manifold is studied using its underlying structure and so the length of a curve γ : R → M traveling in the manifold cannot be interpreted using the
Euclidean distance but requires to use the metric defined onto the manifold itself.
Let z 1 , z 2 ∈ M be two points of the manifold, and γ be a curve traveling in M parametrized by t ∈ [0 , 1] such that γ (0) =
z 1 and γ (1) =
z 2 .
Then, the length of γ is given by
[Equation]
Curves γ that are minimizer(s) of this criteria are called geodesic curves.
A distance dist on the manifold M can then be derived and writes:
[Equation]
The manifold M is said to be geodesically complete if all geodesic curves can be extended to R .
For any p ∈ M , the exponential map at p maps a vector v of the tangent space T p M to a point of the manifold ˜ p ∈ M such that the geodesic starting at p with initial velocity v reached ˜ p at time 1.
[Equation]
where γ ( p,v ) (1) means γ (0)
=
p and ˙ γ (0) = v .
Saying that the manifold M is geodesically complete means that the exponential maps is defined on the entire tangent space T p M for each element p ∈ M .
In Pennec (2006), the author discusses the statistical framework that can be developed on geodesically complete manifolds using an intrinsic point of view.
In particular, given a positively oriented
Riemannian manifold M and a chart ϕ = ( x 1 , · · · , x d ) , a volume form dVol g can be defined as the d -form:
[Equation]
This represents an infinitesimal volume element on each tangent space and so a measure on the manifold M
[Equation]
It follows that we are able to integrate functions f : M ⊃ U → R on a given chart ( U, ϕ ) .
[Equation]
This notion can then be extended to the whole manifold M using partition of unity.
In particular, such a property allows us to define probability distributions whose density is defined with respect to the measure on the manifold.
We recall such definition from Pennec (2006) below
Definition 1 Let B ( M ) be the Borel σ -algebra of M .
The random point p has a probability density function ρ p if:
[Equation]
Finally, given a chart ϕ = ( z 1 , · · · , z n ) defined on the whole manifold M and a random point p on
M , the point z = ϕ ( p ) is a random point whose density ρ ′
z may be written with respect to the
Lebesgue measure as such (Pennec, 2006):
[Equation]
B P ROOF OF P ROP .
We adapt the proof in Louis (2019) and Chadebec et al.
(2021) to our specific metric.
We will show that given the manifold M = R d and the Riemannian metric whose local representation is given by
Eq. 7, any geodesic curve γ :] a, b
[ → M is actually extensible to R .
Let us consider a geodesic curve γ such that γ cannot be extended to R .
There exists I =] a, b [ such that I is the maximum definition domain of γ .
We will show that with such an assumption we will end up with a contradiction.
We recall the shape of the Riemannian metric:
[Equation]
Since Σ i are positive definite matrices we have z ⊤ Σ i z > 0 , ∀ z ∈ M − { 0 } .
We further have ω
i ( z ) > 0 , ∀ z ∈ M since the manifold is geodesically complete .
Let t 0 ∈ ] a, b [ we therefore have for any t ∈ ] a, b [ .
[Equation]
where the last equality comes for the constant speed of geodesic curves (Carmo, 1992).
Hence we have:
[Equation]
This means that for any t ∈ ] a, b [ the geodesic curve γ remains within a compact set.
We show now that the curve can actually be extended.
Let us define the sequence t n −−−−→ n →∞ b .
Since the geodesic curves have a constant speed the set I = { ( t n , ˙ γ ( t n ) } n ∈ N is compact.
Moreover, using CauchyLipchitz theorem, we can find ε > 0 such that for any n ∈ N , the geodesic γ can be extended to ] t n − ε, t n + ε [ .
Since, t n can be as close as b as desired we can assure that the curve definition domain can be extended to ] a, b + ε 2 [ . C T HE G ENERATION P ROCESS A LGORITHM - I MPLEMENTATION D ETAILS
In this appendix, we provide pseudo-code algorithms explaining how to build the metric from a trained VAE and how to use the proposed sampling process.
Noteworthy is the fact that we do not amend the training process of the vanilla VAE which remains pretty simple and stable.
C. B UILDING THE M ETRIC
In this section, we explain how to build the proposed Riemannian metric. For the sake of clarity, we recall the expression of the metric in Eq. 7 below [Equation]
where
[Equation]
Algorithm
Input: A trained VAE model m , the training dataset X , λ for x i ∈
X do µ i , Σ i
= m ( x i )
▷ Retrieve training embeddings and covariance matrices end for
Select k centroids c i in the µ i
▷
e.g. with k -medoids
Get corresponding covariance matrices
Σ
i
[Equation]
▷ Set ρ to the max distance between two closest neighbors
Build the metric using Eq.
[Equation]
Return G ▷ Return G as a function
As is standard in VAE implementations, we assume that the covariance matrices Σ i given by the
VAE are diagonal and that the encoder outputs a mean vector and the log of the diagonal coefficients.
In the implementation, the exponential is then applied to recover the Σ i so that no singular matrix arises.
C. S AMPLING P ROCESS
Further to the description performed in the paper, we provide here a detailed algorithm stating the main steps of the generation process.
C.2. T HE HMC S AMPLER
In the sampling process we propose to rely on the Hamiltonian Monte Carlo sampler to sample from the Riemanian uniform distribution.
In a nutshell, the HMC sampler aims at sampling from a target distribution p target ( z ) with z ∈ R d using Hamiltonian dynamics.
The main idea behind such a sampler is to introduce an auxiliary random variable v ∼ N (0 , I d ) independent from z and mimic the behavior of a particle having z (resp.
v ) as location (resp.
velocity).
The Hamiltonian of the particle then writes
[Equation]
where U ( z ) is the potential energy of such a particle and K ( v ) is its kinetic energy both given by
[Equation]
The following Hamilton’s equations govern the evolution in time of the particle.
[Equation]
In order to integrate these equations, recourse to the leapfrog integrator is needed and consists in applying n lf times the following equations.
[Equation]
where ε lf is called the leapfrog step size.
This algorithm produces a proposal ( (cid:101) z , (cid:101) v ) that is accepted with probability α where
[Equation]
This procedure is then repeated to create an ergodic Markov chain ( z n ) converging to the distribution p target (Neal & others, 2011; Duane et al., 1987; Liu, 2008; Girolami & Calderhead, 2011).
C. T HE P ROPOSED A LGORITHM
In our setting the target density is given by the density of the Riemannian uniform distribution which writes with respect to Lebesgue measure as follows
[Equation]
The log density follows
[Equation]
In such a case, the Hamiltonian writes
[Equation]
and Hamilton’s equations become
[Equation]
Since the covariance matrices are supposed to be diagonal as is standard in VAE implementations, the computation of the inverse metric is straightforward.
Moreover, since G ( z ) is smooth and has a closed form, it can be differentiated with respect to z pretty easily.
Now, the leapfrog integrator given in Eq.
12 can be used and the acceptance ratio α is easy to compute.
Noteworthy is the fact that the normalizing constant C is never needed since it vanishes in the gradient computation and simplifies in the acceptance ratio α .
We provide a pseudo-code of the proposed sampling procedure in Alg. 2.
A typical choice in the sampler’s hyper-parameters used in the paper is N = 100 , n lf =and ε lf = 0 .
The initialization of the chain can be done either randomly or on points that belong to the manifold (i.e. the centroids c i or µ i ).
Input: The function
{+Initialization: z ▷ Initialize the chain for i = 
+}
→ N do v ∼ N (0 , I d ) ▷ Draw a velocity
H 0 ← H ( z , v ) ▷ Compute the starting Hamiltonian z 0 ← z for k =← n lf do ¯ v ← v − ε lf 2 · ∇ z H ( z , v ) (cid:101)
z ← z + ε lf · ¯ v ▷ Leapfrog step Eq.(cid:101) v ← ¯ v − ε lf 2 · ∇ z H ( (cid:101)
z , ¯ v ) v ← (cid:101) v z ← (cid:101) z end for
H ← H ( (cid:101) z , (cid:101) v )
▷ Compute the ending Hamiltonian
Accept (cid:101) z with probability α = min (cid:16) 1 , exp( H 0 − H ) (cid:17) if Accepted then z ← (cid:101) z else z ← z 0 end if end for Return z D O THER G ENERATION D. S OME F URTHER S AMPLES ON CELEBA AND MNIST
In this section, we provide some further generated samples using the proposed method.
Figure 5 and
Figure 6 again support the fact that the method is able to generate sharp and diverse samples.
We also add the other variants of the RAE model in Figure 7.
[Figure]
In this appendix [Figure] we gather the resulting samplings from the different considered models for SVHN and CIFAR 10.
[Figure] [Figure]
E E XPERIMENTAL S ET - UP
The RAEs, VAEs and AEs are trained for 100 epochs for SVHN, MNIST 2 and Celeba and 200 on
CIFAR10.
Each time we use the official train and test split of the data.
For MNIST and SVHN, 10k samples out of the train set are reserved for validation and 40k for CIFAR10.
As to Celeba, we use the official validation set for validation.
The model that is kept at the end of training is the one achieving the best validation loss.
All the models are trained with a batch size of 100 and starting learning rate of 1 e − 3 (but CIFAR where the learning rate is set to 5 e − 4 ) with an Adam optimizer (Kingma & Ba, 2014).
We also use a scheduler decreasing the learning rate by half if the validation loss stops increasing for 5 epochs.
For the experiments on the sensitivity to the training set size, we keep the same set-up.
For each dataset we ensure that the validation set is 1 / 5 th the size of the train set but for CIFAR where we select the best model on the train set.
The neural networks architectures can be found in Table 3 and are inspired by Ghosh et al.
The metrics (FID and PRD scores) are computed with 10000 samples against the test set (for Celeba we selected only the 10000 first samples of the official test set).
The factor ρ is set to ρ = max i min j ̸ = i ∥
c i − c j ∥ 2 to ensure some smoothness of the manifold.
For models coming from peers, we use the parameters provided by the authors when available.
For the data augmentation task, the generative models are trained on each class for 1000 epochs with a batch size of 100 and a starting learning rate of 1 e − 4 .
Again a scheduler is used and the learning rate is cut by half if the loss does not improve for 20 epochs.
All the models have the autoencoding architecture described in Table 3.
As to the classifier, it is trained with a batch size of 200 forepochs with a starting learning rate of 1 e − 4 and Adam optimizer.
A scheduler reducing the learning rate by half every 5 epochs if the validation loss does not improve is again used.
The best kept model is the on achieving the best balanced accuracy on the validation set.
Its neural network architecture may be found in Table 4.
MRIs are only pre-processed such that the maximum value of a voxel isand the minimum 0 for each data point
[Table] [Table] [Table]
[Table] [Table]
F D ATASET S IZE S ENSIBILITY ON SVHN
In Figure
[Figure]
we show the same plot for SVHN as in Sec. 5.2.
Again the proposed method appears to be part of the most robust generation procedures to dataset size changes.
[Figure]
G A BLATION S TUDY G. I NFLUENCE OF THE N UMBER OF C ENTROIDS IN THE M ETRIC
In order to assess the influence of the number of centroids and their choice in the metric in Eq.
7, we show in Figure 11 the evolution of the FID according to the number of centroids in the metric (left) and the variation of FID according to the choice in the centroids.
As expected, choosing a small number of centroids will increase the value of the FID since it reduces the variability of the generated samples that will remain close to the centroids.
Nonetheless, as soon as the number of centroids is higher than 1000 the FID score is either competitive or better than peers and continues decreasing as the number of centroids increases.
[Figure]
To assess the variability of the generated samples, we propose to analyze some generated samples when only 2 centroids are considered.
In Figure 12, we display on the left the decoded centroids along with the closest image to these decoded centroids in the train set.
On the right are presented some generated samples.
We place these samples in the top row if they are closer to the first decoded centroid and in the bottom row otherwise.
Interestingly, even with a small number of centroids the proposed sampling scheme is able to access to a relatively good diversity of samples.
These samples are not simply resampled train images or a simple interpolation between selected centroids as some of the generated samples have attributes such as glasses that are not present in the images of the decoded centroids.
[Figure]
G. I NFLUENCE OF λ IN THE M ETRIC
In this section, we also assess the influence of the regularization factor λ in Eq.
7 on the resulting sampling.
To do so, we generate 10k samples using the proposed method on both MNIST and
Celeba datasets for values of λ ∈ [1 e − 6 , 1 e − 4 , 1 e − 2 , 1 e − 1 , 1] .
Then, we compute the FID against the test set.
Each time, we consider k = 1000 centroids in the metric.
As shown in Figure 13, the influence of λ remains limited.
In practice, λ is mainly here to avoid pathological cases such as the metric collapsing to 0 far from the centroids.
In the implementation, a typical choice for λ is 1 e − 2 .
[Figure]
G. T HE C HOICE OF ρ
In the experiments presented, the smoothing factor ρ in Eq.
7 is set to the value of the maximum distance between two closest centroids ρ = max i min j ̸
= i ∥
c j − c i ∥ 2 .
This choice is motivated by the fact that we wanted to build a smooth metric and so ensure some smoothness of the manifold while trying to interpolate faithfully between the metric tensors G i =
Σ − 1 i .
In particular, a small value of ρ would have allowed disconnected regions and the sampling may have not prospected well the learned manifold and would have only become a resampling of the centroids.
On the other hand, setting a high value for ρ would have biased the interpolation and the value of the metric at a µ i .
As a result, G ( µ i ) might have been very different from the one observed Σ − 1 i since the other µ j would have had a strong influence on its value.
The proposed value for ρ appeared to work well in practice.
H O THER C LASSIFICATION M ETRICS
In Table 5 are presented some further classification results for each considered model while generated samples using each generation procedure are made available in Figure 14.
On OASIS database the proposed method appears to produce visually the sharpest samples.
This better generation performance is also supported by the classification metrics provided in Table 2 and Table
[Table] [Table]
[Figure]