Principle:Sktime Pytorch forecasting Series Decomposition
| Knowledge Sources | |
|---|---|
| Domains | Time_Series, Forecasting, Deep_Learning, Signal_Processing |
| Last Updated | 2026-02-08 09:00 GMT |
Overview
Time series decomposition into trend and seasonal components using a differentiable moving average filter, enabling deep learning models to separately process low-frequency trends and high-frequency seasonal patterns.
Description
Series Decomposition separates a time series into two additive components: a trend component and a seasonal (residual) component. The trend is extracted by applying a moving average filter, and the seasonal component is computed as the difference between the original series and the extracted trend.
The MovingAvg filter smooths the input using average pooling with a configurable kernel size. To preserve the original sequence length, the filter applies edge padding before pooling: the first value of the sequence is replicated to pad the left side, and the last value is replicated to pad the right side. The amount of padding on each side depends on whether the kernel size is odd or even. The filter operates along the time dimension independently for each feature channel.
The SeriesDecomposition module orchestrates this by passing the input through the moving average to obtain the trend, then subtracting the trend from the original input to recover the seasonal component. Both components are returned.
This decomposition is a core building block in the Autoformer architecture and related models, where the trend and seasonal paths are processed by different network branches, allowing each branch to specialize.
Usage
Use SeriesDecomposition as an intra-network layer within forecasting models (e.g., Autoformer) to decompose intermediate representations at each layer. Choose the kernel_size to match the expected periodicity of the data: larger kernels extract smoother, longer-period trends. Typical values are 25 for hourly data or smaller values for lower-frequency data. The decomposition is fully differentiable, so gradients flow through both the trend and seasonal branches.
Theoretical Basis
Additive Decomposition:
Where is the trend component and is the seasonal component at time step .
Moving Average Trend Extraction:
Where is the kernel size. For positions near the boundaries, edge values are replicated to fill the padding.
Seasonal Component:
Edge Padding for Length Preservation:
For a kernel size :
- If is odd: pad on both sides
- If is even: pad on the left and on the right
Padding replicates the boundary values:
Pseudo-code:
# Series Decomposition (pseudo-code)
def series_decomposition(x, kernel_size):
# Edge-padded moving average
front_pad = repeat(x[:, 0:1, :], padding_left)
end_pad = repeat(x[:, -1:, :], padding_right)
x_padded = concat(front_pad, x, end_pad)
trend = avg_pool_1d(x_padded, kernel_size)
# Seasonal = original minus trend
seasonal = x - trend
return seasonal, trend