Variational Autoencoders are generative latent-variable models that are popularly used for unsupervised learning and are aimed at maximizing the log-likelihood of the data, that is, maximizing
-
$z \sim \mathcal{N}(0, I)$ -
$x | z \sim \mathcal{N}(\mu_\theta(z), \Sigma_\theta(z))$
Given
One way of optimizing for log-likelihood is to use the variational distribution
This is the objective that we use for optimizing VAEs, where different flavours of VAE can be obtained by changing either the approximate posterior
In this repo we have implemented a simple version of a VAE, where
The likelihood
- Sampling: Provide the methodology of computing a reparamterized sample from the given distribution.
- KL Divergence: Compute and return the KL divergence of the distribution with the standard normal, that is,
$\mathbb{KL}[\mathcal{N}(\mu, \Sigma) || \mathcal{N}(0, I)]$ where$\Sigma$ is a diagonal covariance matrix. - Negative Log Likelihood: Given some data
$x$ , returns the log likelihood under the current gaussian, that is,$\log \mathcal{N}(x | \mu, \Sigma)$ - Mode: Returns the mode of the distribution
The Variational Autoencoder (VAE) model consists of an encoder network that parameterizes the distribution
- Encode: The function that takes as input a batched data sample, and returns the approximate posterior distribution
$q_\phi$ - Decode: The function that takes as input a batched sample from the latent space, and returns the mode of the distribution
$p_\theta$ - Sample: Generates a novel sample by sampling from the prior and then using the mode of the distribution
$p_\theta$ - Forward: The main function for training. Given a data sample x, encode it using the encode function, and then obtain a reparameterized sample from it, and finally decode it. Return the mode from the decoded distribution
$p_\theta$ , as well as the conditional likelihood and KL terms of the loss. - Log Likelihood: The main function for testing that approximates the log-likelihood of the given data. It is computed using importance sampling as
$\log \frac{1}{K} \sum\limits_{k=1}^K \frac{p_\theta(x, z_k)}{q_\phi(z_k|x)}$ where$z_k \sim q_\phi(z | x)$ .