Skip to content

Composed Normalizer

Composing Normalizers¤

Data pipelines often require multiple transformation steps. The ComposedNormalizer allows you to pipe normalizers together.

By default, compute_stats works sequentially through the pipeline: the second normalizer computes its statistics on the data after it has been transformed by the first normalizer. You can disable this by passing sequential=False.

from neojax.data.normalizers import ComposedNormalizer, RobustNormalizer, MinMaxNormalizer

# Build a pipeline
pipeline = ComposedNormalizer(
    RobustNormalizer(),
    MinMaxNormalizer()
)

# Computes robust stats, transforms data, then computes min/max stats on the output
pipeline = pipeline.compute_stats(data)

Composed Normalizer¤

neojax.data.normalizers.composed_normalizer.ComposedNormalizer ¤

Composes multiple normalizers into a pipeline.

The normalizers are applied sequentially in the order they are provided. This class allows for complex normalization pipelines, such as first applying a robust scaler and then a min-max scaling.

Parameters:

Name Type Description Default
*normalizers BaseNormalizer

Normalizer instances to be composed in the pipeline.

required
Internal Attributes

These fields store the internal state of the normalizer.

  • stats (dict[str, tuple[BaseNormalizer, ...]]): Dict containing 'normalizers', which stores the sequence of normalizers as a tuple.

Examples:

import jax.numpy as jnp
from neojax.data.normalizers import (
    ComposedNormalizer,
    MinMaxNormalizer,
    UnitGaussianNormalizer
)

norm = ComposedNormalizer(
    MinMaxNormalizer(),
    UnitGaussianNormalizer()
)

data = jnp.ones((3, 3, 3))
# compute stats (sequentially)
norm = norm.compute_stats(data)

transformed = norm(data)

Info

If all normalizer statistics need to be computed on raw data, pass sequential=False to compute_stats().

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

Computes statistics for each normalizer in the pipeline.

Each normalizer in the pipeline computes its statistics independently based on the provided data, either sequentially of non-sequentially. See sequential for details.

Parameters:

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

The input array to compute statistics from.

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

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

None
sequential bool

Whether to apply stats computations in sequence, i.e., compute the stats on the transformed inputs of the previous normalizer. Non-sequential computes each stat on the raw inputs (e.g. for parallel computation). Default is sequential.

True

Returns:

Type Description
ComposedNormalizer

A new ComposedNormalizer instance with updated statistics for all sub-normalizers.

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

Applies the sequence of normalizations to the input.

Parameters:

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

The input array to transform.

required

Returns:

Type Description
Float[Array, ...]

The transformed array.

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

Reverts the sequence of normalizations in reverse order.

Parameters:

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

The transformed array to revert.

required

Returns:

Type Description
Float[Array, ...]

The de-normalized array.

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

Standardizes input by applying the transform pipeline.

Parameters:

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

Input array.

required

Returns:

Type Description
Float[Array, ...]

Normalized input array.