Machine learning building blocks
Logistic sigmoid
ml.sigmoidAlso called sigmoid, logistic, logistic function, expit
Maps a real number to (0, 1). It is the inverse of the logit and satisfies σ(−x) = 1 − σ(x).
Notation
input
x ∈ ℝ
Result: the probability
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
≈ 0.5
Given
Result
≈ 0.73105857863
Given
Result
≈ 0.119202922022
Given
Result
≈ 1
Common mistakes
Computes e× / (1 + e×)
The two exponentials overflow to inf for x above about 709, and inf / inf is NaN.
Fix: Use 1 / (1 + e−×) for x ≥ 0 and e× / (1 + e×) for x < 0, or call scipy.special.expit / torch.sigmoid.
Uses ex in the denominator
The result is 1 / (1 + e×) = σ(−x) = 1 − σ(x).
Fix: Negate the exponent: 1 / (1 + e−×).
Source
Goodfellow et al. 2016, §6.2.2.2
Goodfellow, Ian; Bengio, Yoshua; Courville, Aaron. Deep Learning. MIT Press, 2016.