class
Threshold
extends
ModuleThreshold(threshold: float, value: float, inplace: bool = False)Threshold activation function.
Applies element-wise:
Values that fall at or below the threshold are replaced with a constant
value. This generalises the standard ReLU (threshold=0, value=0) to
arbitrary cut-off points and fill values.
Parameters
thresholdfloatThe cut-off value. Elements strictly greater than this pass through
unchanged.
valuefloatThe replacement constant for elements that do not exceed the threshold.
inplacebool= FalseAccepted for API compatibility; currently unused. Default:
False.Notes
- Input: — any shape.
- Output: — same shape as input.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.Threshold(threshold=1.0, value=-1.0)
>>> x = lucid.tensor([0.5, 1.0, 1.5, 2.0])
>>> m(x)
tensor([-1. , -1. , 1.5, 2. ])
>>> # Use as a generalised ReLU with a non-zero floor
>>> m = nn.Threshold(threshold=0.0, value=0.0)
>>> x = lucid.randn(8, 32)
>>> out = m(x)
>>> out.shape
(8, 32)Methods (3)
dunder
__init__
→None__init__(threshold: float, value: float, inplace: bool = False)Initialise the Threshold module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Apply the activation function element-wise.
Parameters
inputTensorInput tensor of arbitrary shape.
Returns
TensorOutput tensor of the same shape as input.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.