Machine learning runs on numerical computation: iterative methods that update estimates rather than deriving symbolic solutions. The fundamental difficulty: infinitely many reals must live in finitely many bit patterns, so almost every number carries rounding error — and error compounds across operations, making theoretically correct algorithms fail in practice.
§4.1 Overflow and underflow
Underflow underflow Numbers near zero rounding to exactly zero — then division and log blow up (÷0, log 0 = −∞). defined in ch. 4 — open in glossary : numbers near zero round to exactly zero — and many functions change qualitatively at zero (division raises or returns NaN; log 0 = −∞, which becomes NaN downstream). Overflow overflow Large-magnitude numbers approximated as ±∞; further arithmetic turns them into NaN. defined in ch. 4 — open in glossary : large magnitudes become ±∞, and further arithmetic turns them into NaN.
The canonical function needing stabilization is the softmax softmax softmax(x)ᵢ = exp(xᵢ)/Σⱼexp(xⱼ): turns a real vector into multinoulli probabilities; stabilized by subtracting maxᵢxᵢ (shift-invariant). defined in ch. 4 — open in glossary , used to produce multinoulli probabilities:
Term by term
| exponentiate each score — the overflow/underflow hazard: e^{710} = ∞ and e^{−746} = 0 in float64 | positive | |
| the normalizer — if EVERY term underflows, this is 0 and we divide by zero | positive | |
| a probability; with all inputs equal to c, every output should be exactly 1/n regardless of c | (0,1), sums to 1 |
The fix exploits shift-invariance — adding a scalar to every input does not change the value: evaluate with . The largest argument to exp becomes 0 (no overflow) and the denominator contains a 1 (no divide-by-zero). Try to break both versions:
naive: exp(xᵢ)/Σexp(xⱼ)OK
| exp terms | [1.000, 2.718, 7.389] |
| denominator | 11.11 |
| softmax | [0.09003, 0.2447, 0.6652] |
fine at this scale — but drag c to either extreme…
stable: z = x − max(x) firstOK
| exp terms | [0.1353, 0.3679, 1.000] |
| denominator | 1.503 |
| softmax | [0.09003, 0.2447, 0.6652] |
largest argument to exp is 0, so no overflow; denominator ≥ 1, so no divide-by-zero. Same analytic value — softmax is shift-invariant.
these are real float64 computations happening in your browser, not a simulation
One residue remains: the numerator can still underflow, so naively taking can produce — log softmax needs its own stabilized routine (same trick). In practice, most readers lean on stable low-level libraries; Theano-style packages even detect and auto-stabilize common unstable expressions.
§4.2 Poor conditioning
Conditioning measures how rapidly a function’s output changes under small input perturbations — fast change means input rounding error becomes large output error. For :
Term by term
| ratio of largest to smallest eigenvalue magnitude — how unevenly A stretches space (§2.7’s ellipse, very elongated) | ratio ≥ 1 | |
| the condition number: large κ ⟹ inversion amplifies pre-existing input error — an INTRINSIC property of A, before any rounding in the inversion itself | scalar |
Worked example
has : an input error along the second axis is magnified 5× more by than one along the first. In the EigenLens, set λ₁ = 2.5, λ₂ = 0.5 — the elongated ellipse IS bad conditioning, and the same ratio returns as gradient descent’s nemesis in §4.3.1.
§4.3 Gradient-based optimization
Optimization: minimize (or maximize — just minimize ) an objective function objective function The function being minimized/maximized (= criterion; when minimized also called cost, loss, or error function); optimum written x* = arg min f(x). defined in ch. 4 — open in glossary , a.k.a. criterion — or, when minimized, cost / loss / error function (this book uses the terms interchangeably). The optimum gets a star: .
The derivative is the slope: — it tells us how to change to improve : for small . Stepping opposite the derivative is gradient descent gradient descent (Steepest descent, Cauchy 1847) iterate x′ = x − ε∇ₓf(x): small steps against the gradient until it (nearly) vanishes. defined in ch. 4 — open in glossary (Cauchy, 1847):
Fig 4.1 (recreated) — the derivative always points the way downhill.
Where , the derivative says nothing — critical (stationary) points critical point (Stationary point) where the derivative/gradient is zero: local minimum, local maximum, or saddle point. defined in ch. 4 — open in glossary , of three kinds:
Fig 4.2 (recreated) — zero slope can mean lower than all neighbors, higher than all neighbors, or ( saddle saddle point A critical point that is a minimum along some cross-sections and a maximum along others (Hessian has both signs of eigenvalues). defined in ch. 4 — open in glossary ) neighbors both higher AND lower.
Deep learning objectives have many suboptimal local minima and saddle points in flat regions, so we settle for finding very low — not provably minimal (fig 4.3’s landscape: a near-optimal local minimum is an acceptable halting point; a poor one should be avoided; the global one may be unreachable).
The multivariate case: which direction is downhill?
With inputs , partial derivatives assemble into the gradient gradient ∇ₓf(x): the vector of all partial derivatives; points directly uphill, so −∇f points directly downhill. defined in ch. 4 — open in glossary , and the slope along a unit vector is the directional derivative . The best direction falls out in three moves:
step 1/3: Find the unit direction with the most negative slope — the directional derivative comes from the chain rule on f(x + αu) at α = 0.
Term by term
| the uphill direction — negated to descend | n×1 | |
| the LEARNING RATE: a small constant, a value solved to zero the directional derivative, or the best of several tried (a LINE SEARCH) | scalar > 0 | |
| the proposed new point; iterate until every gradient element is (nearly) zero — or solve ∇f = 0 directly when possible | n×1 |
What this really says
Gradient descent is local greed: take the best infinitesimal step, repeatedly, with the learning rate learning rate ε: the positive scalar step size of gradient descent — constant, solved-for, or chosen by line search. defined in ch. 4 — open in glossary deciding how far to trust the local slope. The same repeated-small-improvement idea works in discrete spaces too, where it is called hill climbing. What the slope does NOT tell you is how it will change as you move — that is curvature, the subject of §4.3.1.
Check yourself — numerics and gradients
1.In the SoftmaxStabilizer you drag c to 800. Predict both pipelines.
2.Even after stabilizing softmax, why does log softmax need its OWN stabilized routine?
3.What does a large condition number of A tell you about solving with A⁻¹?
4.Why does the negative gradient point 'directly downhill'?
5.Why does deep learning 'settle' for a low—but not provably minimal—objective value?