Skip to content
fn

logsigmoid

→Tensor
logsigmoid(input: Tensor)

Numerically stable log⁡σ(x)\log \sigma(x).

Direct evaluation of log⁡(1/(1+e−x))\log(1 / (1 + e^{-x})) underflows once σ(x)\sigma(x) is below machine epsilon (around x≲−37x \lesssim -37 for float32). Rewriting as −softplus⁡(−x)-\operatorname{softplus}(-x) matches the same value while staying finite for arbitrarily negative inputs.

Parameters

inputTensor
Input logits.

Returns

Tensor

log⁡σ(x)\log \sigma(x) with the same shape as input, values in (−∞,0](-\infty, 0].

Notes

log⁡σ(x)=−log⁡(1+e−x)=−softplus⁡(−x)\log\sigma(x) = -\log(1 + e^{-x}) = -\operatorname{softplus}(-x)

Frequently the building block of binary cross-entropy with logits (BCE-with-logits) and of importance-weighting computations in RL.

Examples

>>> import lucid
>>> from lucid.nn.functional import logsigmoid
>>> x = lucid.tensor([-10.0, 0.0, 10.0])
>>> logsigmoid(x)
tensor([-10., -0.6931, -4.54e-05])

Used by 2