MAFSampler

Sampler fitting a Masked Autoregressive Flow (MAF) in the Autoencoder’s latent space.

Available models:

AE

Vanilla Autoencoder model.

VAE

Vanilla Variational Autoencoder model.

BetaVAE

\(\beta\)-VAE model.

VAE_LinNF

Variational Auto Encoder with linear Normalizing Flows model.

VAE_IAF

Variational Auto Encoder with Inverse Autoregressive Flows (IAF).

DisentangledBetaVAE

Disentangled \(\beta\)-VAE model.

FactorVAE

FactorVAE model.

BetaTCVAE

\(\beta\)-TCVAE model.

IWAE

Importance Weighted Autoencoder model.

MSSSIM_VAE

VAE using perseptual similarity metrics model.

WAE_MMD

Wasserstein Autoencoder model.

INFOVAE_MMD

Info Variational Autoencoder model.

VAMP

Variational Mixture of Posteriors (VAMP) VAE model

SVAE

\(\mathcal{S}\)-VAE model.

Adversarial_AE

Adversarial Autoencoder model.

VAEGAN

Variational Autoencoder using Adversarial reconstruction loss model.

VQVAE

Vector Quantized-VAE model.

HVAE

Hamiltonian VAE.

RAE_GP

Regularized Autoencoder with gradient penalty model.

RAE_L2

Regularized Autoencoder with L2 decoder params regularization model.

RHVAE

Riemannian Hamiltonian VAE model.

class pythae.samplers.MAFSamplerConfig(n_made_blocks=2, n_hidden_in_made=3, hidden_size=128, include_batch_norm=False)[source]

This is the MAF sampler model configuration instance.

Parameters
  • n_made_blocks (int) – The number of MADE model to consider in the MAF. Default: 2.

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

  • hidden_size (list) – The number of unit in each hidder layer. The same number of units is used across the n_hidden_in_made and n_made_blocks

  • include_batch_norm (bool) – Whether to include batch normalization after each MADE layers. Default: False.

class pythae.samplers.MAFSampler(model, sampler_config=None)[source]

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

Parameters
  • model (BaseAE) – The AE model to sample from

  • sampler_config (MAFSamplerConfig) – A MAFSamplerConfig instance containing the main parameters of the sampler. If None, a pre-defined configuration is used. Default: None

Note

The method fit must be called to fit the sampler before sampling.

fit(train_data, eval_data=None, training_config=None, batch_size=64)[source]

Method to fit the sampler from the training data

Parameters
  • train_data (Union[torch.Tensor, np.ndarray, Dataset]) – The train data needed to retrieve the training embeddings and fit the flows in the latent space.

  • eval_data (Union[torch.Tensor, np.ndarray, Dataset]) – The train data needed to retrieve the evaluation embeddings and fit the flows in the latent space.

  • training_config (BaseTrainerConfig) – the training config to use to fit the flow.

  • batch_size (int) – The batch size to use to retrieve the embeddings. Default: 64.

sample(num_samples=1, batch_size=500, output_dir=None, return_gen=True, save_sampler_config=False)[source]

Main sampling function of the sampler.

Parameters
  • num_samples (int) – The number of samples to generate

  • batch_size (int) – The batch size to use during sampling

  • output_dir (str) – The directory where the images will be saved. If does not exist the folder is created. If None: the images are not saved. Defaults: None.

  • return_gen (bool) – Whether the sampler should directly return a tensor of generated data. Default: True.

  • save_sampler_config (bool) – Whether to save the sampler config. It is saved in output_dir

Returns

The generated images

Return type

Tensor