espnet2.asr.state_spaces.components.TSInverseNormalization
espnet2.asr.state_spaces.components.TSInverseNormalization
class espnet2.asr.state_spaces.components.TSInverseNormalization(method, normalizer)
Bases: Module
TSInverseNormalization is a module that performs the inverse normalization operation based on the method used during normalization. This is useful in time series forecasting tasks where the predicted values need to be converted back to the original scale.
method
The method used for normalization. Can be either “mean” or “last”.
- Type: str
normalizer
An instance of the TSNormalization class that holds the scaling factor used during normalization.
Type:TSNormalization
Parameters:
- method (str) – The normalization method used, either “mean” or “last”.
- normalizer (TSNormalization) – The normalizer object containing the scaling information.
Returns: The input tensor scaled back to the original values.
Return type: Tensor
####### Examples
>>> normalizer = TSNormalization(method="mean", horizon=5)
>>> ts_inverse_norm = TSInverseNormalization(method="mean", normalizer=normalizer)
>>> x_normalized = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
>>> x_original = ts_inverse_norm(x_normalized)
NOTE
The scaling is only applied if the method is either “mean” or “last”. If a different method is provided, the input tensor will be returned unchanged.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
forward(x)
Time Series Inverse Normalization module.
This module is used to apply inverse normalization on time series data based on the method specified during initialization. The two supported methods are “mean” and “last”, which correspond to scaling the input tensor by the mean or last observed value during normalization.
method
The method used for normalization; should be either “mean” or “last”.
- Type: str
normalizer
An instance of the TSNormalization class that contains the scaling factor.
Type:TSNormalization
Parameters:
- method (str) – The normalization method to use. Can be “mean” or “last”.
- normalizer (TSNormalization) – An instance of the TSNormalization class used to retrieve the scaling factor.
Returns: The inverse normalized tensor.
Return type: Tensor
####### Examples
>>> normalizer = TSNormalization(method="mean", horizon=5)
>>> ts_inverse_norm = TSInverseNormalization(method="mean", normalizer=normalizer)
>>> input_tensor = torch.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
>>> output_tensor = ts_inverse_norm(input_tensor)
NOTE
Ensure that the normalizer has been applied to the input tensor before using this module for inverse normalization.