Appearance
05-收束
本文件作用
本文件把 TimesNet 文档集收束成一张可复习的完整接口树。它不新增复杂细节,只负责把入口、主链、子块、出口接起来。
1. 完整执行树
2. 文件对应关系
| 文件 | 层级 | 入口 | 出口 |
|---|---|---|---|
| [[00-总览]] | 总览 | TimesNet 文档集 | 学习路径与全局图 |
| [[调试形参]] | 调试入口 | run_benchmark.py 参数 | 可直接复制到 PyCharm / VSCode 的参数 |
| [[01-Layer0-接入界面]] | Layer0 | forecast_fit() 补齐 config + TransformerAdapter._process() | TimesNet.forward(x_enc, x_mark_enc, x_dec, x_mark_dec) |
| [[02-Layer1-forecast主链]] | Layer1 | TimesNet.forecast(x_enc, x_mark_enc, x_dec, x_mark_dec) | dec_out: (B,seq_len+pred_len,c_out) |
| [[03A-Layer2A-DataEmbedding]] | Layer2A | self.enc_embedding(x_enc, x_mark_enc) | enc_out: (B,seq_len,d_model) |
| [[03B-Layer2B-TimesBlock]] | Layer2B | self.model[i](enc_out) | enc_out: (B,T,d_model) |
| [[03B1-Layer3-FFT_for_Period]] | Layer3 | FFT_for_Period(x,k) | period_list 与 period_weight |
| [[03B2-Layer3-Inception_Block_V1]] | Layer3 | self.conv(out) | 二维周期网格卷积输出 |
3. 一句话掌握 TimesNet
TimesNet 的主线是:
text
归一化数值序列
-> 嵌入到 hidden 空间
-> 用线性层把时间长度扩展到历史+未来
-> FFT 找主要周期
-> 每个周期把 1D 时间折成 2D 周期网格
-> 用多尺度 2D 卷积提取周期模式
-> 按周期强度加权融合
-> 映射回原变量空间
-> 反归一化并截取未来窗口4. toy shape 总表
| 步骤 | 张量 |
|---|---|
x_enc | (3,8,4) |
_process 构造 x_dec | (3,9,4) |
| Normalization | (3,8,4) |
| DataEmbedding | (3,8,6) |
permute(0,2,1) | (3,6,8) |
predict_linear: 8 -> 13 | (3,6,13) |
permute(0,2,1) | (3,13,6) |
TimesBlock 输入 | (3,13,6) |
period=4 padding | (3,16,6) |
period=4 2D grid | (3,6,4,4) |
Inception conv | (3,6,4,4) |
| reshape back and crop | (3,13,6) |
| stack top_k=2 | (3,13,6,2) |
| weighted sum + residual | (3,13,6) |
| projection | (3,13,4) |
| De-Normalization | (3,13,4) |
| forward tail slice | (3,5,4) |
5. 与已学模型的差异
| 模型 | 核心操作 | 代码阅读重点 |
|---|---|---|
| DLinear | 趋势/季节分解 + 线性层 | 分解窗口、Linear 输入输出 |
| PatchTST | patch 化 + Transformer Encoder | unfold、patch embedding、attention |
| Informer | ProbSparse Attention + Encoder/Decoder | Q/K/V、ProbAttention、decoder 输入 |
| TimesNet | FFT 周期发现 + 2D Inception 卷积 | rfft、周期 reshape、Conv2d、周期融合 |
6. 下一步阅读建议
- 先用 [[调试形参]] 跑通 TimesNet,并把断点打在
TimesNet.forward()、TimesNet.forecast()、TimesBlock.forward()、FFT_for_Period()。 - 在
TimesBlock.forward()内观察period_list,确认不同 batch 下period_weight如何变化。 - 对比 PatchTST 的 patch 网格和 TimesNet 的周期网格:PatchTST 的二维结构来自滑窗切片,TimesNet 的二维结构来自 FFT 选周期后的重排。
- 最后回到论文,把 TimesNet 的创新点对应到三个代码点:
FFT_for_Period、reshape(B,length//period,period,N)、Inception_Block_V1。