Skip to main content
Open In Colab This section runs SARSA on the windy gridworld of Sutton and Barto, Example 6.5 (Sutton & Barto, 2018): a small gridworld with a wind that pushes the agent upward in the middle of the grid.

The windy gridworld

The grid has 7 rows and 10 columns. Every episode starts in S, in the fourth row of the first column, and ends when the agent reaches the goal G, in the same row of the eighth column. The actions are the four moves up, down, left and right. In columns 4 to 9 a wind blows upward: after each move, the wind pushes the agent up by the strength of the column it left, 1 or 2 cells. Moves off the grid stop at the edge. Every step has reward −1-1 and γ=1\gamma = 1, so the return of an episode is minus its number of steps. Monte Carlo control is a poor fit for this task. Some policies never reach the goal, for example one that keeps walking into the top edge of the grid, and an episode under such a policy never ends, so Monte Carlo never gets a return to learn from. SARSA learns during the episode. Each step that goes nowhere lowers the value of the action that caused it, and the ϵ\epsilon-greedy policy soon picks another action.
The agent is tabular SARSA with α=0.5\alpha = 0.5, ϵ=0.1\epsilon = 0.1 and QQ initialized to 0, the settings of Sutton and Barto. Ties between greedy actions are broken at random.
The next cell trains 20 agents with different seeds for 500 episodes each, then reads the greedy policy off each agent’s QQ and follows it from S without exploration.
Output from cell 5 Episodes completed against time steps for 20 seeds. The darker line is seed 0, the seed in the next figure. The first episode is long, 722 steps on average over the seeds. The agent starts with Q=0Q = 0 everywhere and wanders until it reaches the goal by chance. Every step of that walk lowers the value of the action it took, so the next episodes avoid the same detours and finish faster. The curves bend upward because each episode takes fewer steps than the one before. The agents complete their first 170 episodes in 8,183 steps on average, close to the 8,000 steps of Sutton and Barto’s figure. Episodes 151 to 170 take 22.6 steps on average, and episodes 481 to 500 take 20.1. The shortest path takes 15 steps, and the ϵ\epsilon-greedy agent stays above that. About one action in ten is random, and a random move in the windy columns can cost several steps to recover from. SARSA learns the values of this ϵ\epsilon-greedy policy, exploration included. Output from cell 6 The windy gridworld with the wind strength of each column (bottom row; darker columns blow harder) and the greedy path of seed 0 after 500 episodes. The greedy policy of seed 0 reaches G in 15 steps, the shortest possible. It cannot go straight to G, because the wind would carry it above the goal’s row. It moves right into the windy columns, lets the wind lift it to the top row, continues to the last column, where there is no wind, walks down to one row below the goal, and then moves left. The wind of strength 1 lifts it onto G with the last move. Across the 20 seeds, the greedy policy reaches the goal in 17, with paths of 15 to 18 steps. In the other 3 seeds the greedy policy gets stuck in the top row. It chooses up, into the edge of the grid, and stays where it is. In each of these cells the estimate for up is slightly higher than, or tied with, the estimate for moving right along the route. SARSA’s estimates are only approximately learned after 500 episodes, and a difference of a few tenths between two actions is enough to make the greedy policy choose a move that goes nowhere. The ϵ\epsilon-greedy agent escapes such a loop with a random action, and the purely greedy policy cannot. With 170 episodes instead of 500, only 8 of the 20 greedy policies reach the goal. 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.