Thomas Piacentini
← Workshop

07 / 15 · 60–90 min

Follow the gradient.

How can derivatives calibrate a sensor?

Choose a laboratory
Check my intuition

01 · Predict

Before changing the settings.

The loss is L(w) = ½w², so its derivative is w. Starting at w = 2, what value follows one gradient step with α = 0.1 and no momentum?

A hint

w_new = w − α × gradient

02 · Experiment and compare

Put the model to the test.

Compare both curves at β = 0 and then 0.8. Increase the step until oscillation or divergence appears. Repeat with centred data: the problem conditioning changes.

-2.80-225-1.250-0.4750.4100log₁₀(loss)Iteration
Dashed: plain gradient. Solid: momentum. The vertical axis is logarithmic.

Target: gain 1.4; bias −0.8. Estimate: (1.309 ; -0.603).

Plain gradient loss
0.03
Momentum loss
1.63E-3
Calibrated gain
1.31
Compare A and B →

Read values as a table
IterationGainBiasLoss
0.000.000.002.36
1.000.230.101.30
2.000.570.250.31
3.000.930.400.07
4.001.190.510.41
5.001.320.560.71
6.001.300.530.64
7.001.180.450.33
8.001.000.350.09
9.000.830.250.06
10.000.720.180.16
11.000.670.140.23
12.000.710.130.19
13.000.790.150.11
14.000.900.170.05
15.000.990.200.05
16.001.060.210.07
17.001.090.200.09
18.001.080.170.07
19.001.040.140.05
20.001.000.100.03
21.000.960.060.04
22.000.940.030.04
23.000.940.010.04
24.000.962.26E-30.04
25.000.99-2.08E-30.03
26.001.03-4.79E-30.03
27.001.06-9.43E-30.03
28.001.07-0.020.03
29.001.08-0.030.03
30.001.08-0.050.03
31.001.08-0.070.02
32.001.07-0.090.02
33.001.06-0.110.02
34.001.06-0.120.02
35.001.07-0.140.02
36.001.08-0.150.02
37.001.09-0.160.02
38.001.11-0.160.02
39.001.12-0.170.02
40.001.12-0.180.02
41.001.13-0.200.02
42.001.13-0.210.01
43.001.13-0.220.01
44.001.13-0.230.01
45.001.14-0.250.01
46.001.14-0.260.01
47.001.15-0.270.01
48.001.15-0.280.01
49.001.16-0.280.01
50.001.17-0.290.01
51.001.17-0.300.01
52.001.18-0.310.01
53.001.18-0.329.64E-3
54.001.18-0.339.28E-3
55.001.19-0.348.93E-3
56.001.19-0.358.60E-3
57.001.19-0.368.28E-3
58.001.20-0.377.97E-3
59.001.20-0.377.68E-3
60.001.20-0.387.39E-3
61.001.21-0.397.11E-3
62.001.21-0.406.85E-3
63.001.22-0.406.60E-3
64.001.22-0.416.35E-3
65.001.22-0.426.12E-3
66.001.23-0.435.89E-3
67.001.23-0.435.67E-3
68.001.23-0.445.46E-3
69.001.24-0.455.26E-3
70.001.24-0.455.06E-3
71.001.24-0.464.87E-3
72.001.24-0.474.69E-3
73.001.25-0.474.52E-3
74.001.25-0.484.35E-3
75.001.25-0.484.19E-3
76.001.26-0.494.03E-3
77.001.26-0.503.88E-3
78.001.26-0.503.74E-3
79.001.26-0.513.60E-3
80.001.27-0.513.47E-3
81.001.27-0.523.34E-3
82.001.27-0.523.21E-3
83.001.27-0.533.10E-3
84.001.28-0.532.98E-3
85.001.28-0.542.87E-3
86.001.28-0.542.76E-3
87.001.28-0.552.66E-3
88.001.29-0.552.56E-3
89.001.29-0.562.47E-3
90.001.29-0.562.38E-3
91.001.29-0.572.29E-3
92.001.29-0.572.20E-3
93.001.30-0.582.12E-3
94.001.30-0.582.04E-3
95.001.30-0.581.97E-3
96.001.30-0.591.89E-3
97.001.30-0.591.82E-3
98.001.30-0.601.76E-3
99.001.31-0.601.69E-3
100.001.31-0.601.63E-3
Understand the calculations

03 · Connect the diagram to calculations

The numbers behind motion.

We calibrate ẑ = ax + b on 21 noiseless measurements generated by a = 1.4 and b = −0.8. The chain rule connects loss to each parameter: error → prediction → gain or bias. Momentum accumulates gradients. Both optimizers start at (0, 0) and see the same data. The plot shows log₁₀ loss with a display floor of 10⁻⁹.

L = mean((a x + b − z)²) / 2
∂L/∂a = mean(error × x) ; ∂L/∂b = mean(error)
vₖ₊₁ = βvₖ + ∇L(wₖ)
wₖ₊₁ = wₖ − αvₖ₊₁
A few lines to reconstruct
gradient = [mean(error * x), mean(error)]
velocity = beta * velocity + gradient
weights = weights - rate * velocity

The notebook provides one function per laboratory, hand-calculated examples and tests. Exercises isolate components; these pages run the complete simulations.

Keep an observation

04 · Record

What changed?

Compare two settings. Record the effect, your explanation and a case where the model might fail. Saving keeps the current settings and seed, not a certification of competence.

Open my notebook →

atomsh / lab