Normalization Config
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(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:
-
bool–True if input statistics are missing, False otherwise.
set_input_stats(means, stds)
set_target_stats(means, stds)
validate_global_stats_single_element(v, info)
classmethod
Validate stats length against the per_channel parameter.
Parameters:
-
v(OptionalFloatStats) –Value to validate.
-
info(ValidationInfo) –Validated values.
Returns:
-
OptionalFloatStats–Validate value.
validate_means_stds()
Validate that means and stds are provided in pairs or set to None.
Returns:
-
Self–The validated model instance.
Raises:
-
ValueError–If only one of means or stds is provided for input or target, or if paired lists have mismatched lengths.
validate_size(n_input_channels, n_output_channels)
Validate that statistics sizes match the number of channels.
Parameters:
-
n_input_channels(int) –The number of input channels to validate against.
-
n_output_channels(int) –The number of output channels to validate against.
Raises:
-
ValueError–If any provided statistics list does not match the expected size.
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(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:
-
bool–True if input statistics are missing, False otherwise.
set_input_range(mins, maxes)
set_target_range(mins, maxes)
validate_global_stats_single_element(v, info)
classmethod
Validate stats length against the per_channel parameter.
Parameters:
-
v(OptionalFloatStats) –Value to validate.
-
info(ValidationInfo) –Validated values.
Returns:
-
OptionalFloatStats–Validate value.
validate_mins_maxes()
Validate that mins and maxes are provided in pairs or both None.
Returns:
-
Self–The validated model instance.
Raises:
-
ValueError–If only one of mins or maxes is provided for input or target, or if paired lists have mismatched lengths.
validate_size(n_input_channels, n_output_channels)
Validate that statistics sizes match the number of channels.
Parameters:
-
n_input_channels(int) –The number of input channels to validate against.
-
n_output_channels(int) –The number of output channels to validate against.
Raises:
-
ValueError–If any provided statistics list does not match the expected size.
NoNormConfig
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(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:
-
bool–True if quantile values need to be computed.
set_input_quantile_values(lower, upper)
set_target_quantile_values(lower, upper)
validate_global_stats_single_element(v, info)
classmethod
Validate stats length against the per_channel parameter.
Parameters:
-
v(OptionalFloatStats) –Value to validate.
-
info(ValidationInfo) –Validated values.
Returns:
-
OptionalFloatStats–Validate value.
validate_quantile_levels()
Validate quantile levels are in valid range and properly ordered.
Returns:
-
Self–The validated model instance.
validate_quantile_values()
Validate that computed quantile value lists are provided in pairs.
Returns:
-
Self–The validated model instance.
validate_size(n_input_channels, n_output_channels)
Validate that statistics sizes match the number of channels.
Parameters:
-
n_input_channels(int) –The number of input channels to validate against.
-
n_output_channels(int) –The number of output channels to validate against.
Raises:
-
ValueError–If any provided statistics list does not match the expected size.