TropicalActivation将每个元素映射到固定斜率的多个可学习截距分支,取最大值后乘以阶数相关缩放,输入与输出形状一致。
输入 2×12×16输出 2×12×165 个参数 · degree=4,5 个可学习截距;元素级可学习激活。CPU 实跑,按 sum(p.numel() for p in model.parameters()) 统计。forward() 数据流顺序拆解 · 点击任意子模块方块可同步查看对应源码切片TropicalActivation将每个元素映射到固定斜率的多个可学习截距分支,取最大值后乘以阶数相关缩放,输入与输出形状一致。
695 def __init__(self, degree): 700 super(TropicalActivation, self).__init__()701 self.degree = degree 702 self.register_buffer('powers', torch.arange(0, degree + 1))703 self.coefficients = nn.Parameter(torch.ones(degree + 1)) 715 return math.sqrt(2) / self.degree * (x.unsqueeze(-1) * self.powers + self.coefficients).max(-1)[0]705 def forward(self, x):
x 为任意浮点张量;实跑输入 2×12×16。图中候选轴通过实际算子追踪获得,保持主类的多项式热带激活路径。
from OrthoTropicalActivation import TropicalActivation activation = TropicalActivation(degree=4) y = activation(x)
Method 动机参考:通过少量共享参数学习激活分段位置,保持元素级接入接口。
| 消融变体 | 结构配置 | 验证目的 |
|---|---|---|
| ReLU | 固定分段函数 | 建立基础激活对照 |
| degree=2 | 三个仿射候选 | 比较低阶容量 |
| degree=4 | 五个仿射候选 | 比较精度与额外计算量 |