GaussianMixtureSampler

Implementation of a Gaussian mixture sampler.

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.GaussianMixtureSamplerConfig(n_components=10)[source]

Gaussian mixture sampler config class.

Parameters

n_components (int) – The number of Gaussians in the mixture

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

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

Parameters
  • model (BaseAE) – The vae model to sample from.

  • sampler_config (BaseSamplerConfig) – An instance of BaseSamplerConfig in which any sampler’s parameters is made available. If None a default configuration is used. Default: None.

Note

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

fit(train_data, batch_size=64, **kwargs)[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 mixture in the latent space.

  • 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