Skip to main content
Open In Colab Run SARSA and Q-learning on the same CliffWalking-v1 environment, with the same hyperparameters, and read off the difference in learned policies. This is Sutton & Barto Example 6.6.
  • Environment: CliffWalking-v1 (4×12 grid, reward 1-1 per step, 100-100 on the cliff with reset to start, deterministic, γ=1\gamma = 1).
  • Behavior policy (both methods): ϵ\epsilon-greedy with ϵ=0.1\epsilon = 0.1.
  • TD target: SARSA uses Q(S,A)Q(S', A') where AA' is the next action sampled from ϵ\epsilon-greedy; Q-learning uses maxaQ(S,a)\max_{a'} Q(S', a').
The expected outcome: Q-learning’s greedy policy walks along the cliff edge (shortest path), SARSA’s greedy policy walks along the top row (safer under ϵ\epsilon-greedy exploration).
Output from cell 4
Output from cell 5 Two readings of the figures. Returns curve. Q-learning’s training-time return is worse (lower) than SARSA’s, even though Q-learning learns the optimal greedy policy. The reason: training-time return is collected under the ϵ\epsilon-greedy behavior policy. Q-learning’s greedy target is the cliff-edge path, so its ϵ\epsilon-greedy rollouts occasionally take a random step into the cliff and absorb the 100-100 penalty. SARSA’s TD target accounts for the exploration cost, it learns a Q that places lower value on cells adjacent to the cliff, so its ϵ\epsilon-greedy rollouts walk the safer top-row path and rarely fall off. Greedy paths. Read off the deterministic argmaxaQ(s,a)\arg\max_a Q(s, a) from each Q-table:
  • Q-learning: shortest path from start to goal, hugging the cliff edge.
  • SARSA: longer path along the top row, away from the cliff.
The two methods are minimizing different objectives. Q-learning’s target policy is the optimal one (for the actual MDP), exposed only at evaluation time when ϵ=0\epsilon = 0. SARSA’s target policy is the ϵ\epsilon-greedy policy itself, so it embeds the exploration cost into the value function. If you set ϵ0\epsilon \to 0 over training, both methods converge to the same greedy policy. The interesting regime is the one shown here: a fixed exploration rate during training, and the difference in behavior under that exploration that the two TD targets capture. Key references: (O’Donoghue et al., 2016; Ma & Yu, 2016; Li, 2017; Mansour & Singh, 2013; Lillicrap et al., 2015)

References

  • Li, Y. (2017). Deep Reinforcement Learning: An Overview.
  • Lillicrap, T., Hunt, J., Pritzel, A., Heess, N., Erez, T., et al. (2015). Continuous control with deep reinforcement learning.
  • Ma, S., Yu, J. (2016). Transition-based versus State-based Reward Functions for MDPs with Value-at-Risk.
  • Mansour, Y., Singh, S. (2013). On the Complexity of Policy Iteration.
  • O’Donoghue, B., Munos, R., Kavukcuoglu, K., Mnih, V. (2016). Combining policy gradient and Q-learning.