本文给出了pytorch里面支持的所有二十几种激活函数的可视化作图。

文章目录


  1. Sigmoid
  2. LogSigmoid
  3. SoftSign
  4. HardSigmoid
  5. Tanh
  6. HardTanh
  7. ReLU
  8. ReLU6
  9. PReLU
  10. Leaky ReLU
  11. RReLU
  12. ELU
  13. CELU
  14. SELU
  15. GeLU
  16. SoftPlus
  17. Mish
  18. Silu
  19. HardSwish
  20. TanhShrink
  21. SoftShrink
  22. HardShrink

这里罗列了pytorch里面支持的所有二十几种激活函数,对每个激活函数及其梯度函数都作了图像,可以让大家更直观的了解激活函数的特性。

Sigmoid

$$ \text{Sigmoid}(x) = \sigma(x) = \frac{1}{1 + e^{-x}} $$
Sigmoid
图 1:Sigmoid 及其梯度

LogSigmoid

$$ \text{LogSigmoid}(x) = \log\left(\frac{ 1 }{ 1 + e^{-x}}\right) $$
LogSigmoid
图 2:LogSigmoid 及其梯度

SoftSign

$$ \text{SoftSign}(x) = \frac{x}{ 1 + |x|} $$
SoftSign
图 3:SoftSign 及其梯度

HardSigmoid

$$ \text{Hardsigmoid}(x) = \begin{cases} 0 & \text{if~} x \le -3, \\ 1 & \text{if~} x \ge +3, \\ x / 6 + 1 / 2 & \text{otherwise} \end{cases} $$
HardSigmoid
图 4:HardSigmoid 及其梯度

Tanh

$$ \text{Tanh}(x) = \tanh(x) = \frac{e^{x} - e^{-x}} {e^{x} + e^{-x}} $$
Tanh
图 5:Tanh 及其梯度

HardTanh

HardTanh
图 6:HardTanh 及其梯度

ReLU

$$ \text{ReLU}(x) = \max(0, x) $$
ReLU
图 7:ReLU 及其梯度

ReLU6

$$ \text{ReLU6}(x) = \min(\max(0,x), 6) $$
ReLU6
图 8:ReLU6 及其梯度

PReLU

$$ f(x)= \begin{cases} x, &x \gt 0\\ ax, & x \le 0 \end{cases} $$

$PReLU$的参数$a$在训练中学习得到。

PReLU
图 9:PReLU 及其梯度

Leaky ReLU

$$ \text{LeakyRELU}(x) = \begin{cases} x, & \text{ if } x \geq 0 \\ \alpha x, & \text{ otherwise } \end{cases} $$
LeakyReLU
图 10:LeakyReLU 及其梯度

RReLU

$$ \text{RReLU}(x) = \begin{cases} x & \text{if } x \geq 0 \\ ax & \text{ otherwise }, a \sim \mathcal{U}(\text{lower}, \text{upper}) \end{cases} $$

这里的参数$a$服从$(lower, upper)$间的均匀分布。

RReLU
图 11:RReLU 及其梯度

ELU

$$ f(x)= \begin{cases} x, &x \gt 0\\ \alpha(e^x - 1), & x \le 0 \end{cases} $$
ELU
图 12:ELU 及其梯度

CELU

$$ f(x)= \begin{cases} x, &x \gt 0\\ \alpha(e^{\frac{x}{\alpha}} - 1), & x \le 0 \end{cases} $$
CELU
图 13:CELU 及其梯度

SELU

$$ \text{SELU}(x) = \text{scale} * (\max(0,x) + \min(0, \alpha * (\exp(x) - 1))) $$
SELU
图 14:SELU 及其梯度

GeLU

$$ \text{GELU}(x) = x * \Phi(x), \Phi(x) \text{为高斯分布的累积分布函数} $$
GeLU
图 15:GeLU 及其梯度

SoftPlus

$$ \text{Softplus}(x) = \frac{1}{\beta} * \log(1 + e^{\beta * x}) $$
SoftPlus
图 16:SoftPlus 及其梯度

Mish

$$ \text{Mish}(x) = x * \text{Tanh}(\text{Softplus}(x)) $$
Mish
图 17:Mish 及其梯度

Silu

$$ \text{silu}(x) = x * \sigma(x), \text{where } \sigma(x) \text{ 为 sigmoid.} $$
Silu
图 18:Silu 及其梯度

HardSwish

$$ \text{Hardswish}(x) = \begin{cases} 0 & \text{if~} x \le -3, \\ x & \text{if~} x \ge +3, \\ x \cdot (x + 3) /6 & \text{otherwise} \end{cases} $$
HardSwish
图 19:HardSwish 及其梯度

TanhShrink

$$ \text{Tanhshrink}(x) = x - \tanh(x) $$
TanhShrink
图 20:TanhShrink 及其梯度

SoftShrink

$$ \text{SoftShrinkage}(x) = \begin{cases} x - \lambda, & \text{ if } x \gt \lambda \\ x + \lambda, & \text{ if } x \lt -\lambda \\ 0, & \text{ otherwise } \end{cases} $$
SoftShrink
图 21:SoftShrink 及其梯度

HardShrink

$$ \text{HardShrink}(x) = \begin{cases} x, & \text{ if } x \gt \lambda \\ x, & \text{ if } x \lt -\lambda \\ 0, & \text{ otherwise } \end{cases} $$
HardShrink
图 22:HardShrink 及其梯度

[本]通信工程@河海大学 & [硕]CS@清华大学
这个人很懒,他什么也没有写!

0
6358
0

更多推荐


2022年11月30日