← Back to the track

Learn machine learning · part 4 · session 3

Slope without calculus

Two points close together and one division. That is the whole of it, and this session checks your numbers against the symbolic derivative afterwards.

After this session you will be able to measure the slope of a curve with arithmetic alone, and say from its sign which way reduces the loss.

slope.numericSession 4.3About 30 minutesYour check: demonstrate the idea yourself

To pass: name the direction that reduces L at three marked points on the same curve, three of three.

01 · The question

People stop here, at the word calculus, and there is no need. To walk downhill you need one thing: which way is down, and how steeply. You can get both by measuring the curve at two points very close together and dividing the rise by the run. It is arithmetic, and the number it gives you is the .

The curve on this page is written out in full so nothing is hidden. Compute the slope at three points by hand. The textbook formula appears once all three slopes are entered, so you can check your arithmetic against it.

The curve, in full

L(w) is (w - 2) squared, plus 1. Written L(w) = (w - 2) ** 2 + 1 the way code writes it.

Minimum at w = 2, where L = 1.

Two ways to measure. Take a step to the right and compare: that is the forward difference, (L(w + h) - L(w)) / h. Take a step each way and compare those: that is the central difference, (L(w + h) - L(w - h)) / (2 * h), and it is the better one.

02 · Predict

This is a guess. You will measure it in a minute.

Before anything runs

You measure the slope of this curve at w = 0 from two points 0.01 either side of it. How close will that estimate be to the true slope?

You measure the slope of this curve at w = 0 from two points 0.01 either side of it. How close will that estimate be to the true slope?

Choose something first.

03 · Try it

Evaluate the curve

To four decimals.

Attempts: 0

Move the probe

Which way is down

illustrativethe 4.3 curve and its slope

Standing on the left wall at w = 0, with a level laid on the ground.

The slope is the tilt of the ground under your feet, and its sign is the direction of downhill.

The probe is a slider over w, and the step size h is four buttons. Nothing here animates: the chord redraws as you move.

-2.00 to 6.00
h, the step size

w = 0.00, h = 0.010, slope -4.0000. The chord falls from left to right.

computed in this browsertwo evaluations and a division

slope -4.0000

w runs -2 to 6 left to right and L runs 0 to 18 bottom to top. The dashed upright marks w = 2, where the curve bottoms out at L = 1. The solid chord is the central difference through the two probe points, drawn out to plus and minus 1.4 in w so its slope is visible; at h = 0.01 the two probe points themselves are a pixel apart.

Does increasing w raise or lower L here?

Three slopes, by hand

To four decimals.

Attempts: 0

To four decimals.

Attempts: 0

To four decimals.

Attempts: 0

The textbook formula appears once all three slopes are entered, so you can check your arithmetic against it. Showing it first would turn the arithmetic into a copying exercise.

Break the estimate

The same two quotients at w = 0.00 across three step sizes. The whole table fills at once.

At w = 0.00 the central difference reads -4.0000 at every step size, while the forward difference moves from -3.0000 at h = 1 to -3.9990 at h = 0.001. The symbolic value is -4.0000.

Show the comparison
Values shown in the figure above
whcentralforwardsymbolic
0.001.000-4.0000-3.0000-4.0000
0.000.010-4.0000-3.9900-4.0000
0.000.001-4.0000-3.9990-4.0000

Central difference is exact on this curve because the curvature errors on the two sides cancel. On a curve that is not a quadratic it is close, not exact, and this is the check that will verify every in 5.4.

04 · Compare

Call the three directions in the gate below and the verdict lands here.

05 · Check your understanding

Your check: an outcome you produce

not yet

Three of three: at each marked point, the direction that reduces L. Use the probe to compute each slope first if you want to; that is the intended route.

Not met yet. Keep working the session.

Three marked points on the same curve

At w = -1.5, which direction reduces L?
At w = 4, which direction reduces L?
At w = 1.25, which direction reduces L?

Call all three first.

Ask for a hint

Rungs open as you run the session, not as time passes. You have run it 0 times.

1. A question: available after 3 evaluated runs.

2. A narrowing: available after 5 evaluated runs.

3. A worked fragment, on a different curve: available after 7 evaluated runs.

4. The answer: available after 9 evaluated runs.

Save your takeaway

Your takeaway

Edit it into your own words, or keep the line as it is.

This session puts nothing on the shelf. It is the concept 4.4 needs, and 4.4 produces the trace.