Project 11 of 12, for Paul
Calculus for ML
Calculus for machine learning, on the hill in the park: slopes measured numerically, the gradient straight uphill, and the chain rule saying which way to turn the dials on the Archive's new thermometer, a model with two settings.
Sign up free to open itLog in
Act 5 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- PaulThe next floor up is mine, machine learning, and training a model is walking downhill. First, though, we need a hill.
- PaulThe park hill's a formula. How steep is the path, and which way is straight up from the gorse?
- YahyaAnd the Archive's new thermometer reads one and a half degrees low. Either that or the air's wrong, so it's the thermometer.
- PaulThey're all slopes, the three of them, so measure them and work out the ones you can.
hill_height(east, north) is the park hill's survey: its height in metres, at a point that many metres east and north of the park gate. The path runs due north from the gate to the top, and path_height(metres) gives its height that far along. Both are written.
Write four functions:
slope(f, x, step=1e-5): the slope of the functionfatx, measured a small step either side.partial_slopes(f, east, north, step=1e-5): the two slopes off(east, north), stepping east with north held still, then stepping north with east held still, as(east_slope, north_slope).uphill(f, east, north): the way straight uphill, as(bearing, steepness): the bearing of the arrow(east_slope, north_slope), from 0 up to 360, and its length.miss_slopes(gain, offset, reading, true): the thermometer's corrected reading isgain * reading + offset. Return the slopes of its squared miss,(gain * reading + offset - true) ** 2, forgainand foroffset, worked out with the chain rule.
Steepest on the path: 650 m from the gate, slope 0.243, about 1 in 4 At the top: slopes 0.000 east, 0.000 north From the gorse: straight uphill is 340 degrees, slope 0.212 Thermometer check (reads 8.5, should be 10.0): gain slope -25.5: turn the gain up offset slope -3.0: turn the offset up
What you learn
What's in it
- How steep, right here
- How steep, not how high
- The night the glass fell
- A step either side
- Two steps apart
- A slope for each way you face
- East, then north
- Straight uphill
- Uphill is west
- Rates multiply
- Inside and out
- Which way to turn the dials
- Reading high
- How Paul would do it
- Fix Riya's version
- Make the hill survey
- Ship it