noether.data.preprocessors.normalizers

Attributes

Classes

NormalizerConfig

Base configuration for normalizers. All normalizer configs should inherit from this class.

ShiftAndScaleNormalizerConfig

Base configuration for normalizers. All normalizer configs should inherit from this class.

ShiftAndScaleNormalizer

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

MeanStdNormalizerConfig

Base configuration for normalizers. All normalizer configs should inherit from this class.

MeanStdNormalization

Normalizes data using mean and standard deviation. It shifts the data by subtracting the mean and scales it by dividing by the standard deviation.

PositionNormalizerConfig

Base configuration for normalizers. All normalizer configs should inherit from this class.

PositionNormalizer

Normalizes position data to a range of [0, scale], or [-scale, scale] when zero_center is True. It inherits from ShiftAndScaleNormalizer and applies a shift and scale based on the provided raw position min and max values.

FieldNormalizerConfig

Declarative normalizer config that references dataset statistics by convention.

FieldNormalizer

Preprocessor that normalizes a field based on a specified strategy and dataset statistics.

Functions

Module Contents

noether.data.preprocessors.normalizers.validate_tensor(v)
Parameters:

v (Any)

Return type:

torch.Tensor

noether.data.preprocessors.normalizers.TorchTensor
noether.data.preprocessors.normalizers.FloatOrArray
noether.data.preprocessors.normalizers.SequenceOrTensor
class noether.data.preprocessors.normalizers.NormalizerConfig(/, **data)

Bases: noether.core.schemas.lib._RegistryBase

Base configuration for normalizers. All normalizer configs should inherit from this class.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

kind: str | None = None

Kind of normalizer to use, i.e. class path

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class noether.data.preprocessors.normalizers.ShiftAndScaleNormalizerConfig(/, **data)

Bases: NormalizerConfig

Base configuration for normalizers. All normalizer configs should inherit from this class.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

kind: str | None = 'noether.data.preprocessors.normalizers.ShiftAndScaleNormalizer'

Kind of normalizer to use, i.e. class path

shift: TorchTensor

Value to subtract from the input data. Can be a single value or a Sequence if we want to apply a different shift per dimension. Assumed in log scale if logscale is True.

scale: TorchTensor

Value to divide the input data by. Can be a single value or a Sequence if we want to apply a different scale per dimension. Assumed in log scale if logscale is True.

logscale: bool = False

If true, the input data is assumed to be in log scale.

check_shift_scale()
Return type:

Self

class noether.data.preprocessors.normalizers.ShiftAndScaleNormalizer(normalizer_config, **kwargs)

Bases: noether.data.preprocessors.PreProcessor

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

Parameters:
  • normalizer_config (ShiftAndScaleNormalizerConfig) – Configuration containing shift and scale values. See ShiftAndScaleNormalizerConfig for details.

  • **kwargs – Additional arguments passed to the parent class.

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.

scale
shift
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

class noether.data.preprocessors.normalizers.MeanStdNormalizerConfig(/, **data)

Bases: NormalizerConfig

Base configuration for normalizers. All normalizer configs should inherit from this class.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

kind: str | None = 'noether.data.preprocessors.normalizers.MeanStdNormalization'

Kind of normalizer to use, i.e. class path

mean: TorchTensor

mean to subtract from the input data. Can be a single value or a Sequence if we want to apply a different mean per dimension.

std: TorchTensor

standard deviation to divide the input data by. Can be a single value or a Sequence if we want to apply a different std per dimension.

logscale: bool = False

If true, the input data is assumed to be in log scale.

class noether.data.preprocessors.normalizers.MeanStdNormalization(normalizer_config, **kwargs)

Bases: ShiftAndScaleNormalizer

Normalizes data using mean and standard deviation. It shifts the data by subtracting the mean and scales it by dividing by the standard deviation.

Parameters:
  • normalizer_config (MeanStdNormalizerConfig) – Configuration containing mean and std values. See MeanStdNormalizerConfig for details.

  • **kwargs – Additional arguments passed to the parent class.

Raises:
  • ValueError – If mean and std do not have the same length.

  • ValueError – If any value in std is zero (to avoid division by zero).

  • ValueError – If any value in std is negative.

EPSILON = 1e-06
mean
std
class noether.data.preprocessors.normalizers.PositionNormalizerConfig(/, **data)

Bases: NormalizerConfig

Base configuration for normalizers. All normalizer configs should inherit from this class.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

kind: str | None = 'noether.data.preprocessors.normalizers.PositionNormalizer'

Kind of normalizer to use, i.e. class path

raw_pos_min: TorchTensor

Minimum raw position values of the entire simulation mesh. Can be a single value or a sequence of values.

raw_pos_max: TorchTensor

Maximum raw position values of the entire simulation mesh. Can be a single value or a sequence of values.

scale: float = None

Scaling factor, the coordinates will be scaled linearly between [0, scale] (or [-scale, scale] if zero_center is True). Defaults to 1000.

zero_center: bool = False

If True, coordinates are scaled to [-scale, scale] instead of [0, scale].

check_min_max()
Return type:

Self

class noether.data.preprocessors.normalizers.PositionNormalizer(normalizer_config, **kwargs)

Bases: ShiftAndScaleNormalizer

Normalizes position data to a range of [0, scale], or [-scale, scale] when zero_center is True. It inherits from ShiftAndScaleNormalizer and applies a shift and scale based on the provided raw position min and max values.

Parameters:
  • normalizer_config (PositionNormalizerConfig) – Configuration containing raw position min, max, scale, and zero_center values. See PositionNormalizerConfig for details.

  • **kwargs – Additional arguments passed to the parent class.

Raises:
  • ValueError – If raw_pos_min and raw_pos_max do not have the same length.

  • ValueError – If raw_pos_max is equal to raw_pos_min.

  • ValueError – If scale is not a positive number.

EPSILON = 1e-06
raw_pos_min
raw_pos_max
zero_center
resizing_scale
class noether.data.preprocessors.normalizers.FieldNormalizerConfig(/, **data)

Bases: NormalizerConfig

Declarative normalizer config that references dataset statistics by convention.

Instead of embedding numeric values (mean, std, etc.) directly, this config declares how to normalize a field. The actual statistics are resolved at runtime from the dataset’s statistics file.

For "mean_std" normalization, the builder looks up {field}_mean and {field}_std in the dataset statistics (customizable via stat_keys).

For "min_max" normalization, the builder looks up {field}_min and {field}_max (customizable via stat_keys).

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

kind: str | None = 'noether.data.preprocessors.normalizers.FieldNormalizer'

Kind of normalizer to use, i.e. class path

strategy: Literal['mean_std', 'position', 'min_max'] = 'mean_std'

Normalization strategy. "mean_std" for mean/std normalization, "min_max" for min/max normalization.``”position”`` is an alias for min_max,

logscale: bool = False

If true, the input data is converted to log scale before normalization. Only used for "mean_std".

stat_keys: dict[str, str] | None = None

{"mean": "custom_mean_key", "std": "custom_std_key"}. For "min_max/position": {"min": "custom_min_key", "max": "custom_max_key"}.

Type:

Optional overrides for statistic key lookup. For "mean_std"

scale: float = None

Scaling factor for position normalization. Coordinates are scaled to [0, scale]. Only used for "position".

zero_center: bool = False

If True, position normalization is zero-centered (scaled to [-scale, scale]) instead of [0, scale]. Only used for "position".

class noether.data.preprocessors.normalizers.FieldNormalizer(normalizer_config, statistics, **kwargs)

Bases: noether.data.preprocessors.PreProcessor

Preprocessor that normalizes a field based on a specified strategy and dataset statistics.

Parameters:
  • normalizer_config (FieldNormalizerConfig) – Configuration containing the normalization strategy and logscale flag. See FieldNormalizerConfig for details.

  • statistics (dict[str, list[float | int] | float | int] | None) – A dictionary containing the dataset statistics needed for normalization (e.g., mean, std, raw_pos_min, raw_pos_max).

  • **kwargs – Additional arguments passed to the parent class.

Raises:
  • ValueError – If the required statistics for the chosen strategy are not present in the statistics dictionary.

  • ValueError – If the normalization strategy is not supported.

normalizer: noether.data.preprocessors.PreProcessor
denormalize(x)

Denormalizes the input data. This method should be overridden by subclasses if denormalization is supported. If denormalization is not supported, it raises NotImplementedError or decide to implement the identity function.

Parameters:

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

Return type:

torch.Tensor

noether.data.preprocessors.normalizers.AnyNormalizer