Skip to main content

Introduction

Temporal normalization has proven to be essential in neural forecasting tasks, as it enables network’s non-linearities to express themselves. Forecasting scaling methods take particular interest in the temporal dimension where most of the variance dwells, contrary to other deep learning techniques like BatchNorm that normalizes across batch and temporal dimensions, and LayerNorm that normalizes across the feature dimension. Currently we support the following techniques: std, median, norm, norm1, invariant, revin.

References

Figure 1. Illustration of temporal normalization (left), layer normalization (center) and batch normalization (right). The entries in green show the components used to compute the normalizing statistics.

1. Auxiliary Functions

masked_median

Masked Median Compute the median of tensor x along dim, ignoring values where mask is False. x and mask need to be broadcastable. Parameters: Returns:

masked_mean

Masked Mean Compute the mean of tensor x along dimension, ignoring values where mask is False. x and mask need to be broadcastable. Parameters: Returns:

2. Scalers

minmax_statistics

MinMax Scaler Standardizes temporal features by ensuring its range dweels between [0,1] range. This transformation is often used as an alternative to the standard scaler. The scaled features are obtained as: z=(x[B,T,C]min(x)[B,1,C])/(max(x)[B,1,C]min(x)[B,1,C])\mathbf{z} = (\mathbf{x}_{[B,T,C]}-\mathrm{min}({\mathbf{x}})_{[B,1,C]})/ (\mathrm{max}({\mathbf{x}})_{[B,1,C]}- \mathrm{min}({\mathbf{x}})_{[B,1,C]}) Parameters: Returns:

minmax1_statistics

MinMax1 Scaler Standardizes temporal features by ensuring its range dweels between [-1,1] range. This transformation is often used as an alternative to the standard scaler or classic Min Max Scaler. The scaled features are obtained as: z=2(x[B,T,C]min(x)[B,1,C])/(max(x)[B,1,C]min(x)[B,1,C])1\mathbf{z} = 2 (\mathbf{x}_{[B,T,C]}-\mathrm{min}({\mathbf{x}})_{[B,1,C]})/ (\mathrm{max}({\mathbf{x}})_{[B,1,C]}- \mathrm{min}({\mathbf{x}})_{[B,1,C]})-1 Parameters: Returns:

std_statistics

Standard Scaler Standardizes features by removing the mean and scaling to unit variance along the dim dimension. For example, for base_windows models, the scaled features are obtained as (with dim=1): z=(x[B,T,C]xˉ[B,1,C])/σ^[B,1,C]\mathbf{z} = (\mathbf{x}_{[B,T,C]}-\bar{\mathbf{x}}_{[B,1,C]})/\hat{\sigma}_{[B,1,C]} Parameters: Returns:

robust_statistics

Robust Median Scaler Standardizes features by removing the median and scaling with the mean absolute deviation (mad) a robust estimator of variance. This scaler is particularly useful with noisy data where outliers can heavily influence the sample mean / variance in a negative way. In these scenarios the median and amd give better results. For example, for base_windows models, the scaled features are obtained as (with dim=1): z=(x[B,T,C]median(x)[B,1,C])/mad(x)[B,1,C]\mathbf{z} = (\mathbf{x}_{[B,T,C]}-\textrm{median}(\mathbf{x})_{[B,1,C]})/\textrm{mad}(\mathbf{x})_{[B,1,C]} mad(x)=1Nxmedian(x)\textrm{mad}(\mathbf{x}) = \frac{1}{N} \sum_{}|\mathbf{x} - \mathrm{median}(x)| Parameters: Returns:

invariant_statistics

Invariant Median Scaler Standardizes features by removing the median and scaling with the mean absolute deviation (mad) a robust estimator of variance. Aditionally it complements the transformation with the arcsinh transformation. For example, for base_windows models, the scaled features are obtained as (with dim=1): z=(x[B,T,C]median(x)[B,1,C])/mad(x)[B,1,C]\mathbf{z} = (\mathbf{x}_{[B,T,C]}-\textrm{median}(\mathbf{x})_{[B,1,C]})/\textrm{mad}(\mathbf{x})_{[B,1,C]} z=arcsinh(z)\mathbf{z} = \textrm{arcsinh}(\mathbf{z}) Parameters: Returns:

identity_statistics

Identity Scaler A placeholder identity scaler, that is argument insensitive. Parameters: Returns:

3. TemporalNorm Module

TemporalNorm

Bases: Module Temporal Normalization Standardization of the features is a common requirement for many machine learning estimators, and it is commonly achieved by removing the level and scaling its variance. The TemporalNorm module applies temporal normalization over the batch of inputs as defined by the type of scaler. z[B,T,C]=Scaler(x[B,T,C])\mathbf{z}_{[B,T,C]} = \textrm{Scaler}(\mathbf{x}_{[B,T,C]}) If scaler_type is revin learnable normalization parameters are added on top of the usual normalization technique, the parameters are learned through scale decouple global skip connections. The technique is available for point and probabilistic outputs. z^[B,T,C]=γ^[1,1,C]z[B,T,C]+β^[1,1,C]\mathbf{\hat{z}}_{[B,T,C]} = \boldsymbol{\hat{\gamma}}_{[1,1,C]} \mathbf{z}_{[B,T,C]} +\boldsymbol{\hat{\beta}}_{[1,1,C]} Parameters: dim (int, optional): Dimension over to compute scale and shift. Defaults to -1. eps (float, optional): Small value to avoid division by zero. Defaults to 1e-6. num_features (int, optional): For RevIN-like learnable affine parameters initialization. Defaults to None.

TemporalNorm.transform

Center and scale the data. Parameters: Returns:

TemporalNorm.inverse_transform

Scale back the data to the original representation. Parameters: Returns:

Example