Back to topic
Optional
One Q-learning update
Apply Q(s,a) ← Q + α[r + γ max Q(s',·) − Q] on a 2×2 table; match the new value.
- Version
- v1
- Minutes
- ~20
- Evidence
- Self-check in the notebook
Until platform auto-check exists, compare cell output with the expected numbers in the notebook. This is not a debt and does not affect mastery.
Download the notebook and run it locally. Its environment requirements are listed inside.
Notebook contents
Readable on your phone. The code below has not been executed in the browser; download the notebook to run it.
Agents · Одно обновление Q-learning / One Q-learning update
Activity version: 1 · Seed: n/a · Данные: таблица , переход .
.
Ожидаемые числа (, , )
| Quantity | Value | Tolerance |
|---|---|---|
| new | abs ≤ 1e-12 |
Самопроверка в ноутбуке
Не влияет на mastery.
import numpy as np
Q = np.array([[0.0, 0.0], [0.0, 2.0]], dtype=float)
alpha, gamma = 0.5, 0.9
s, a, r, sp = 0, 1, 1.0, 1
td = r + gamma * Q[sp].max() - Q[s, a]
Q[s, a] = Q[s, a] + alpha * td
print("Q", Q)
assert abs(Q[0, 1] - 1.4) < 1e-12
assert Q[0, 0] == 0.0 and Q[1, 0] == 0.0 and Q[1, 1] == 2.0
print("OK: Q-learning one update")Самопроверка в ноутбуке
- после обновления
- остальные ячейки не изменились