Skip to content
BIASED
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 .ipynb

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 · Данные: таблица Q∈R2×2Q\in\mathbb R^{2\times 2}, переход (s,a,r,s′)=(0,1,1.0,1)(s,a,r,s')=(0,1,1.0,1).

Q(s,a)←Q(s,a)+α[r+γmax⁡a′Q(s′,a′)−Q(s,a)]Q(s,a)\leftarrow Q(s,a)+\alpha\bigl[r+\gamma\max_{a'}Q(s',a')-Q(s,a)\bigr].

Ожидаемые числа (α=0.5\alpha=0.5, γ=0.9\gamma=0.9, Q(1,1)=2Q(1,1)=2)
Quantity Value Tolerance
new Q(0,1)Q(0,1) 1.41.4 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")
Самопроверка в ноутбуке
  • Q(0,1)=1.4Q(0,1)=1.4 после обновления
  • остальные ячейки не изменились