SARSA is an on-policy TD control algorithm. The name comes from the tuple .
Update rule:
On-policy: unlike Q-Learning's , SARSA uses the action that the agent actually takes. It learns the value of the policy it's following (including exploration).
SARSA vs Q-Learning:
| SARSA | Q-Learning | |
|---|---|---|
| Target | (actual next action) | (best action) |
| Policy | On-policy | Off-policy |
| Behavior | Learns to be safe while exploring | Learns optimal regardless of exploration |
Classic example (CliffWalking):
- Q-learning learns the optimal path (right along the cliff edge) — risky during exploration
- SARSA learns a safer path (far from the cliff) — accounts for its own -greedy exploration
When to use SARSA: when the evaluation policy and behavior policy should be the same, or when you care about safety during learning (the learned policy reflects exploration risks).
Expected SARSA: uses instead of — reduces variance, interpolates between SARSA and Q-learning.
See also: Q-Learning, Miscoral Difference Learning, Actor-Critic Methods