评价此页

Softshrink#

class torch.nn.Softshrink(lambd=0.5)[source]#

Element-wise apply the soft shrinkage function.

SoftShrinkage(x)={xλ, if x>λx+λ, if x<λ0, otherwise \text{SoftShrinkage}(x) = \begin{cases} x - \lambda, & \text{ if } x > \lambda \\ x + \lambda, & \text{ if } x < -\lambda \\ 0, & \text{ otherwise } \end{cases}
参数

lambd (float) – The λ\lambda value for the Softshrink formulation. (Must be no less than zero). Default: 0.5

形状
  • Input: ()(*), where * means any number of dimensions.

  • Output: ()(*), same shape as the input.

../_images/Softshrink.png

示例

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