Skip to main content

11.3 Training and backpropagation

Source: Ideas from Computational Physics (Landau, Páez, Bordeianu), §11.2.3–11.2.5. Rewritten in original wording — no textbook SimpleNet.py dump. Continues 11.2b. Next: 11.3b.

Teach with known answers​

Figure 11.4 — forward → Loss → ∂ℒ → update.

Feed training pairs with known correct outputs y(c)y^{(c)}. Compare to predictions y(p)y^{(p)}. Define Loss, nudge weights with derivatives (backpropagation), then repeat. Pick MSE, the SGD step, and the logistic f′=f(1−f)f'=f(1-f) identity among lookalikes.

Finally evaluate on unseen data. Trained nets are efficient pattern engines but poor explainers: the parameter soup rarely narrates why a decision was made (hence the Blueprint quote in §11.1).

Meson-track toy​

Classify π\pi (11) vs μ\mu (00) from track length/width. Mean-center features (length mean 1414, width mean 88):

IDLength−14-14Width−8-8Label
A−1-1−2-211 (π\pi)
B222200 (μ\mu)
C111100
D−2-2−1-111

If the net always predicts 00, then L=0.5\mathcal{L}=0.5 on these four labels — right half the time by chance.

Gradients via the chain rule​

Extremize L\mathcal{L} in the weights/biases (six ww's and three bb's even in the tiny 2–2–1 net): seek ∂L/∂wi=0\partial\mathcal{L}/\partial w_i=0 and ∂L/∂bj=0\partial\mathcal{L}/\partial b_j=0. In practice, compute gradients and take the SGD steps you picked above.

Example (book walk-through style): one sample with x1=−2x_1=-2, x2=−1x_2=-1, y(c)=1y^{(c)}=1, all weights 11, biases 00:

h1=h2=f(−3)≈0.0474,y(p)=f(2h1)≈0.524.h_1=h_2=f(-3)\approx 0.0474,\qquad y^{(p)}=f(2h_1)\approx 0.524.

Then

∂L∂w1=∂L∂y(p)∂y(p)∂h1∂h1∂w1≈0.0215\frac{\partial\mathcal{L}}{\partial w_1} =\frac{\partial\mathcal{L}}{\partial y^{(p)}} \frac{\partial y^{(p)}}{\partial h_1} \frac{\partial h_1}{\partial w_1} \approx 0.0215

(positive ⇒ decrease w1w_1 to lower L\mathcal{L}). Sweep parameters one-at-a-time or in batches until L\mathcal{L} stalls.

Practice checklist​

  1. Implement MSE Loss; check L=0.5\mathcal{L}=0.5 for all-zero predictions on the four labels.
  2. Forward the all-ones-weight net on (x1,x2)=(−2,−1)(x_1,x_2)=(-2,-1); lock y(p)y^{(p)}.
  3. Compute f′(−3)f'(-3) and ∂L/∂w1\partial\mathcal{L}/\partial w_1; apply one SGD step and re-forward.
  4. (Open) Train a 2–2–1 net on all four tracks; try 3 hidden nodes or two hidden layers and compare final L\mathcal{L}.

Takeaway​

StepAction
ForwardPredict y(p)y^{(p)}
LossMSE vs y(c)y^{(c)}
BackwardChain-rule ∂L/∂w\partial\mathcal{L}/\partial w
Updatew←w−η ∂L/∂ww\leftarrow w-\eta\,\partial\mathcal{L}/\partial w
TestUnseen tracks / holdout
Quiz

Training / backprop

1 / 4

MSE Loss averages…

Pick an answer to see if you are right.

Next: 11.3b Training labs.