fn

logit

Tensor
logit(x: Tensor, eps: float | None = ...)
source

Logit function — inverse of the logistic sigmoid.

Maps a probability in (0,1)(0, 1) to a log-odds value in R\mathbb{R}. Optionally clamps the input to [ϵ,1ϵ][\epsilon, 1 - \epsilon] first to avoid divergence at the boundaries.

Parameters

xTensor
Input tensor with values in (0,1)(0, 1).
epsfloat | None
If provided, x is clamped to [eps, 1 - eps] before the log-ratio is taken, preventing infinities. Defaults to None (no clamping).

Returns

Tensor

Element-wise logit value.

Notes

Mathematical definition:

logit(x)=log ⁣(x1x).\operatorname{logit}(x) = \log\!\Bigl(\tfrac{x}{1 - x}\Bigr).

Inverse of the sigmoid: logit(σ(z))=z\operatorname{logit}(\sigma(z)) = z. Without eps, inputs of exactly 0 or 1 produce -\infty and ++\infty respectively.

Examples

>>> import lucid
>>> x = lucid.tensor([0.1, 0.5, 0.9])
>>> lucid.logit(x)
Tensor([-2.1972,  0.    ,  2.1972])