class
LogSigmoid
extends
ModuleLogSigmoid()Log-Sigmoid activation function.
Applies element-wise:
The output is always . 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 .
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
→Tensorforward(x: Tensor)Apply the activation function element-wise.
Parameters
inputTensorInput tensor of arbitrary shape.
Returns
TensorOutput tensor of the same shape as input.