fn
hardsigmoid
→Tensorhardsigmoid(x: Tensor)Hard sigmoid — piecewise linear approximation of sigmoid.
Avoids the cost of an exponential by clipping a scaled-and-shifted identity to . Widely used as the gating function inside quantised mobile networks (MobileNetV3 Squeeze-and-Excitation blocks).
Parameters
xTensorInput tensor of any shape; activation is element-wise.
Returns
TensorActivated tensor with the same shape as x, values in
.
Notes
Matches sigmoid exactly at (both return 0.5)
but is only piecewise-linear. Derivative is in the linear
region and in the saturated regions.
Examples
>>> import lucid
>>> from lucid.nn.functional import hardsigmoid
>>> x = lucid.tensor([-4.0, -1.0, 0.0, 1.0, 4.0])
>>> hardsigmoid(x)
Tensor([0.0000, 0.3333, 0.5000, 0.6667, 1.0000])