Skip to main content
Open In Colab The Recycling Robot section described a two-state robot, wrote down its Bellman optimality equations, and solved them by evaluating all six of its deterministic policies. Checking every policy works only because the robot is tiny: a problem with ∣S∣|\mathcal S| states and ∣A∣|\mathcal A| actions has ∣A∣∣S∣|\mathcal A|^{|\mathcal S|} deterministic policies. This section solves the same robot with value iteration, which needs no enumeration. The dynamics, rewards and parameters (α=0.8\alpha = 0.8, β=0.4\beta = 0.4, rsearch=2r_{\text{search}} = 2, rwait=1r_{\text{wait}} = 1, γ=0.9\gamma = 0.9) are the ones in that section. Value iteration starts from v0=0v_0 = 0 and applies the optimality backup to every state in each sweep: vk+1(s)=max⁡a∑s′p(s′∣s,a)[r+γ vk(s′)].v_{k+1}(s) = \max_a \sum_{s'} p(s' \mid s, a) \left[ r + \gamma\, v_k(s') \right]. One sweep does for every state what one level of the lookahead tree in the Recycling Robot section does for the root, but each state is computed once and its value reused, instead of once per tree node.
The sweep function computes the action values of every state from the same vkv_k and keeps the largest one. The loop stops when no value changes by more than 10−810^{-8}. The values reach v∗=(16.949,15.254)v_* = (16.949, 15.254), the solution found in the Recycling Robot section by checking every policy. Output from cell 3 Left: the two state values approach v∗v_* (dashed lines). Right: the largest error shrinks by about a factor of γ=0.9\gamma = 0.9 per sweep, so it falls on a straight line on the log scale. The error shrinks by a factor of γ\gamma per sweep because the optimality backup is a contraction: it brings any two value functions at least a factor γ\gamma closer in the largest state difference. With γ=0.9\gamma = 0.9 that is slow, and the loop needs 181 sweeps to reach 10−810^{-8}. The greedy policy settles much sooner than the values. After one and two sweeps the low state prefers to wait, because with so few steps left the benefit of recharging is out of reach. From the third sweep on, the greedy policy is search in high and recharge in low, the optimal policy, while the values still have far to go. The greedy policy is already optimal once vkv_k is close enough to v∗v_* to rank the actions in every state correctly, which here happens after three sweeps. Key references: (Sutton & Barto, 2018)

References

  • Sutton, R., Barto, A. (2018). Reinforcement Learning: An Introduction. Link

Found an error on this page? Report an issue.