Hardshrink

Contents

Hardshrink#

class brainstate.nn.Hardshrink(lambd=0.5)#

Applies the Hard Shrinkage (Hardshrink) function element-wise.

Hardshrink is defined as:

\[\begin{split}\text{HardShrink}(x) = \begin{cases} x, & \text{ if } x > \lambda \\ x, & \text{ if } x < -\lambda \\ 0, & \text{ otherwise } \end{cases}\end{split}\]
Parameters:
  • lambd (float) – The \(\lambda\) value for the Hardshrink formulation. Default: 0.5

  • Shape

  • -----

  • Input (-)

  • Output (-)

Examples

>>> import brainstate.nn as nn
>>> import brainstate
>>> m = nn.Hardshrink()
>>> x = brainstate.random.randn(2)
>>> output = m(x)