VAE_IAF

This module is the implementation of a Variational Autoencoder with Inverse Autoregressive Flow to enhance the expressiveness of the posterior distribution. (https://arxiv.org/abs/1606.04934).

Available samplers

NormalSampler

Samples from a Standard normal distribution in the Autoencoder’s latent space.

GaussianMixtureSampler

Fits a Gaussian Mixture in the Autoencoder’s latent space.

TwoStageVAESampler

Fits a second VAE in the Autoencoder’s latent space.

MAFSampler

Fits a Masked Autoregressive Flow in the Autoencoder’s latent space.

IAFSampler

Fits an Inverse Autoregressive Flow in the Autoencoder’s latent space.

class pythae.models.VAE_IAF_Config(input_dim=None, latent_dim=10, uses_default_encoder=True, uses_default_decoder=True, reconstruction_loss='mse', n_made_blocks=2, n_hidden_in_made=3, hidden_size=128)[source]

VAE with Inverse Autoregressive Normalizing Flow config class.

Parameters
  • input_dim (int) – The input_data dimension

  • latent_dim (int) – The latent space dimension. Default: None.

  • reconstruction_loss (str) – The reconstruction loss to use [‘bce’, ‘mse’]. Default: ‘mse’.

  • n_made_blocks (int) – The number of MADE models to consider in the IAF used in the VAE. Default: 2.

  • n_hidden_in_made (int) – The number of hidden layers in the MADE models composing the IAF in the VAE. Default: 3.

  • hidden_size (list) – The number of unit in each hidder layerin the MADE model. The same number of units is used across the n_hidden_in_made and n_made_blocks. Default: 128.

class pythae.models.VAE_IAF(model_config, encoder=None, decoder=None)[source]

Variational Auto Encoder with Inverse Autoregressive Flows (IAF).

Parameters
  • model_config (VAE_IAF_Config) – The Variational Autoencoder configuration seting 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 VAE NF model

Parameters

inputs (BaseDataset) – The training dataset with labels

Returns

An instance of ModelOutput containing all the relevant parameters

Return type

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