fn
softplus
→Tensorsoftplus(x: Tensor, beta: float = 1.0, threshold: float = 20.0)Smooth approximation of relu.
Softplus is a strictly positive, smooth function that
behaves like for large positive inputs and like
for large negative inputs. Its derivative is sigmoid, which is
why softplus appears naturally as the log-partition of a Bernoulli and
as the analytic primitive of the logistic function.
Parameters
xTensorInput tensor of any shape; activation is element-wise.
betafloat= 1.0Sharpness parameter . Larger
beta makes the
curve approach a hard ReLU. Default 1.0.thresholdfloat= 20.0For numerical stability the formula collapses to the identity
whenever (the
term would otherwise overflow). Default
20.0.Returns
TensorActivated tensor with the same shape as x, strictly positive.
Notes
Derivative is . The overflow guard at
threshold exploits that for large the function is
indistinguishable from in finite precision. The engine's
bare softplus kernel implements the special case
, ; when either
argument deviates the full formula is composed so autograd still
flows through the existing backward nodes.
Examples
>>> import lucid
>>> from lucid.nn.functional import softplus
>>> x = lucid.tensor([-2.0, 0.0, 2.0])
>>> softplus(x)
Tensor([0.1269, 0.6931, 2.1269])