学术
模块更新于 2026-11-20· 浏览 1· 下载 0

M-KAN 多阶KAN表示学习模块

双分支解耦:一条支路用 ChebyshevKAN(切比雪夫多项式替代样条,避开原始 KAN 递归低效)沿通道学表征,另一条用深度卷积捕获时序依赖;

时间序列时间序列时间序列预测MKANKANICLR2025

结构图

M-KAN 多阶KAN表示学习模块结构图
M-KAN 多阶KAN表示学习模块结构图

双分支解耦:一条支路用 ChebyshevKAN(切比雪夫多项式替代样条,避开原始 KAN 递归低效)沿通道学表征,另一条用深度卷积捕获时序依赖;

论文信息

  • 论文:TimeKAN: KAN-based Frequency Decomposition Learning Architecture for Long-term Time Series Forecasting
  • 出处:ICLR 2025

核心痛点

真实时间序列由多个频率成分交织而成,混在一起极难建模。主流思路是先分解,但分解后往往对不同频率套同一套方法,用固定激活函数的 MLP 表征能力不够,预测次优。

模块亮点

  • 双分支解耦:一条支路用 ChebyshevKAN(切比雪夫多项式替代样条,避开原始 KAN 递归低效)沿通道学表征,另一条用深度卷积捕获时序依赖;消融中去掉深度卷积或换自注意力都掉点(Weather MSE 从 0.162 升至 0.168)
  • 阶数随频率递增:低频到高频用阶数逐级递增的 KAN,对齐频带复杂度;消融中比统一换 MLP、固定低阶、固定高阶都好,多阶 KAN 在 ETTh2 上 MSE 仅 0.290
  • 极致轻量:KAN 极少神经元即可够用,深度卷积分组进一步省参数;TimeKAN 在 Weather 上参数量仅为 TimeMixer 的 20.05%、MACs 仅为 36.14%

适用场景

领域为多变量长时间序列预测;原文在 Weather、ETTh1、ETTh2、ETTm1、ETTm2、Electricity 六个数据集上验证,除 Electricity 外均达 SOTA;可迁移到能源等时序任务。

插入位置建议

  • 替换 DLinear、TimeMixer 等分解类模型中作用于各分量的 MLP / 线性层
  • 作为通用时序块插在 Embedding 之后、预测头之前,输入输出均为 (B, T, D)
  • 接入 SCINet、TimesNet、PDF 等多尺度框架的子序列分支,按尺度分配阶数

适用任务

  • 多变量长时间序列预测

完整代码

m-kan.py
import torch
import torch.nn as nn


"""《TimeKAN: KAN-based Frequency Decomposition Learning Architecture for Long-term Time Series Forecasting》 ICLR 2025
现实世界的时间序列通常具有多个相互交织的频率成分,这使得准确的时间序列预测具有挑战性。将混合频率成分分解为多个单频率成分是一种自然的选择。
然而,模式的信息密度在不同频率上有所不同,对不同频率成分采用统一的建模方法可能会导致不准确的表征。
为了应对这一挑战,受最近的 Kolmogorov-Arnold 网络 (KAN) 灵活性的启发,我们提出了一种基于 KAN 的频率分解学习架构 (TimeKAN),以解决由多频率混合引起的复杂预测挑战。
具体来说,TimeKAN 主要由三个组件组成:级联频率分解 (CFD) 块、多阶 KAN 表示学习 (M-KAN) 块和频率混合块。CFD 块采用自下而上的级联方法获得每个频带的序列表示。
得益于 KAN 的高灵活性,我们设计了一个新颖的 M-KAN 块来学习和表示每个频带内的特定时间模式。最后,使用频率混合块将频带重新组合为原始格式。
在多个真实世界时间序列数据集上进行的大量实验结果表明,TimeKAN 作为一种极轻量级架构实现了最先进的性能。
"""


# This is inspired by Kolmogorov-Arnold Networks but using Chebyshev polynomials instead of splines coefficients
class ChebyKANLinear(nn.Module):
    def __init__(self, input_dim, output_dim, degree):
        super(ChebyKANLinear, self).__init__()
        self.inputdim = input_dim
        self.outdim = output_dim
        self.degree = degree

        self.cheby_coeffs = nn.Parameter(torch.empty(input_dim, output_dim, degree + 1))
        self.epsilon = 1e-7
        self.pre_mul = False
        self.post_mul = False
        nn.init.normal_(self.cheby_coeffs, mean=0.0, std=1 / (input_dim * (degree + 1)))
        self.register_buffer("arange", torch.arange(0, degree + 1, 1))

    def forward(self, x):
        # Since Chebyshev polynomial is defined in [-1, 1]
        # We need to normalize x to [-1, 1] using tanh
        # View and repeat input degree + 1 times
        b,c_in = x.shape
        if self.pre_mul:
            mul_1 = x[:,::2]
            mul_2 = x[:,1::2]
            mul_res = mul_1 * mul_2
            x = torch.concat([x[:,:x.shape[1]//2], mul_res])
        x = x.view((b, c_in, 1)).expand(
            -1, -1, self.degree + 1
        )  # shape = (batch_size, inputdim, self.degree + 1)
        # Apply acos
        x = torch.tanh(x)
        x = torch.tanh(x)
        x = torch.acos(x)
        # x = torch.acos(torch.clamp(x, -1 + self.epsilon, 1 - self.epsilon))
        # # Multiply by arange [0 .. degree]
        x = x* self.arange
        # Apply cos
        x = x.cos()
        # Compute the Chebyshev interpolation
        y = torch.einsum(
            "bid,iod->bo", x, self.cheby_coeffs
        )  # shape = (batch_size, outdim)
        y = y.view(-1, self.outdim)
        if self.post_mul:
            mul_1 = y[:,::2]
            mul_2 = y[:,1::2]
            mul_res = mul_1 * mul_2
            y = torch.concat([y[:,:y.shape[1]//2], mul_res])
        return y



class ChebyKANLayer(nn.Module):
    def __init__(self, in_features, out_features, order):
        super().__init__()
        self.fc1 = ChebyKANLinear(
            in_features,
            out_features,
            order)

    def forward(self, x):
        B, N, C = x.shape
        x = self.fc1(x.reshape(B * N, C))
        x = x.reshape(B, N, -1).contiguous()
        return x



class BasicConv(nn.Module):
    def __init__(self, c_in, c_out, kernel_size, degree, stride=1, padding=0, dilation=1, groups=1, act=False, bn=False,
                 bias=False, dropout=0.):
        super(BasicConv, self).__init__()
        self.out_channels = c_out
        self.conv = nn.Conv1d(c_in, c_out, kernel_size=kernel_size, stride=stride, padding=kernel_size // 2,
                              dilation=dilation, groups=groups, bias=bias)
        self.bn = nn.BatchNorm1d(c_out) if bn else None
        self.act = nn.GELU() if act else None
        self.dropout = nn.Dropout(dropout)

    def forward(self, x):
        if self.bn is not None:
            x = self.bn(x)
        x = self.conv(x.transpose(-1, -2)).transpose(-1, -2)
        if self.act is not None:
            x = self.act(x)
        if self.dropout is not None:
            x = self.dropout(x)
        return x


class M_KAN(nn.Module):
    def __init__(self, d_model, seq_len, order):
        super().__init__()
        self.channel_mixer = nn.Sequential(
            ChebyKANLayer(d_model, d_model, order)
        )
        self.conv = BasicConv(d_model, d_model, kernel_size=3, degree=order, groups=d_model)

    def forward(self, x):
        x1 = self.channel_mixer(x)
        x2 = self.conv(x)
        out = x1 + x2
        return out


if __name__ == '__main__':
    batch_size = 16
    seq_len = 32
    d_model = 64
    order = 3

    block = M_KAN(d_model=d_model, seq_len=seq_len, order=order).to('cuda')

    input = torch.rand(batch_size, seq_len, d_model).to('cuda')

    output = block(input)

    print(f"Input size: {input.size()}")
    print(f"Output size: {output.size()}")


环境与依赖

Python 3.9+

继续浏览

下一篇MBRConv 多分支重参数化卷积多分支零开销:训练时并联 3×3、1×1、3×1、1×3 等卷积核,推理时融成一个卷积,部署零额外开销;模型从 75.243K 参数、17.447G FLOPs 降到 4.047K、0.924G,最高 1,100 FPS

相关资源