Play first

Open your browser console and have a friend think of a whole number between 1 and 100. You guess. After each guess they say only “higher” or “lower”. Play one round before reading on, and pay attention to what you actually do.

Most people go to 50 first. Told “higher”, they go to 75. Told “lower”, they go somewhere near 62. Nobody taught you this. You worked it out.

What is your strategy, exactly?

Try to write it down in one sentence before reading the next paragraph.

Here is one way to put it. You keep a current best guess. You make a prediction. You receive feedback about the direction of your error. You move your guess in that direction, by an amount related to how uncertain you still are. Then you repeat.

Compare that to the converter loop from the previous lesson:

const guess = miles * factor;
const error = km - guess;
factor = factor + 0.01 * error * miles;

Same shape. Predict, measure the error, move. You have been running a learning algorithm in your head since childhood.

One important difference

In the guessing game you are told only the direction: higher or lower. You are not told by how much. If you were told “you are 37 too low”, you could jump straight to the answer in one move.

The converter gets the richer kind of feedback. error carries both a direction (its sign) and a size (its magnitude). That is why the converter can take a large step when it is badly wrong and a small step when it is nearly right.

This distinction matters more than it looks. Nearly every method in this course depends on having feedback with both direction and size. When you meet a problem where you only get direction, or only get a final score at the very end, ordinary training stops working and you need different techniques.

Why halving is a good idea

Going to 50, then 75, then 62 halves the remaining range each time. Starting from 100 possibilities, you need at most 7 guesses. Guessing 1, 2, 3, 4 in order would need up to 100.

Notice what you traded. The stupid strategy moves by a fixed small amount every time. Your strategy moves by an amount that depends on how much uncertainty is left. Big steps early, small steps late.

Keep that in mind. When we get to learning rates in section 4, the central question will be exactly this: how big should each step be? Too small and you crawl. Too large and you overshoot past the answer and bounce around it forever.

Try this before the next lesson

  1. Play the game with a range of 1 to 1000. How many guesses did you need? Does it match the “at most 10” that halving predicts?
  2. Play deliberately badly: always move your guess by exactly 1 in the direction you are told. Count the guesses. This is what a learning rate that is too small feels like.
  3. Now always move by 40 in the direction you are told. Describe what goes wrong. This is what a learning rate that is too large feels like.