fn

softplus

Tensor
softplus(x: Tensor, beta: float = 1.0, threshold: float = 20.0)
source

Smooth approximation of relu.

Softplus is a strictly positive, CC^\infty smooth function that behaves like xx for large positive inputs and like exe^x 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

xTensor
Input tensor of any shape; activation is element-wise.
betafloat= 1.0
Sharpness parameter β>0\beta > 0. Larger beta makes the curve approach a hard ReLU. Default 1.0.
thresholdfloat= 20.0
For numerical stability the formula collapses to the identity xx whenever βx>threshold\beta x > \text{threshold} (the eβxe^{\beta x} term would otherwise overflow). Default 20.0.

Returns

Tensor

Activated tensor with the same shape as x, strictly positive.

Notes

softplusβ(x)=1βlog ⁣(1+eβx)\text{softplus}_\beta(x) = \frac{1}{\beta}\log\!\big(1 + e^{\beta x}\big)

Derivative is σ(βx)\sigma(\beta x). The overflow guard at threshold exploits that for large βx\beta x the function is indistinguishable from xx in finite precision. The engine's bare softplus kernel implements the special case β=1\beta = 1, threshold\text{threshold} \to \infty; 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])