Lesson 58
Expected SARSA
Replace SARSA's single next action with the average value of every next action under the policy. One example is on this page.
Intermediate12 min
What You Will Learn
- Idea
- Example
- When to use it
Idea
Expected SARSA uses the same on-policy idea as SARSA, but it does not depend on one sampled next action. The target averages the next action values with the probabilities of the policy. That average has less noise than one sample and still accounts for exploration.
Example
import numpy as np
q_next = np.array([0.2, 0.8])
policy = np.array([0.5, 0.5])
expected = float(policy @ q_next)
reward, gamma, q, alpha = 0.0, 0.9, 0.1, 0.5
updated = q + alpha * (reward + gamma * expected - q)
print(f"Q: {updated:.3f}")Output:
Q: 0.275When to use it
- Use it when a discrete action set is small enough to average.
- A uniform policy makes the target the mean of the next action values.
- It sits between SARSA's one sample and Q-learning's max.
Loading playground…