shredx.utils.scaling.min_max_scale#
- shredx.utils.scaling.min_max_scale(tensor: Float[Tensor, '... dim'], feature_range: tuple[float, float] = (0, 1), scaler: tuple[float, float] | None = None) tuple[Float[Tensor, '... dim'], tuple[float, float]]#
Scale a tensor to a given feature range using linear min-max normalization.
The input tensor must contain at least two elements. By default, the tensor is scaled to the (0, 1) interval. Optionally, a precomputed
(min, max)pair can be passed viascalerfor consistent scaling across different tensors.- Parameters:
- tensorFloat[torch.Tensor, “… dim”]
Input tensor to be scaled.
- feature_rangetuple[float, float], optional
Desired range of transformed data, by default
(0, 1).- scalertuple[float, float] or None, optional
Tuple
(min, max)used for scaling, typically obtained from a previous call to this function. IfNone, the minimum and maximum are computed fromtensor.
- Returns:
- scaledFloat[torch.Tensor, “… dim”]
Tensor scaled to the specified
feature_range.- min_maxtuple[float, float]
Tuple
(min, max)values used for scaling, either computed fromtensoror passed in viascaler.
- Raises:
- ValueError
If
feature_rangeis not a tuple of two elements.- ValueError
If
tensorhas fewer than two elements.