Perfect! Let's trace through a single training step:
NETWORK:
Input: x equals 2.0
Weight: w equals 0.5 (random initial)
Target: y equals 4.0 (we want to learn times 2)
FORWARD PASS:
x equals 2.0
w equals 0.5
prediction equals x times w equals 1.0
target equals 4.0
loss equals (target minus prediction) squared equals 9.0
BACKWARD PASS (backpropagation):
Gradient of loss w.r.t. prediction equals minus 6.0.
Gradient of prediction w.r.t. weight equals 2.0.
Chain rule: d(loss) by d(weight) equals minus 12.0.
UPDATE WEIGHTS:
learning_rate equals 0.01
weight_update equals minus learning_rate times gradient equals 0.12
new_weight equals 0.62
AFTER ONE TRAINING STEP:
Old prediction: 1.0
New prediction: 1.24
Loss decreased: 9.0 to 7.66
After 100 steps, weight will approach 2.0 (the times 2 we wanted)!
THE BEAUTY: The network learns automatically from data, no hand-coding!
Want to see how this scales to deep networks with many layers?