You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

STL分解中卷积滤波器提取趋势分量的逻辑及源码解析

STL Decomposition: Convolution Filters for Trend Calculation

Hey there, let's break down your two questions about how convolution filters work in the statsmodels STL implementation, since you've already nailed the seasonal component extraction.


1. How are the filter values (array) generated?

The filter array used for trend calculation in STL is directly tied to the Loess smoothing window (specified by the trend parameter, which should be an odd integer larger than the seasonal period). Here's the core logic:

  • Tricube Weight Kernel: The base filter weights come from the tricube weight function, which gives higher weight to points closer to the center of the smoothing window. For a window centered at position x0, the weight for a point x in the window is:
    weight = (1 - abs((x - x0)/h)**3)**3
    
    where h is half the window width (e.g., for a window size of 7, h = 3). This creates a smooth, bell-shaped weight array that prioritizes local points.
  • Boundary Handling: For points at the start/end of the time series, we can't use a full symmetric window. Statsmodels uses mirroring (extending the series by reflecting its edges) to create a pseudo-symmetric window, ensuring the filter weights remain valid at boundaries without introducing bias.
  • Robust Mode Adjustment: If you're using the robust=True flag, the filter weights get updated iteratively. After each trend estimate, the algorithm calculates absolute residuals, identifies outliers, and down-weights their influence by adjusting the tricube weights using the residuals' median absolute deviation (MAD).

2. How to calculate trend values using the convolution filter?

Trend calculation in STL is an iterative, convolution-based Loess smoothing process. Here's the step-by-step flow (as implemented in statsmodels):

  • Preprocess the Series: First, subtract the current seasonal component estimate from the original observations to get a deseasonalized series (since STL iteratively refines all components).
  • Convolution with Filter Weights: Compute the trend value for each point by performing a weighted convolution between the deseasonalized series and the precomputed filter array. This is equivalent to a local weighted average: for each window, multiply each point by its corresponding filter weight, sum the products, and normalize by the total weight in the window (to keep the scale consistent).
  • Iterative Refinement: STL doesn't stop at one pass. After getting an initial trend, it updates the seasonal component and residuals, then recalculates the filter weights (especially in robust mode) and repeats the convolution step. This loop continues until the components stabilize (changes fall below a convergence threshold).
  • Edge Case Handling: The convolution uses a "same" output mode, so the resulting trend array has the same length as the input series. The mirrored boundary extensions ensure the first/last few trend values are as reliable as the inner points.

内容的提问来源于stack exchange,提问作者gautam vj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 20:42:45