class

LogSigmoid

extendsModule
LogSigmoid()
source

Log-Sigmoid activation function.

Applies element-wise:

LogSigmoid(x)=ln ⁣(σ(x))=ln ⁣(11+ex)=ln ⁣(1+ex)\text{LogSigmoid}(x) = \ln\!\left(\sigma(x)\right) = \ln\!\left(\frac{1}{1 + e^{-x}}\right) = -\ln\!\bigl(1 + e^{-x}\bigr)

The output is always 0\leq 0. Useful as a numerically stable log-probability output for binary models, or when computing negative log-likelihood loss without a separate sigmoid step.

Notes

  • Input: ()(*) — any shape.
  • Output: ()(*) — same shape as input, values in (,0](-\infty, 0].

The implementation fuses the log and sigmoid into a single engine call to avoid materialising the intermediate sigmoid tensor and to ensure numerical accuracy for large negative inputs.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.LogSigmoid()
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
>>> m(x)
tensor([-2.1269, -1.3133, -0.6931, -0.3133, -0.1269])
>>> # Log-probability output for binary classification
>>> x = lucid.randn(32, 1)
>>> log_probs = m(x)   # values in (-inf, 0]
>>> log_probs.shape
(32, 1)

Methods (1)

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.