Integrals: adding up thin slices
Why this matters
The derivative asked how fast something changes. The integral asks the reverse: given a rate, what's the total? A car's speed over an hour adds up to the distance it covered; a curve's heights, added over a stretch, give the area underneath. The method is the same idea as everything else in this module: cut the problem into thin slices, each easy, and add them up, with thinner slices giving a better answer. In ML, area turns up in two important places: the probability of a continuous value landing in a range is an area under a curve, and one of the most common scores for a classifier, the AUC, is literally an area under a curve.
- Estimate the area under a curve by cutting it into thin strips and adding them up
- Use trapezoids for a better estimate, and watch the answer settle as the strips get thinner
- Write a trapezoid sum in Python, plot the trapezoids' tops against the curve, and see that adding up differences undoes taking them
- Find a probability as an area under a bell curve, and an AUC score as an area under a ROC curve, in NumPy and with torch.trapezoid
The math: strips, added up
Purpose. A total from a rate, an area from a curve.
To find the area under f between x = a and x = b, cut the stretch into n strips of width Δx = (b − a)/n. Each strip is close to a rectangle, height f(x) and width Δx. Add them up:
In plain words: height times width for each thin strip, all added. It's lesson 26's Σ again.
For x² from 0 to 2 with 4 strips, using each strip's left edge for the height: 0.5 × (0 + 0.25 + 1 + 2.25) = 1.75. The true area is 8/3 ≈ 2.667, so left edges underestimate a rising curve.