class

Threshold

extendsModule
Threshold(threshold: float, value: float, inplace: bool = False)
source

Threshold activation function.

Applies element-wise:

Threshold(x)={xif x>thresholdvalueotherwise\text{Threshold}(x) = \begin{cases} x & \text{if } x > \text{threshold} \\ \text{value} & \text{otherwise} \end{cases}

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

thresholdfloat
The cut-off value. Elements strictly greater than this pass through unchanged.
valuefloat
The replacement constant for elements that do not exceed the threshold.
inplacebool= False
Accepted 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)
source

Initialise the Threshold module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Apply the activation function element-wise.

Parameters

inputTensor
Input tensor of arbitrary shape.

Returns

Tensor

Output tensor of the same shape as input.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.