Hard Shrinkage activation function.
Applies element-wise:
Values within the band are zeroed out ("shrunk" to zero), while large values pass through unchanged. Hard shrinkage encourages sparse representations and is commonly used in sparse coding and wavelet-based signal processing.
Parameters
lambdfloat= 0.5Threshold . Default:
0.5.Notes
- Input: — any shape.
- Output: — same shape as input.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.Hardshrink(lambd=0.5)
>>> x = lucid.tensor([-1.0, -0.4, 0.0, 0.4, 1.0])
>>> m(x)
tensor([-1., 0., 0., 0., 1.])
>>> # Sparsifying activation for dictionary learning
>>> m = nn.Hardshrink(lambd=1.0)
>>> x = lucid.randn(8, 64)
>>> out = m(x)
>>> out.shape
(8, 64)