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

MLP predictor implementation.

Summary

Classes:

MlpPredictor

MlpPredictor - Multi Layer Perceptron predictor.

Reference

class MlpPredictor(name, from_position, data, input_size, hidden_size, output_size, n_layers, activation, dropout, loss_function, class_weights=None, **kwargs)[source]

Bases: GranularBaseModel

MlpPredictor - Multi Layer Perceptron predictor.

__init__(name, from_position, data, input_size, hidden_size, output_size, n_layers, activation, dropout, loss_function, class_weights=None, **kwargs)[source]

Construct MlpPredictor.

Parameters
  • name (str) – model name.

  • from_position (List[int]) – list of input model positions.

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

  • input_size (int) – size of the input.

  • hidden_size (int) – size of the hidden layers.

  • output_size (int) – size of the output.

  • n_layers (int) – number of layers.

  • activation (str) – name of the activation.

  • dropout (float) – dropout rate.

  • loss_function (str) – name of the loss function.

  • class_weights (Optional[List[float], None]) – weights for the classes. Defaults to None, a.k.a., no weighting.

Raises

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

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

Run a step in the model.

Parameters

x (Any) – model input.

Return type

Any

Returns

model step output.

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

Forward pass in the model.

Parameters

x (Any) – model input.

Return type

Any

Returns

model 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__ = 'MlpPredictor - Multi Layer Perceptron predictor.'
__module__ = 'gt4sd.frameworks.granular.ml.models.mlp_predictor.core'