mlcolvar.core.transform.tools.Normalization

class mlcolvar.core.transform.tools.Normalization(in_features: int, mean: Tensor = None, range: Tensor = None, stats: dict = None, mode: str = 'mean_std')[source]

Bases: Transform

Normalizing block, used for computing standardized inputs/outputs.

__init__(in_features: int, mean: Tensor = None, range: Tensor = None, stats: dict = None, mode: str = 'mean_std')[source]

Initialize a normalization object. Values will be subtracted by self.mean and then divided by self.range. The parameters for the standardization can be either given from the user (via mean/range keywords), or they can be calculated from a datamodule. In the former, the mode will be overriden as ‘custom’. ‘In the latter, the standardization mode can be either ‘mean_std’ (remove by the mean and divide by the standard deviation) or ‘min_max’ (scale and shift the range of values such that all inputs are between -1 and 1).

Parameters:
  • in_features (int) – number of inputs

  • mean (torch.Tensor, optional) – values to be subtracted

  • range (torch.Tensor, optional) – values to be scaled by

  • mode (str, optional) – normalization mode (mean_std, min_max), by default ‘mean_std’

Methods

__init__(in_features[, mean, range, stats, mode])

Initialize a normalization object.

extra_repr()

Return the extra representation of the module.

forward(x)

Compute standardized inputs.

inverse(x)

Remove standardization.

set_custom([mean, range])

Set parameter of the normalization layer.

set_from_stats(stats[, mode])

Set parameters of the normalization layer based on a dictionary with statistics

setup_from_datamodule(datamodule)

Initialize parameters based on pytorch lighting datamodule.

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor[source]

Compute standardized inputs.

Parameters:

x (torch.Tensor) – input/output

Returns:

out – standardized inputs

Return type:

torch.Tensor

inverse(x: Tensor) Tensor[source]

Remove standardization.

Parameters:

x (torch.Tensor) – input

Returns:

out – un-normalized inputs

Return type:

torch.Tensor

set_custom(mean: Tensor = None, range: Tensor = None)[source]

Set parameter of the normalization layer.

Parameters:
  • mean (torch.Tensor) – Value that will be removed.

  • range (torch.Tensor, optional) – Value that will be divided for.

set_from_stats(stats: dict, mode: str = None)[source]

Set parameters of the normalization layer based on a dictionary with statistics

Parameters:
  • stats (dict or Statistics) – dictionary with statistics

  • mode (str, optional) – standardization mode (‘mean_std’ or ‘min_max’), by default None (will use self.mode)

setup_from_datamodule(datamodule)[source]

Initialize parameters based on pytorch lighting datamodule.

Attributes

T_destination

call_super_init

dump_patches

training