Topics
Sigmoid function, also known as logistic function, maps any real-valued number to a value between 0 and 1.
Input . Output .
Properties:
- Function has an S-shaped curve
- Maps inputs to a probability-like range
- As ,
- As ,
import numpy as np
def sigmoid(z):
# Prevent overflow/underflow for large inputs
z = np.clip(z, -500, 500)
return 1 / (1 + np.exp(-z))
Role: Often used in neural networks or for estimating probabilities in classical machine learning algorithms such as logistic regression.
Derivative:
Numerical Stability: Computing can cause numerical issues (overflow or underflow) for very large or small . The exp-normalize trick or a stable sigmoid implementation helps. For example, compute for and for .
def sigmoid(z):
"Numerically stable sigmoid function."
if z >= 0:
return 1 / (1 + exp(-z))
else:
s = exp(z)
return s / (1 + s)