Shrink#
API#
- class warp_nn.modules.activations.Shrink( )[source]#
Bases:
ModuleShrink activation function.
This class computes the element-wise Shrink activation function:
\[\begin{split}\text{Shrink}(x) = \begin{cases} x + \text{bias}, & \text{ if } x < -\lambda\\ x - \text{bias}, & \text{ if } x > \lambda\\ 0, & \text{ otherwise} \end{cases}\end{split}\]where
\[\lambda = \text{lambd}\]PyTorch’s
Hardshrink(lambd)andSoftshrink(lambd)are equivalent toShrink(lambd=lambd, bias=0)andShrink(lambd=lambd, bias=lambd), respectively.- Parameters:
lambd – The lambda value (threshold) for the Shrink function.
bias – The bias value subtracted from (added to) the values above (below) the threshold.
requires_grad – Whether the cached output arrays of the module require gradients.
- __call__(
- input: array,
Forward pass of the activation function.
- Parameters:
input – The input array, with up to 3 dimensions.
- Returns:
The output array, with same shape as the input array.
- Raises:
TypeError – If the input array’s data type or number of dimensions is not supported.