gt4sd.frameworks.granular.ml.models.vae_mlp.core module

VaeMlp implementation.

Summary

Classes:

VaeMlp

VaeMlp - variational encoder using MLP with Gaussian prior and approximate posterior.

Reference

class VaeMlp(name, position, data, input_size_enc=256, hidden_size_enc=256, n_layers_enc=2, activation_enc='linear', dropout_enc=0.0, hidden_size_dec=256, n_layers_dec=2, activation_dec='linear', dropout_dec=0.0, output_size_dec=256, latent_size=196, loss_function='mse', kl_low=0.0, kl_high=0.1, kl_n_epochs=100, kl_start_epoch=0, **kwargs)[source]

Bases: GranularEncoderDecoderModel

VaeMlp - variational encoder using MLP with Gaussian prior and approximate posterior.

__init__(name, position, data, input_size_enc=256, hidden_size_enc=256, n_layers_enc=2, activation_enc='linear', dropout_enc=0.0, hidden_size_dec=256, n_layers_dec=2, activation_dec='linear', dropout_dec=0.0, output_size_dec=256, latent_size=196, loss_function='mse', kl_low=0.0, kl_high=0.1, kl_n_epochs=100, kl_start_epoch=0, **kwargs)[source]

Construct VaeMlp.

Parameters
  • name (str) – model name.

  • position (int) – position of the model.

  • data (Dict[str, str]) – data name mappings.

  • input_size_enc (int) – encoder input size. Defaults to 256.

  • hidden_size_enc (int) – encoder hidden size. Defaults to 256.

  • n_layers_enc (int) – number of layers for the encoder. Defaults to 2.

  • activation_enc (str) – activation function for the encoder. Defaults to “linear”.

  • dropout_enc (float) – encoder dropout rate. Defaults to 0.0.

  • hidden_size_dec (int) – decoder hidden size. Defaults to 256.

  • n_layers_dec (int) – number of layers for the decoder. Defaults to 2.

  • activation_dec (str) – activation function for the decoder. Defaults to “linear”.

  • dropout_dec (float) – decoder dropout rate. Defaults to 0.0.

  • output_size_dec (int) – decoder output size. Defaults to 256.

  • latent_size (int) – size of the latent space. Defaults to 196.

  • loss_function (str) – loss function. Defaults to “mse”.

  • kl_low (float) – low KL weight.

  • kl_high (float) – high KL weight.

  • kl_n_epochs (int) – KL number of epochs.

  • kl_start_epoch (int) – KL starting epoch.

Raises

ValueError – in case the provided loss function is not supported.

decode(z, *args, **kwargs)[source]

Decode a latent space point.

Parameters

z (Any) – latent point.

Return type

Any

Returns

decoded sample.

_sampling_step(x, *args, **kwargs)[source]

Run a sampling step in the model.

Parameters

x (Any) – model input.

Return type

Any

Returns

model sampling step output.

encode(x, *args, **kwargs)[source]

Encode a sample.

Parameters

x (Any) – input sample.

Return type

Any

Returns

latent encoding.

_run_step(x, *args, **kwargs)[source]

Run a step in the model.

Parameters

x (Any) – model input.

Return type

Any

Returns

model step output.

step(input_data, target_data, device='cpu', current_epoch=0, *args, **kwargs)[source]

Training step for the model.

Parameters
  • input_data (Any) – input for the step.

  • target_data (Any) – target for the step.

  • device (str) – string representing the device to use. Defaults to “cpu”.

  • current_epoch (int) – current epoch. Defaults to 0.

Return type

Tuple[Any, Any, Any]

Returns

a tuple containing the step output, the loss and the logs for the module.

__annotations__ = {}
__doc__ = 'VaeMlp - variational encoder using MLP with Gaussian prior and approximate posterior.'
__module__ = 'gt4sd.frameworks.granular.ml.models.vae_mlp.core'
val_step(input_data, target_data, device='cpu', current_epoch=0, *args, **kwargs)[source]

Validation step for the model.

Parameters
  • input_data (Any) – input for the step.

  • target_data (Any) – target for the step.

  • device (str) – string representing the device to use. Defaults to “cpu”.

  • current_epoch (int) – current epoch. Defaults to 0.

Return type

Any

Returns

a tuple containing the step output, the loss and the logs for the module.

static add_model_specific_args(parent_parser, name, *args, **kwargs)[source]

Adding to a parser model specific arguments.

Parameters
  • parent_parser (ArgumentParser) – patent parser.

  • name (str) – model name.

Return type

ArgumentParser

Returns

updated parser.