08 / 15 · 90–120 min
Learn to decide.
How does a reward change a policy?
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.
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 %
Read values as a table
| Held-out episode | Success | Moves | Return | Collisions |
|---|---|---|---|---|
| 1.00 | 1.00 | 14.00 | 0.48 | 0.00 |
| 2.00 | 1.00 | 13.00 | 0.52 | 0.00 |
| 3.00 | 1.00 | 12.00 | 0.56 | 0.00 |
| 4.00 | 1.00 | 8.00 | 0.72 | 0.00 |
| 5.00 | 1.00 | 8.00 | 0.72 | 0.00 |
| 6.00 | 1.00 | 7.00 | 0.76 | 0.00 |
| 7.00 | 1.00 | 8.00 | 0.72 | 0.00 |
| 8.00 | 1.00 | 12.00 | 0.56 | 1.00 |
| 9.00 | 1.00 | 6.00 | 0.80 | 0.00 |
| 10.00 | 1.00 | 1.00 | 1.00 | 0.00 |
| 11.00 | 1.00 | 13.00 | 0.52 | 1.00 |
| 12.00 | 1.00 | 8.00 | 0.72 | 0.00 |
| 13.00 | 1.00 | 2.00 | 0.96 | 0.00 |
| 14.00 | 1.00 | 15.00 | 0.44 | 0.00 |
| 15.00 | 1.00 | 1.00 | 1.00 | 0.00 |
| 16.00 | 1.00 | 18.00 | 0.32 | 0.00 |
| 17.00 | 1.00 | 4.00 | 0.88 | 0.00 |
| 18.00 | 1.00 | 9.00 | 0.68 | 0.00 |
| 19.00 | 1.00 | 3.00 | 0.92 | 0.00 |
| 20.00 | 1.00 | 8.00 | 0.72 | 0.00 |
| 21.00 | 1.00 | 4.00 | 0.88 | 0.00 |
| 22.00 | 1.00 | 12.00 | 0.56 | 0.00 |
| 23.00 | 1.00 | 3.00 | 0.92 | 0.00 |
| 24.00 | 1.00 | 8.00 | 0.72 | 0.00 |
| 25.00 | 1.00 | 8.00 | 0.72 | 0.00 |
| 26.00 | 1.00 | 9.00 | 0.68 | 0.00 |
| 27.00 | 1.00 | 9.00 | 0.68 | 0.00 |
| 28.00 | 1.00 | 7.00 | 0.76 | 0.00 |
| 29.00 | 1.00 | 8.00 | 0.72 | 1.00 |
| 30.00 | 1.00 | 17.00 | 0.36 | 0.00 |
| 31.00 | 1.00 | 1.00 | 1.00 | 0.00 |
| 32.00 | 1.00 | 6.00 | 0.80 | 0.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 updatesA 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.
atomsh / lab