emmi.modules.preprocessors.normalizers.shift_and_scale_normalizer

Classes

ShiftAndScaleNormalizer

Preprocessor that shifts and scales the input data, with (x + shift) * scale.

Module Contents

class emmi.modules.preprocessors.normalizers.shift_and_scale_normalizer.ShiftAndScaleNormalizer(normalizer_config, **kwargs)

Bases: ksuit.data.preprocessors.PreProcessor

Preprocessor that shifts and scales the input data, with (x + shift) * scale.

Parameters:
  • shift – shift to apply to the input data. Can be a Sequence if we want to apply a different scale per dimension. Defaults to None.

  • scale – scale to apply to the input data. Can be a Sequence if we want to apply a different scale per dimension. Defaults to None.

  • logscale_shift – Shift to apply when the target tensor is in log scale. Defaults to None.

  • logscale_scale – Scale to apply when the target tensor is in log scale. Defaults to None.

  • logscale – If true, the values we want to shift and scale are transformed to logscale. That implies that the mean and std should be comped in log scale as well. Defaults to False.

  • normalizer_config (ksuit.schemas.normalizers.normalizer_config.ShiftAndScaleNormalizerConfig)

Raises:
  • ValueError – If shift and scale do not have the same length.

  • ValueError – If logscale_shift and logscale_scale do not have the same length when logscale is True.

  • TypeError – If shift, scale, logscale_shift, or logscale_scale are not of type Sequence or torch.Tensor.

  • ValueError – If scale contains zero values (to avoid division by zero).

  • ValueError – If scale contains negative values.

  • ValueError – If shift and scale are provided but not both.

shift: torch.Tensor | None = None
scale: torch.Tensor | None = None
logscale
denormalize(x)

Denormalizes the input data by applying the inverse operation of the normalization.

Parameters:

x (torch.Tensor) – torch.Tensor: The input tensor to denormalize.

Return type:

torch.Tensor