fn
hardshrink
→Tensorhardshrink(x: Tensor, lambd: float = 0.5)Hard shrinkage operator.
Sets elements with magnitude below to zero, leaves larger-magnitude elements untouched. Standard tool for sparse coding and the proximal operator of the "pseudonorm" on a coefficient-by-coefficient basis.
Parameters
xTensorInput tensor.
lambdfloat= 0.5Threshold . Default
0.5.Returns
TensorShrunk tensor with the same shape as x.
Notes
Discontinuous at — for an everywhere-continuous
alternative use softshrink (the proximal operator of the
norm).
Examples
>>> import lucid
>>> from lucid.nn.functional import hardshrink
>>> x = lucid.tensor([-1.0, -0.3, 0.0, 0.3, 1.0])
>>> hardshrink(x, lambd=0.5)
Tensor([-1.0000, 0.0000, 0.0000, 0.0000, 1.0000])