Sigmoid Derivative (Vectorized, Numerically Stable)
Difficulty: Medium · Concept: Activation Functions — Historical / Saturating Functions
Backpropagation through a sigmoid layer needs , not just . Sigmoid has an unusually clean derivative in terms of its own output: — no separate derivation needed once you already have .
Two things make this harder than Sigmoid Activation From Scratch: it operates on a list of values, not just one, and — unlike the original problem's moderate test range — it has to stay numerically correct at extreme magnitudes. Sigmoid Activation's solution notes that 1 / (1 + math.exp(-z)) overflows for z below roughly -709, since that requires computing math.exp(1e3)-scale numbers. This problem actually requires fixing that, not just mentioning it.
Your task: implement sigmoid_derivative(z_list), returning for every z in z_list. Must not raise OverflowError even for very large-magnitude inputs (e.g. -1000 or 1000).