hard_shrink

Contents

hard_shrink#

class brainstate.nn.hard_shrink(x, lambd=0.5)[source]#

Hard shrinkage activation function.

Applies the hard shrinkage function element-wise:

\[\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:
  • x (ArrayLike) – Input array of any shape.

  • lambd (float, optional) – The \(\lambda\) threshold value for the hard shrinkage formulation. Default is 0.5.

Returns:

Output array with the same shape as the input.

Return type:

jax.Array or Quantity