Skip to content

Min-Max Normalizer

Min/Max Normalizer¤

(Supports both "scale" and destructive "clip" modes)

neojax.data.normalizers.min_max_normalizer.MinMaxNormalizer ¤

Normalizes data to be within a given min and max.

Minima and maxima can be passed the following ways:

  1. During initialization if known or explicitly required (e.g. known physical bounds).
  2. Learned from data by passing them to compute_stats

Data can be clipped or scaled to [min, max] range.

Parameters:

Name Type Description Default
minima float | int | Float[Array, ...] | None

Optional min for dynamical scaling. Default is None, i.e., use learned min from self.stats. If Array, should be broadcast-compatible with transformation data and maxima.

None
maxima float | int | Float[Array, ...] | None

Optional max for dynamical scaling. Default is None, i.e., use learned max from self.stats. If Array, should be broadcast-compatible with transformation data and minima.

None
Internal Attributes

These fields store the internal state of the normalizer.

  • stats (dict[str, Float[Array, ...] | None]): Dict of min and max if passed at initialization, else None.

Warning

Inverse transformation can only be applied to scaled transformations.

maxima property ¤

Accessor for the max stored in stats.

minima property ¤

Accessor for the min stored in stats.

compute_stats(data: Float[Array, 'c ...'], axis: int | tuple[int, ...] | None = None) -> MinMaxNormalizer ¤

Computes min and max from given data.

To normalize per-channel for input (c, d1, ..., dN), pass axis=tuple(range(1, data.ndim)). To normalize across all axes, pass axis=None.

Parameters:

Name Type Description Default
data Float[Array, 'c ...']

The input array.

required
axis int | tuple[int, ...] | None

Axis or axes along which the statistics are computed. The default (None) computes the global min/max.

None

Returns:

Type Description
MinMaxNormalizer

A new MinMaxNormalizer instance with updated min and max.

transform(x: Float[Array, ...], mode: typing.Literal['clip', 'scale'] = 'scale') -> Float[Array, ...] ¤

Normalizes input by clipping or rescaling it.

Uses learned minima or maxima from self.stats.

Parameters:

Name Type Description Default
x Float[Array, ...]

The input array to transform.

required
mode Literal['clip', 'scale']

Whether to "clip" values to be in [minima, maxima] (inclusive) or "scale" values inside range with standard min/max scaling (x - min) / (max - min + eps). Default is "scale".

'scale'

Warning

"clip" is a destructive operation. Clipped data cannot be reconstructed:

    inverse_transform(transform(x, mode="clip", ...), ...) != x

Returns:

Type Description
Float[Array, ...]

The min/max normalized array.

Raises:

Type Description
ValueError

If the transformation mode is unsupported.

inverse_transform(x: Float[Array, ...]) -> Float[Array, ...] ¤

Reverts scaled min/max normalization.

Can only reverse scaled normalization. Clipped normalizations are irreversible.

Parameters:

Name Type Description Default
x Float[Array, ...]

The standardized array to revert.

required

Returns:

Type Description
Float[Array, ...]

The de-normalized array.

__call__(x: Float[Array, ...], mode: typing.Literal['clip', 'scale'] = 'scale') -> Float[Array, ...] ¤

Standardizes input using learned min and max.

See transform for details.

Parameters:

Name Type Description Default
x Float[Array, ...]

Input array.

required
mode Literal['clip', 'scale']

Whether to "clip" values to be in [minima, maxima] (inclusive) or "scale" values inside range with standard min/max scaling (x - min) / (max - min + eps). Default "scale".

'scale'

Returns:

Type Description
Float[Array, ...]

Standardized input array.