Skip to content

DLinear 总览与 Level 树

Abstract

这篇是 DLinear/ 目录的唯一总入口。

它只做四件事:

  1. 固定当前真实运行例子
  2. 固定一个最小 toy 例子
  3. 给出从命令行到 DLinear.forward(...) 的总顺序图和 Level 树
  4. 说明后续每篇文档各自展开哪一部分

0. DLinear 是什么,为什么存在

0.1 背景困境

2021-2022 年,时间序列预测领域陷入一个奇怪的军备竞赛:

  • Informer 用 ProbSparse Attention 降低 O(L²) → O(L log L)
  • Autoformer 加 Auto-Correlation + 序列分解
  • FEDformer 加频域分析
  • 每篇论文都比前一篇复杂,都声称刷了 SOTA

困境:这些复杂模型,到底是因为 Transformer 结构好,还是因为用了序列分解或归一化这类通用技巧?

0.2 DLinear 的回答

ICLR 2023,Zeng et al. 发表 Are Transformers Effective for Time Series Forecasting?(LTSF-Linear):

把复杂 Transformer 全去掉,只用一个线性层,加一点序列分解,居然打平甚至超过 Informer 等模型。

两个核心动作:

动作做法意义
序列分解x = trend + seasonal分离慢变化与快变化,让线性层只需处理各自的规律
独立线性外推Linear_Seasonal + Linear_Trend各自一个 nn.Linear(seq_len, pred_len),直接映射历史→未来

0.3 这一套文档的学习目的

0. 当前学习这组 DLinear 文档的第一性

当前学习 DLinear,不是为了背一个简单模型名字,而是为了建立三种能力:

  1. 代码实现能力:知道一个最简单的 forecasting 模型怎样接到 TFB 里、怎样收输入、怎样吐输出。
  2. 实验运行能力:知道改 seq_len / pred_len / moving_avg / individual 会影响哪里,能跑通最小实验。
  3. 模型对照能力:用 DLinear 这个最简单基线,分清哪些是 TFB 固定外壳,哪些是 Informer 这种复杂模型才额外引入的机制。

用最小模型建立"读模型代码 → 接框架 → 动代码 → 跑实验"的底座。

1. 当前真实运行例子

固定主线例子:

  • 数据:ETTh1.csv
  • 模型:time_series_library.DLinear
  • adapter:transformer_adapter
  • strategy:rolling_forecast

关键参数:

参数含义
seq_len96encoder 输入历史长度
label_len48decoder 已知段(DLinear 不使用,但 adapter 统一传入)
horizon = pred_len24预测步数
batch_size4每批样本数
moving_avg25滑动平均窗口大小,决定 trend 平滑程度
enc_in7ETTh1 特征数
individualFalse所有变量共享一套 seasonal/trend 线性头

2. 贯穿所有文档的统一 toy 例子

Important

设计原则:B ≠ seq_len ≠ enc_in ≠ pred_len ≠ moving_avg

各维度互不相等,防止 permute/reshape 后 shape 看起来没变化而掩盖轴语义。

参数toy 值真实值
B24
seq_len696
pred_len224
enc_in37
moving_avg325
individualFalseFalse

toy 输入(encoder 侧,x_enc):

python
# shape: (2, 6, 3)  即 (B=2, seq_len=6, enc_in=3)
x_enc[0] = [
    [1.0,  10.0, 100.0],   # t=0
    [2.0,  11.0, 101.0],   # t=1
    [3.0,  12.0, 102.0],   # t=2
    [4.0,  13.0, 103.0],   # t=3
    [5.0,  14.0, 104.0],   # t=4
    [6.0,  15.0, 105.0],   # t=5
]

最终输出 shape:(2, 2, 3)(B, pred_len, enc_in)

3. 总顺序图

4. 总抽象树

5. Level 到文档的映射表

层级文档解决的问题入口出口
Level 101-Level1-配置进入DLinear命令行 → DLinear(config)run_benchmark.pymodel = DLinear(config)
Level 202-Level2-数据进入DLinearbatch → DLinear.forward(...)_process(...)DLinear.forward(x_enc,...)
Level 303-Level3-forward主链forward(...) 走哪条分支DLinear.forward(...)forecast(x_enc)
Level 404-Level4-encoder全链精读encoder(x_enc) 全链encoder(x_enc)(B, pred_len, C)

6. 附录文档

文档职责
A1-参数速查各参数控制哪个张量或模块
A2-Torch函数解释AvgPool1d / permute 等函数补充说明
A3-DLinear论文原理与代码桥接论文动机与代码对应
A4-学习目的与阅读建议当前进度 + 下一步建议

7. 固定阅读顺序

主线(一轮读完):

  1. 01-Level1-配置进入DLinear
  2. 02-Level2-数据进入DLinear
  3. 03-Level3-forward主链
  4. 04-Level4-encoder全链精读
  5. 09-DLinear全览流程图收束

按需查阅:

9. 只留一句

这组 DLinear 文档按"真实运行链 + Level 主树 + 必要附录"组织,所有 toy 例子使用统一参数(B=2, seq_len=6, pred_len=2, enc_in=3, moving_avg=3),各维度互不相等,确保 permute/shape 变化可见。


附:三模型结构对比

*记录并在线阅读我的笔记*