Basis Lab

From a Straight Line to Backpropagation

When the Derivative Equations Stop Being Solvable

Last timeSolving It Exactly, Once

Put a squashing function after the line and the two equations that gave w = 3 and b = 2 cannot be solved. What survives is the slope at the point you are standing on.

The twelve measurements have an exact best line, reached by writing two

equations and solving them. The slope is 3, the offset is 2, the

total squared error is 12, and nothing about that answer was approximate.

It is worth being precise about why that worked, because the next model breaks

exactly one thing about it. The score was

$E(w,b)=650w2+156wb+12b2−4212w−516b+6846E(w, b) = 650w^2 + 156wb + 12b^2 - 4212w - 516b + 6846$

and each measurement's residual, the measurement minus the prediction, was

ri=yi−(wxi+b)r_i = y_i - (w x_i + b), so the amount by which the prediction overshot was

wxi+b−yiw x_i + b - y_i. Either way round, the unknowns appeared multiplied by known

numbers and nothing else. Differentiating a sum of squares of such things

gives a sum of terms each linear in the unknowns, and twelve linear terms

collapse into one by adding up the numbers in front. That collapse is the whole

trick. It is what turned twelve measurements into the two equations

650w+78b=2106650w + 78b = 2106 and 78w+12b=25878w + 12b = 258, and two linear equations in two

unknowns are solved by elimination.

A model that can bend

A straight line through these points leaves a total squared error of 12, which

is small, but a line cannot bend at all. The smallest change that lets the model

bend is to push the line through a squashing function and then stretch and shift

the result.

FIG 1The line, squashed, then stretched and shifted
The old straight line, now squeezed into the interval from minus one to one. This is the only new thing in the model and it is the thing that will cost the closed form.
An offset applied after the squashing, which the model needs because the squashed part can only reach from minus v to plus v.
The input, scaled to run from one twelfth to one. Without this the squashing function is flat at every measurement and its derivative is zero to eleven decimal places.
Four parameters now instead of two. The output weight v and the offset c sit outside the squashing function and the model is still linear in them. The slope w and the bias b sit inside it, and that is where the trouble is. Read the model on the measurement at x = 4 as follows: u is 4 divided by 12, which is one third, so the prediction is v times tanh of one third, plus c.

Fix the four parameters at v=20v = 20, w=1w = 1, b=0b = 0 and c=15c = 15 to have

something to compute with. On the measurement at x=4x = 4, where the recorded

value is y=15y = 15, the scaled input is u=4/12=1/3u = 4/12 = 1/3 and the squashing

function is needed at 1/31/3. By its definition in terms of exponentials,

$$\tanh\left(\tfrac{1}{3}\right) = \frac{e^{2/3} - 1}{e^{2/3} + 1}

= \frac{1.9477340 - 1}{1.9477340 + 1} = \frac{0.9477340}{2.9477340}

= 0.32151274$$

so the prediction is 20×0.32151274+15=6.4302548+15=21.43025520 \times 0.32151274 + 15 = 6.4302548 + 15 = 21.430255.

The prediction is too high by 21.430255−15=6.43025521.430255 - 15 = 6.430255, and the square of

that gap, which is this measurement's contribution to the total, is

41.34817641.348176.

Across all twelve measurements those contributions add to 552.55552.55, against the

straight line's 12. The bent model has been handed four parameters and is

currently far worse than the two parameter line, because these four numbers

were chosen for convenient arithmetic rather than for fit. The question is how

to improve them.

The lesson stops here

4 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Measuring How Wrong a Straight Line Is, on Twelve Points
  2. 02The Two Equations That Pin Down the Best Lineopening only
  3. 03When the Derivative Equations Stop Being Solvableyou are here
  4. 04The Largest Step This Data Allowsopening only
  5. 05Putting a Bend in the Model, and Differentiating Through Itopening only
  6. 06Every Derivative of a Two Unit Network, by Handopening only
  7. 07One Sweep Back Instead of Seven Chainsopening only
  8. 08Running It, and Reading the Curve It Producesopening only

Read alongside