All problems
Logistic Sigmoid
Problem
Compute the logistic sigmoid function: σ(z) = 1 / (1 + exp(-z)).
Handle large positive and negative z correctly (avoid overflow).
Hint
Branch on the sign of z to avoid exp() overflow.
Test cases
case 1
in: [0]
expected: 0.5
case 2
in: [100]
expected: 1
case 3
in: [-100]
expected: 0
case 4
in: [2]
expected: 0.8807970779778823
case 5
in: [-2]
expected: 0.11920292202211755
Starter codePython
import math
def sigmoid(z):
# Your code here
pass5 test cases · run your code against them in the editor