模块更新于 2026-11-20· 浏览 0· 下载 0
RCF 残差周期预测
显式建模周期:为每个通道维护一组长度为 W 的可学习循环周期,按时间索引对齐后从输入中减去,骨干只预测残差,输出端再把周期分量加回来
结构图

显式建模周期:为每个通道维护一组长度为 W 的可学习循环周期,按时间索引对齐后从输入中减去,骨干只预测残差,输出端再把周期分量加回来
论文信息
- 论文:CycleNet: Enhancing Time Series Forecasting through Modeling Periodic Patterns
- 出处:NeurIPS 2024
核心痛点
长期时序预测依赖数据里稳定的周期模式,但 Informer、PatchTST 等主流模型靠深而复杂的网络间接提取周期;Autoformer、DLinear 等的滑动均值分解又被回看窗口框死,边缘补零还会失真。
模块亮点
- 显式建模周期:为每个通道维护一组长度为 W 的可学习循环周期,按时间索引对齐后从输入中减去,骨干只预测残差,输出端再把周期分量加回来
- 涨点幅度可观:消融中 Linear / MLP 基线加 RCF 后预测精度提升约 10%~20%;DLinear 加 RCF 仍能再降约 20%
- 几乎零开销:只新增 W×D 个可学习参数、无任何乘加运算(MACs 为 0);W 按数据集最大周期先验设定即可,设错也几乎不受影响
适用场景
领域为长期时间序列预测;原文在 ETT、Weather、Traffic、Electricity、Solar-Energy 上验证,CycleNet/MLP、CycleNet/Linear 分别综合排名第一、第二;适合电力负荷、交通流量、气象等带稳定周期的任务。
插入位置建议
- 包在任意预测模型最外层:输入端减去周期分量、骨干预测残差、输出端加回周期
- 与单层 Linear 或双层 MLP 组合,即得原文的 CycleNet/Linear 与 CycleNet/MLP
- 套在 PatchTST、iTransformer、DLinear 等模型外做即插即用增强,记得传入周期索引 cycle_index
适用任务
- 长期时间序列预测
完整代码
rcf.py
# import torch
# import torch.nn as nn
#
# class RecurrentCycle(torch.nn.Module):
# # Thanks for the contribution of wayhoww.
# # The new implementation uses index arithmetic with modulo to directly gather cyclic data in a single operation,
# # while the original implementation manually rolls and repeats the data through looping.
# # It achieves a significant speed improvement (2x ~ 3x acceleration).
# # See https://github.com/ACAT-SCUT/CycleNet/pull/4 for more details.
# def __init__(self, cycle_len, channel_size):
# super(RecurrentCycle, self).__init__()
# self.cycle_len = cycle_len
# self.channel_size = channel_size
# self.data = torch.nn.Parameter(torch.zeros(cycle_len, channel_size), requires_grad=True)
#
# def forward(self, index, length):
# gather_index = (index.view(-1, 1) + torch.arange(length, device=index.device).view(1, -1)) % self.cycle_len
# return self.data[gather_index]
#
#
# if __name__ == '__main__':
# # 定义周期长度和通道数
# cycle_len = 12
# channel_size = 5
#
# # 初始化RecurrentCycle模块
# block = RecurrentCycle(cycle_len=cycle_len, channel_size=channel_size)
#
# # 测试数据
# batch_size = 4 # 批次大小
# seq_len = 10 # 每个序列的长度
# index = torch.randint(0, cycle_len, (batch_size,)) # 随机生成批次的周期起始索引
#
# # 前向传播
# output = block(index, seq_len)
#
# print("输入索引的形状:", index.size()) # (batch_size,)
# print("输出的形状:", output.size()) # (batch_size, seq_len, channel_size)
"""(NeurIPS 2024)CycleNet: Enhancing Time Series Forecasting through Modeling Periodic Patterns
时间序列数据中存在的稳定周期模式是进行长期预测的基础。在本文中,我们率先探索了显式建模这种周期性,以提高模型在长期时间序列预测 (LTSF) 任务中的性能。
具体来说,我们介绍了残差周期预测 (RCF) 技术,该技术利用可学习的循环来模拟序列中固有的周期性模式,然后对建模周期的残余成分进行预测。将 RCF 与线性层或浅层 MLP 相结合,形成了本文提出的简单而强大的方法,称为 CycleNet。
CycleNet 在包括电力、天气和能源在内的多个领域实现了最先进的预测精度,同时通过减少 90% 以上的所需参数数量来提供显着的效率优势
。此外,作为一种新颖的即插即用技术,RCF 还可以显著提高现有模型的预测精度,包括 PatchTST 和 iTransformer。
"""
# 使用示例
import torch
import torch.nn as nn
class RecurrentCycle(torch.nn.Module):
def __init__(self, cycle_len, channel_size):
super(RecurrentCycle, self).__init__()
self.cycle_len = cycle_len
self.channel_size = channel_size
self.data = torch.nn.Parameter(torch.zeros(cycle_len, channel_size), requires_grad=True)
def forward(self, index, length):
gather_index = (index.view(-1, 1) + torch.arange(length, device=index.device).view(1, -1)) % self.cycle_len
return self.data[gather_index]
class TimeSeriesModel(nn.Module):
def __init__(self, seq_len, pred_len, cycle_len, channel_size, model_type='linear', d_model=64):
super(TimeSeriesModel, self).__init__()
self.seq_len = seq_len
self.pred_len = pred_len
self.cycle_len = cycle_len
self.channel_size = channel_size
self.model_type = model_type
self.d_model = d_model
# RecurrentCycle module
self.cycleQueue = RecurrentCycle(cycle_len=self.cycle_len, channel_size=self.channel_size)
# Prediction model (could be Linear or MLP)
if self.model_type == 'linear':
self.model = nn.Linear(self.seq_len, self.pred_len)
elif self.model_type == 'mlp':
self.model = nn.Sequential(
nn.Linear(self.seq_len, self.d_model),
nn.ReLU(),
nn.Linear(self.d_model, self.pred_len)
)
def forward(self, x, cycle_index):
# x: (batch_size, seq_len, channel_size), cycle_index: (batch_size,
# Remove the cycle of the input data
x = x - self.cycleQueue(cycle_index, self.seq_len)
# Perform prediction
y = self.model(x.permute(0, 2, 1)).permute(0, 2, 1)
# Add back the cycle of the output data
y = y + self.cycleQueue((cycle_index + self.seq_len) % self.cycle_len, self.pred_len)
return y
# 示例:创建并运行模型
if __name__ == '__main__':
batch_size = 4
seq_len = 10
pred_len = 10
cycle_len = 20
channel_size = 5
model_type = 'linear'
model = TimeSeriesModel(seq_len=seq_len, pred_len=pred_len, cycle_len=cycle_len, channel_size=channel_size, model_type=model_type)
# (batch_size, seq_len, channel_size)
input_tensor = torch.rand(batch_size, seq_len, channel_size)
# 创建索引 (batch_size,)
cycle_index = torch.randint(0, cycle_len, (batch_size,))
output = model(input_tensor, cycle_index)
print("输入的形状:", input_tensor.size())
print("输出的形状:", output.size())
环境与依赖
Python 3.9+
继续浏览
下一篇RCM 矩形自校准模块矩形区域显式建模:水平池化 + 垂直池化捕获双向轴向全局上下文,广播相加圈出矩形关键区域,再用 3×3 深度卷积细化局部细节,与校准后的注意力融合相关资源
模块2026-11-20
FAN 频率自适应归一化
频域剥非平稳:对每个输入实例做 DFT,TopK 挑出幅度最大的 K 个主频分量并从输入中减去,骨干只预测平稳残差;FFT 复杂度 O(L log L),GPU 友好
时间序列预测傅里叶变换FAN
时间序列MIT
模块2026-11-20
AdaWave 自适应小波块
小波基可学习:用提升方案的 split–predict–update 三步做小波分解,预测和更新算子全部换成可学习的分组一维卷积,小波基跟着数据自适应学出来,逐级输出低频近似和高频细节
时间序列AdaWave小波变换
时间序列MIT
模块2026-11-20
DDI 双重依赖交互模块
时序通道一体交互:多尺度聚合信息按通道堆叠后切成 patch,先用时间步共享的 MLP 聚合时序依赖,再转置用通道共享的 MLP 融合跨通道依赖,残差保底
时间序列预测DDIAAAI2025
时间序列MIT