Take Part 1's 4 by 12 cliff grid. Every move gives −1, and a step into the cliff gives −100 and sends you back to the start S. This time you know all the rules before you move. So can you just work out the best way to the flag G?
Trying all rules, one move in each of the 37 cells, is hopeless. You'd rather take one rule and improve it, and for that you have to score it first. This side article to my reinforcement learning series follows Chapter 4 of Sutton and Barto, cited at the end.
How good is a random walker?
Start with a walker that picks moves at random. A rule like that is a policy , and a cell's value is the discounted sum of rewards you collect from there, on average. Scoring a policy is called policy evaluation, and since you know the rules, it comes down to a linear system.
Solving for the values
My script (linked under "Every round") solves the 37 equations directly. You can also sweep: start from any guess with the flag at 0, plug the current guesses into the right-hand side, and repeat.
For this converges to in the limit.
Act greedily on those numbers
What you'd expect from making a move once, then walking randomly again, is its action value. Pick the best move in every cell and you get the greedy policy , and switching to it is policy improvement.
The result looks silly. The walker rated the top-left corner a little above its neighbors, so ten cells now march into that corner and bump the top wall forever. Still, every cell's value beats the walker's.
Why greedy never hurts
Was that luck? No, and you can see why from S alone.
The ⇓ step on the board, from to in every cell, is the policy improvement theorem, and it takes one more idea: use the greedy move again at the next cell, and the next. After steps, all that's left of the old policy is its value steps ahead, times , which shrinks to zero.
The proof chain
Unroll one step at a time:
Here averages over following , and each uses that inequality at the next cell.
Repeat until nothing changes
Score the new policy, improve it again, and keep going. That's policy iteration, and here it takes six rounds. In round 6, S finds the 13-step route along the cliff edge, the same one Q-learning found in Part 1.
Out of policies, it scored six, plus the walker. It also has to stop. With the tie rule in the drawer, every round makes some cell strictly better, so no policy comes back.
Every round
| Round | v(S) | Moves changed | Cells improved |
|---|---|---|---|
| 0 (random) | −1072.24 | ||
| 1 | −100.00 | all 37 | 37 |
| 2 | −100.00 | 6 | 6 |
| 3 | −100.00 | 5 | 5 |
| 4 | −15.71 | 5 | 6 |
| 5 | −15.71 | 2 | 2 |
| 6 | −12.25 | 2 | 9 |
Round 1 breaks ties in the order up, right, down, left, and all 24 orders give the same numbers. After that, when two moves tie, the policy keeps its current move (one fix for the bug in the book's Exercise 4.4). Code: python3 scripts/rl_gpi_figures.py.
Evaluation can stop early
Policy iteration solves for the values exactly before every greedy step. Value iteration stops evaluating after one sweep, a single update of every cell from its neighbors' current values, and takes the greedy max inside it.
In general it reaches the optimal values only in the limit. The book says that evaluation "can be truncated in several ways without losing the convergence guarantees of policy iteration".
Two processes, one loop
So you can split the work between evaluation and improvement in many ways. The book calls any such mix generalized policy iteration (GPI): "letting policy-evaluation and policy-improvement processes interact, independent of the granularity and other details of the two processes".
The two processes "can be viewed as both competing and cooperating". Once evaluation scored round 1's policy, for example, that policy was no longer greedy in 6 cells. Then comes the big claim: "Almost all reinforcement learning methods are well described as GPI".
The same loop inside other methods
Without a model, methods estimate values from experience instead. Monte Carlo averages the returns of whole episodes, and temporal-difference (TD) methods move an estimate toward one reward plus the discounted next estimate.
In AlphaGo Zero, Monte Carlo tree search (MCTS) usually picks much stronger moves than the network's raw move probabilities would, so the paper calls it "a powerful policy improvement operator" and uses search and self-play "repeatedly in a policy iteration procedure". The book agrees that AlphaGo Zero "implemented a form of policy iteration". It never calls actor-critic GPI outright, though (notes under Sources).
What I take from it
In any new method, I now look for the two processes: what judges the policy, what improves it, and how much each does before it hands over. Most methods in the series differ in those three answers.
Sources
- Richard S. Sutton and Andrew G. Barto, Reinforcement Learning: An Introduction, 2nd edition, MIT Press, 2018. Chapters used: 4 (policy evaluation, policy improvement, policy iteration, value iteration and GPI, with the GPI loop in panel 6 drawn after the book's GPI diagrams), 3 (the Bellman optimality equation), 5 (Monte Carlo control), 6 (Sarsa and Q-learning), 13 and 14 (actor-critic), 16 (AlphaGo Zero) and 17 (GPI beside actor-critic).
- David Silver et al., Mastering the game of Go without human knowledge, Nature, 2017 (author version).
- Tuomas Haarnoja et al., Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor, ICML 2018.
Notes on the sources
- The book gives Q-learning its GPI label in the introduction and summary of Chapter 6, not in the Q-learning section.
- The book never calls actor-critic a form of GPI. The Chapter 6 summary calls it "a third way in which TD methods can be extended to control", and Chapter 17 lists GPI and actor-critic as separate ways to learn a policy. Haarnoja et al. are more direct: "Actor-critic algorithms are typically derived starting from policy iteration".