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

MLP autoencoder implementation.

Summary

Classes:

MlpAutoEncoder

MlpAutoencoder - Multi Layer Perceptron autoencoder.

Reference

class MlpAutoEncoder(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', **kwargs)[source]

Bases: GranularEncoderDecoderModel

MlpAutoencoder - Multi Layer Perceptron autoencoder.

__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', **kwargs)[source]

Construct MlpAutoEncoder.

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”.

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.

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.

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.

__annotations__ = {}
__doc__ = 'MlpAutoencoder - Multi Layer Perceptron autoencoder.'
__module__ = 'gt4sd.frameworks.granular.ml.models.mlp_auto_encoder.core'