Hamiltonian VAE¶
This module is the implementation of the Hamiltonian VAE proposed in (https://arxiv.org/abs/1805.11328). This model combines Hamiltonian Monte Carlo smapling and normalizing flows together to improve the true posterior estimate within the VAE framework.
Available samplers¶
Samples from a Standard normal distribution in the Autoencoder’s latent space. |
|
Fits a Gaussian Mixture in the Autoencoder’s latent space. |
|
Fits a second VAE in the Autoencoder’s latent space. |
|
Fits a Masked Autoregressive Flow in the Autoencoder’s latent space. |
|
Fits an Inverse Autoregressive Flow in the Autoencoder’s latent space. |
- class pythae.models.HVAEConfig(input_dim=None, latent_dim=10, uses_default_encoder=True, uses_default_decoder=True, reconstruction_loss='mse', n_lf=3, eps_lf=0.001, beta_zero=0.3, learn_eps_lf=False, learn_beta_zero=False)[source]¶
Hamiltonian Variational Autoencoder config class.
- Parameters
latent_dim (int) – The latent dimension used for the latent space. Default: 10
n_lf (int) – The number of leapfrog steps to used in the integrator: Default: 3
eps_lf (int) – The leapfrog stepsize. Default: 1e-3
beta_zero (int) – The tempering factor in the Riemannian Hamiltonian Monte Carlo Sampler. Default: 0.3
learn_eps_lf (bool) – Whether the leapfrog stepsize should be learned. Default: False
learn_beta_zero (bool) – Whether the temperature betazero should be learned. Default: False.
- class pythae.models.HVAE(model_config, encoder=None, decoder=None)[source]¶
Hamiltonian VAE.
- Parameters
model_config (HVAEConfig) – A model configuration setting the main parameters of the model.
encoder (BaseEncoder) – An instance of BaseEncoder (inheriting from torch.nn.Module which plays the role of encoder. This argument allows you to use your own neural networks architectures if desired. If None is provided, a simple Multi Layer Preception (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
decoder (BaseDecoder) – An instance of BaseDecoder (inheriting from torch.nn.Module which plays the role of decoder. This argument allows you to use your own neural networks architectures if desired. If None is provided, a simple Multi Layer Preception (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
Note
For high dimensional data we advice you to provide you own network architectures. With the provided MLP you may end up with a
MemoryError.- forward(inputs, **kwargs)[source]¶
The input data is first encoded. The reparametrization is used to produce a sample \(z_0\) from the approximate posterior \(q_{\phi}(z|x)\). Then Hamiltonian equations are solved using the leapfrog integrator.
- Parameters
inputs (BaseDataset) – The training data with labels
- Returns
An instance of ModelOutput containing all the relevant parameters
- Return type
output (ModelOutput)
- get_nll(data, n_samples=1, batch_size=100)[source]¶
Function computed the estimate negative log-likelihood of the model. It uses importance sampling method with the approximate posterior distribution. This may take a while.
- Parameters
data (torch.Tensor) – The input data from which the log-likelihood should be estimated. Data must be of shape [Batch x n_channels x …]
n_samples (int) – The number of importance samples to use for estimation
batch_size (int) – The batchsize to use to avoid memory issues