神经网络常见激活函数 15-B-SiLU 函数

文章目录

B-SiLU (Bounded Sigmoid Linear Unit)

  • 论文

    https://arxiv.org/pdf/2505.22074

    结合了 SiLU 的自门控特性与可调下限参数,B-SiLU 通过 SUGAR(Surrogate Gradient for ReLU)方法用于解决 ReLU 的「死亡 ReLU 问题」,在前向传播中保持 ReLU 的稀疏性,而在反向传播中 作为 ReLU 的平滑导数替代函数。实验表明,SUGAR 结合 B-SiLU 在 CIFAR-10 和 CIFAR-100 数据集上显著提升了 VGG-16 和 ResNet-18 的测试准确率,分别提升 10-16 个百分点,优于其他替代函数(如 ELU、SELU、LeakyReLU 等。

  • 这篇中,作为ReLU的梯度替代,同时还有一个NELU被提出,但是感觉效果不太好,后续就不写了

函数+导函数

  • B-SiLU函数
    B - S i L U ( x ) = ( x + α ) ⋅ σ ( x ) − α 2 = x + α 1 + e − x − α 2 \begin{aligned} \mathrm{B\text{-}SiLU}(x) &= (x + \alpha) \cdot \sigma(x) - \frac{\alpha}{2} \\ &= \frac{x + \alpha}{1 + e^{-x}} - \frac{\alpha}{2} \end{aligned} B-SiLU(x)=(x+α)⋅σ(x)−2α=1+e−xx+α−2α

    α=0 时,B-SiLU 退化为 SiLU/Swish-1。

  • B-SiLU函数导数
    d d x B - S i L U ( x ) = [ ( x + α ) ⋅ σ ( x ) − α 2 ] ′ = σ ( x ) + ( x + α ) d d x σ ( x ) = σ ( x ) + ( x + α ) ⋅ σ ( x ) ( 1 − σ ( x ) ) \begin{aligned} \frac{d}{dx} \mathrm{B\text{-}SiLU}(x) &= \left[(x + \alpha)\cdot\sigma(x) - \frac{\alpha}{2}\right]' \\ &=\sigma(x) + (x+\alpha) \frac{d}{dx}\sigma(x)\\ &= \sigma(x) + (x + \alpha)\cdot\sigma(x)\bigl(1 - \sigma(x)\bigr) \end{aligned} dxdB-SiLU(x)=[(x+α)⋅σ(x)−2α]′=σ(x)+(x+α)dxdσ(x)=σ(x)+(x+α)⋅σ(x)(1−σ(x))

    其中 σ ( ⋅ ) \sigma(\cdot) σ(⋅) 为 Sigmoid 函数, α = 1.67 \alpha=1.67 α=1.67(论文建议值)。且
    d d x σ ( x ) = σ ( x ) ( 1 − σ ( x ) ) \frac{d}{dx}\sigma(x) = \sigma(x)(1-\sigma(x)) dxdσ(x)=σ(x)(1−σ(x))


函数和导函数图像

  • 画图

    python 复制代码
    import numpy as np
    from matplotlib import pyplot as plt
    
    def b_silu(x, alpha=1.67):
        return (x + alpha) / (1 + np.exp(-x)) - alpha / 2
    
    def b_silu_derivative(x, alpha=1.67):
        sig = 1 / (1 + np.exp(-x))
        return sig + (x + alpha) * sig * (1 - sig)
    
    x = np.linspace(-6, 6, 1000)
    y  = b_silu(x)
    y1 = b_silu_derivative(x)
    
    plt.figure(figsize=(12, 8))
    ax = plt.gca()
    plt.plot(x, y,  label='B-SiLU')
    plt.plot(x, y1, label='Derivative')
    plt.title('B-SiLU (α=1.67) and Derivative')
    
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.spines['bottom'].set_position(('data', 0))
    ax.yaxis.set_ticks_position('left')
    ax.spines['left'].set_position(('data', 0))
    
    plt.legend(loc=2)
    plt.savefig('./b_silu.jpg')
    plt.show()


优缺点

  • B-SiLU 的优点

    1. 有界输出:下限 − α / 2 -\alpha/2 −α/2、上限趋于 + ∞ +\infty +∞。
    2. 平滑可导:避免 ReLU 的"死亡"现象,反向传播更稳定。
    3. 非单调性:负区间小负值仍保留部分梯度,有利于信息流动。
    4. 兼容 ReLU:前向与 ReLU 近似,易于替换且无需大幅调参。
  • B-SiLU 的缺点

    1. 计算量略高:相比 ReLU 多了 sigmoid 运算。
    2. 超参数 α \alpha α:需要针对任务微调,通用性稍逊。
    3. 研究阶段:目前应用案例不如 ReLU/Swish 丰富。

PyTorch 中的 B-SiLU

  • 代码

    python 复制代码
    import torch
    import torch.nn.functional as F
    
    torch.manual_seed(1024)
    
    def b_silu(x, alpha=1.67):
        return (x + alpha) * torch.sigmoid(x) - alpha / 2
    
    x = torch.randn(3)
    y = b_silu(x)
    print("x:", x)
    print("B-SiLU(x):", y)

    输出示例

    复制代码
    x: tensor([-1.4837,  0.2671, -1.8337])
    B-SiLU(x): tensor([-0.8006,  0.2622, -0.8576])

TensorFlow 中的 B-SiLU

  • 代码

    python 复制代码
    import tensorflow as tf
    
    @tf.function
    def b_silu(x, alpha=1.67):
        return (x + alpha) * tf.nn.sigmoid(x) - alpha / 2
    
    x = tf.constant([-1.4837,  0.2671, -1.8337], dtype=tf.float32)
    y = b_silu(x)
    print("x:", x.numpy())
    print("B-SiLU(x):", y.numpy())

    输出示例

    复制代码
    x: [-1.4837  0.2671 -1.8337]
    B-SiLU(x): [-0.80055887  0.2621364  -0.85755754]

备注

  • 这篇论文发布于2025年5月,目前这个B-SiLU 在反向传播中 作为 ReLU 的平滑导数替代函数。所以暂时这里只关注
相关推荐
侃谈科技圈13 小时前
模型之外,声网定义了AI交互新标准
人工智能
weixin_5536544813 小时前
ChatGPT好用还是Gemini好用?
人工智能·chatgpt·大模型
阿文的代码库13 小时前
机器学习评价指标之转换化为二分类任务
人工智能·分类·数据挖掘
余衫马13 小时前
Microsoft Semantic Kernel 实战:使用内核参数实现一个简单的对话机器人
人工智能·microsoft·ai·agent·智能体
搞科研的小刘选手13 小时前
【大连市计算机学会主办】第三届图像处理、智能控制与计算机工程国际学术会议(IPICE 2026)
图像处理·人工智能·深度学习·算法·计算机·数据挖掘·智能控制
灰灰勇闯IT13 小时前
ops-softmax:Transformer 推理中的概率归一化引擎
人工智能·深度学习·transformer
翼龙云_cloud13 小时前
云代理商:Hermes Agent在量化交易中的实战应用
运维·服务器·人工智能·ai智能体·hermes agent
人月神话-Lee13 小时前
【图像处理】高斯模糊——最优雅的模糊算法
图像处理·人工智能·算法·ios·ai编程·swift
中科GIS地理信息培训13 小时前
【ArcGIS Pro 3.7新增功能2】新型高光谱图像工具:连续谱去除、PCA与 MNF 降低数据复杂性、使用波长直接计算、支持STAC等
人工智能·arcgis·目标跟踪
hughnz14 小时前
执行数字化建井计划——提升钻井过程自动化
人工智能·机器人