Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Sktime Pytorch forecasting Series Decomposition

From Leeroopedia


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:

xt=τt+st

Where τt is the trend component and st is the seasonal component at time step t.

Moving Average Trend Extraction:

τt=1ki=(k1)/2(k1)/2xt+i

Where k is the kernel size. For positions near the boundaries, edge values are replicated to fill the padding.

Seasonal Component:

st=xtτt

Edge Padding for Length Preservation:

For a kernel size k:

  • If k is odd: pad k/2 on both sides
  • If k is even: pad k/21 on the left and k/2 on the right

Padding replicates the boundary values:

x~=[x1,,x1left pad,x1,x2,,xT,xT,,xTright pad]

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

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment