0%

激活函数

激活函数

输入图片说明

Linear Activation

f(x)=xf(x) = x

ReLU

f(x)=max(0,x)f(x) = \max(0,\, x)

隐藏层中最常用,计算高效,缓解梯度消失

Sigmoid

f(x)=11+exf(x) = \frac{1}{1+\mathrm{e}^{-x}}

二分类输出层,输出概率值

Tanh

f(x)=tanh(x)=exexex+exf(x) = \tanh(x) = \frac{\mathrm{e}^{x}-\mathrm{e}^{-x}}{\mathrm{e}^{x}+\mathrm{e}^{-x}}

RNN 隐藏层,输出范围 [-1, 1],零中心化

Leaky ReLU

f(x) = \begin{cases} x, & x\ge 0\\[4pt] \alpha x, & x<0 \end{cases} \quad (\alpha\in(0,1))

深层网络中替代 ReLU,提升训练稳定性

Softplus

f(x)=ln(1+ex)f(x) = \ln\!\bigl(1+\mathrm{e}^{x}\bigr)

ReLU 的平滑近似,用于需要平滑激活的场景,如概率模型

ELU

f(x)= \begin{cases} x, & x\ge 0\\[4pt] \alpha\,(\mathrm{e}^{x}-1), & x<0 \end{cases}

加速收敛,输出均值接近 0,适合深层网络

SELU

f(x)=\lambda \begin{cases} x, & x\ge 0\\[4pt] \alpha\,(\mathrm{e}^{x}-1), & x<0 \end{cases}

类似 ELU,但斜率更大,自归一化网络中,保持层间分布稳定
其中 λ1.050 7\lambda\approx 1.050\ 7α1.673 3\alpha\approx 1.673\ 3

Swish

f(x)=x\cdot\sigma(\beta x)=x\cdot\frac{1}{1+\mathrm{e}^{-\beta x}} \quad (\beta=1 时称为 SiLU)

深度模型中性能优于 ReLU,如 EfficientNet

GELU

f(x)=xΦ(x)=x2[1+erf(x2)]f(x)=x\cdot\Phi(x)=\frac{x}{2}\left[1+\mathrm{erf}\!\left(\frac{x}{\sqrt{2}}\right)\right]

类似 Swish,但更平滑,Transformer、BERT、GPT 等模型中广泛使用

激活函数 非线性 输出范围 常用于 特点
Linear (-∞, ∞) 回归输出 简单
ReLU [0, ∞) 隐藏层 快速、稀疏
Sigmoid (0, 1) 二分类输出 易饱和
Tanh (-1, 1) RNN 零中心化
LeakyReLU (-∞, ∞) 隐藏层 解决死神经元
Softplus (0, ∞) 平滑 ReLU 可导
ELU (-α, ∞) 深层网络 加速收敛
SELU 类似 ELU 自归一化网络 自动归一化
Swish (-∞, ∞) 深层模型 非单调
GELU (-∞, ∞) Transformer 高斯加权
-------------本文结束感谢您的阅读-------------