Shortcuts

Softplus

class torch.nn.Softplus(beta=1.0, threshold=20.0)[源代码]

逐元素应用Softplus函数。

Softplus(x)=1βlog(1+exp(βx))\text{Softplus}(x) = \frac{1}{\beta} * \log(1 + \exp(\beta * x))

SoftPlus 是 ReLU 函数的平滑近似,可以用来约束机器的输出始终为正。

为了数值稳定性,当input×β>thresholdinput \times \beta > threshold时,实现会回退到线性函数。

Parameters
  • beta (float) – Softplus 公式的 β\beta 值。默认值:1

  • 阈值 (float) – 高于此值的数值将恢复为线性函数。默认值:20

Shape:
  • 输入:()(*),其中 * 表示任意数量的维度。

  • 输出: ()(*), 与输入形状相同。

../_images/Softplus.png

示例:

>>> m = nn.Softplus()
>>> input = torch.randn(2)
>>> output = m(input)