Thomas Piacentini
← Workshop

08 / 15 · 90–120 min

Learn to decide.

How does a reward change a policy?

Choose a laboratory
Check my intuition

01 · Predict

Before changing the settings.

Q is 0. Reward is 1, γ = 0.9 and the best next value is 2. With α = 0.5, what Q value follows one nonterminal update?

A hint

The target is 1 + 0.9 × 2. Move halfway towards it.

02 · Experiment and compare

Put the model to the test.

Start with 20 episodes and then increase the count. Compare success with a random policy and A*. Vary exploration and imprecise actions; evaluation uses a frozen policy.

S↓↓×→→→↓→↓↓×↓→→↓→→↓×↓→→↓××↓→↓××↓→↓↓×→↓→↓→→↓×↓↓↓↓→→↓×↓→↓↓→→→→→→→GS: start · G: goal · ×: obstacle · 3: terrain cost
Arrows: learned policy. Tinted path: first held-out trial, from S to G.

32 evaluation episodes without exploration or Q updates, using draws separate from training. Arrows show the greedy policy; the path is the first episode.

Q-learning success
100.00 %
Random success
28.13 %
A* success
100.00 %
Compare A and B →

Read values as a table
Held-out episodeSuccessMovesReturnCollisions
1.001.0014.000.480.00
2.001.0013.000.520.00
3.001.0012.000.560.00
4.001.008.000.720.00
5.001.008.000.720.00
6.001.007.000.760.00
7.001.008.000.720.00
8.001.0012.000.561.00
9.001.006.000.800.00
10.001.001.001.000.00
11.001.0013.000.521.00
12.001.008.000.720.00
13.001.002.000.960.00
14.001.0015.000.440.00
15.001.001.001.000.00
16.001.0018.000.320.00
17.001.004.000.880.00
18.001.009.000.680.00
19.001.003.000.920.00
20.001.008.000.720.00
21.001.004.000.880.00
22.001.0012.000.560.00
23.001.003.000.920.00
24.001.008.000.720.00
25.001.008.000.720.00
26.001.009.000.680.00
27.001.009.000.680.00
28.001.007.000.760.00
29.001.008.000.721.00
30.001.0017.000.360.00
31.001.001.001.000.00
32.001.006.000.800.00
Understand the calculations

03 · Connect the diagram to calculations

The numbers behind motion.

The robot observes its exact cell and chooses one of four actions. An action may be randomly replaced according to the imprecision setting. Reaching the goal earns +1; other steps cost −0.04 times the entered cell terrain. A wall leaves the robot in place. Episodes last at most 128 actions. Q-learning learns from trials; A* receives the map and replans at each step. The methods therefore do not start with the same information.

Q(s,a) ← Q(s,a) + α [r + γ max_b Q(s′,b) − Q(s,a)]
terminal: target = r
training: ε-greedy ; evaluation: greedy, no updates
A few lines to reconstruct
target = reward if terminal else reward + gamma * max(Q[next_state])
Q[state][action] += alpha * (target - Q[state][action])

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