Back to topic
Optional
One Bellman backup for an MDP
Compute V'(s) = max_a Σ p(s'|s,a)[r + γV(s')] on a tiny MDP; match the table.
- Version
- v1
- Minutes
- ~25
- 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 · Один шаг Беллмана / One Bellman backup
Activity version: 1 · Seed: n/a · Данные: 2 состояния, 2 действия, .
.
Ожидаемые числа
| Quantity | Value | Tolerance |
|---|---|---|
| abs ≤ 1e-9 | ||
| abs ≤ 1e-9 | ||
| greedy | exact |
Самопроверка в ноутбуке
Не влияет на mastery.
import numpy as np
# states 0,1; actions 0,1
# From 0, action 0: det. to 0 with r=1
# From 0, action 1: det. to 1 with r=0
# From 1, any action: stay with r=0
P = np.zeros((2, 2, 2)) # s, a, s'
R = np.zeros((2, 2, 2))
P[0, 0, 0] = 1.0; R[0, 0, 0] = 1.0
P[0, 1, 1] = 1.0; R[0, 1, 1] = 0.0
P[1, 0, 1] = 1.0; R[1, 0, 1] = 0.0
P[1, 1, 1] = 1.0; R[1, 1, 1] = 0.0
V = np.array([1.0, 0.0])
gamma = 0.9
Q = np.sum(P * (R + gamma * V[None, None, :]), axis=2)
Vp = Q.max(axis=1)
a_star = Q.argmax(axis=1)
print("V'", Vp, "a*", a_star)
assert np.allclose(Vp, [1.9, 0.0], atol=1e-9)
assert a_star[0] == 0
print("OK: Bellman backup")Самопроверка в ноутбуке
- ,
- greedy действие в —