Skip to content

Normalization Config

Source

Pydantic models for normalization strategies.

MeanStdConfig

Bases: BaseModel

Mean and standard deviation normalization configuration.

Holds mean and standard deviation statistics for input and target, used to normalize data. Each statistic can be a single float (applied globally to all channels) or a list of floats (one per channel). If not provided, statistics can be computed automatically.

Attributes:

Name Type Description
name Literal['mean_std']

Identifier for the mean-std normalization scheme.

input_means float | list[float] | None

Means for input normalization. None for automatic computation.

input_stds float | list[float] | None

Standard deviations for input normalization. None for automatic computation.

target_means float | list[float] | None

Means for target normalization. None for automatic computation.

target_stds float | list[float] | None

Standard deviations for target normalization. None for automatic computation.

per_channel bool

When True (default), statistics are computed independently for each channel. When False, a single statistic is computed across all channels.

needs_computation()

Check if statistics need to be computed.

Returns:

Type Description
bool

True if input statistics are missing, False otherwise.

set_input_stats(means, stds)

Set input means and stds together to avoid validation errors.

Parameters:

Name Type Description Default
means list[float]

Mean values per channel.

required
stds list[float]

Standard deviation values per channel.

required

set_target_stats(means, stds)

Set target means and stds together to avoid validation errors.

Parameters:

Name Type Description Default
means list[float]

Mean values per channel.

required
stds list[float]

Standard deviation values per channel.

required

validate_means_stds()

Validate that means and stds are provided in pairs or set to None.

Returns:

Type Description
Self

The validated model instance.

Raises:

Type Description
ValueError

If only one of means or stds is provided for input or target, or if paired lists have mismatched lengths.

MinMaxConfig

Bases: BaseModel

Min-max normalization configuration.

Stores minimum and maximum statistics for scaling data into a desired range. Each statistic can be a single float (applied globally to all channels) or a list of floats (one per channel). If not provided, statistics can be computed automatically.

Attributes:

Name Type Description
name Literal['min_max']

Identifier for min-max normalization.

input_mins float | list[float] | None

Minimum values for input normalization. None for automatic computation.

input_maxes float | list[float] | None

Maximum values for input normalization. None for automatic computation.

target_mins float | list[float] | None

Minimum values for target normalization. None for automatic computation.

target_maxes float | list[float] | None

Maximum values for target normalization. None for automatic computation.

per_channel bool

When True (default), statistics are computed independently for each channel. When False, a single statistic is computed across all channels.

needs_computation()

Check if min/max values need to be computed.

Returns:

Type Description
bool

True if input statistics are missing, False otherwise.

set_input_range(mins, maxes)

Set input mins and maxes together to avoid validation errors.

Parameters:

Name Type Description Default
mins list[float]

Minimum values per channel.

required
maxes list[float]

Maximum values per channel.

required

set_target_range(mins, maxes)

Set target mins and maxes together to avoid validation errors.

Parameters:

Name Type Description Default
mins list[float]

Minimum values per channel.

required
maxes list[float]

Maximum values per channel.

required

validate_mins_maxes()

Validate that mins and maxes are provided in pairs or both None.

Returns:

Type Description
Self

The validated model instance.

Raises:

Type Description
ValueError

If only one of mins or maxes is provided for input or target, or if paired lists have mismatched lengths.

NoNormConfig

Bases: BaseModel

No normalization configuration.

Indicates that no normalization should be applied.

Attributes:

Name Type Description
name Literal['none']

Identifier for no normalization scheme.

needs_computation()

Check if statistics need to be computed.

Returns:

Type Description
bool

Always False, as no statistics are required.

QuantileConfig

Bases: BaseModel

Quantile normalization configuration.

Normalizes data using quantile-based range scaling. Quantile levels can be specified as a single value (applied to all channels) or a list (one per channel). If not provided, quantile values can be computed automatically.

Attributes:

Name Type Description
name Literal['quantile']

Identifier for quantile normalization.

lower_quantiles float | list[float]

Lower quantile level(s). Values must be in [0, 1).

upper_quantiles float | list[float]

Upper quantile level(s). Values must be in (0, 1].

input_lower_quantile_values float | list[float] | None

Computed lower quantile values for input.

input_upper_quantile_values float | list[float] | None

Computed upper quantile values for input.

target_lower_quantile_values float | list[float] | None

Computed lower quantile values for target.

target_upper_quantile_values float | list[float] | None

Computed upper quantile values for target.

per_channel bool

When True (default), quantile values are computed independently for each channel. When False, a single quantile is computed across all channels.

needs_computation()

Check if quantile values need to be computed.

Returns:

Type Description
bool

True if quantile values need to be computed.

set_input_quantile_values(lower, upper)

Set input quantile values together to avoid validation errors.

Parameters:

Name Type Description Default
lower list[float]

Lower quantile values per channel.

required
upper list[float]

Upper quantile values per channel.

required

set_target_quantile_values(lower, upper)

Set target quantile values together to avoid validation errors.

Parameters:

Name Type Description Default
lower list[float]

Lower quantile values per channel.

required
upper list[float]

Upper quantile values per channel.

required

validate_per_channel()

Validate quantile levels match per_channel setting.

Returns:

Type Description
Self

The validated model instance.

Raises:

Type Description
ValueError

If per_channel=False but quantile levels are not length 1.

validate_quantile_levels()

Validate quantile levels are in valid range and properly ordered.

Returns:

Type Description
Self

The validated model instance.

validate_quantile_values()

Validate that computed quantile value lists are provided in pairs.

Returns:

Type Description
Self

The validated model instance.