fn
threshold
→Tensorthreshold(x: Tensor, threshold: float, value: float, inplace: bool = False)Threshold activation — gate elements by a scalar cutoff.
Replaces every element of x that is not strictly greater than
threshold with the constant value. A generalisation of
relu (recovered by threshold=0, value=0) and a common
component of dead-zone non-linearities.
Parameters
xTensorInput tensor.
thresholdfloatCutoff . Elements satisfying are kept.
valuefloatReplacement constant for elements not above the threshold.
inplacebool= FalseAccepted for API compatibility; currently ignored.
Returns
TensorThresholded tensor with the same shape as x.
Notes
Discontinuous at when ; the derivative
is above the threshold and below. Useful as a
deterministic alternative to relu when a non-zero "off"
value is needed (e.g. setting masked positions to a sentinel).
Examples
>>> import lucid
>>> from lucid.nn.functional import threshold
>>> x = lucid.tensor([-1.0, 0.0, 0.5, 1.0])
>>> threshold(x, threshold=0.5, value=-99.0)
Tensor([-99.0000, -99.0000, -99.0000, 1.0000])