Expected SARSA is a temporal difference control algorithm in reinforcement learning that updates an action-value estimate toward the reward plus the expected value of the next state, averaged over all actions according to the current policy. Instead of using the single next action the agent happened to sample, it uses the probability-weighted average of every possible next action value.
This small change removes the sampling noise of the next action from each update. As a result, Expected SARSA usually learns more stably than SARSA, tolerates larger learning rates, and can operate either on-policy or off-policy, which places it conceptually between SARSA and Q-learning.
How the Expected SARSA update works
After taking action A in state S and observing reward R and next state S′, Expected SARSA computes a target equal to R plus γ times the sum over actions of π(a|S′) Q(S′, a). The estimate Q(S, A) then moves toward this target by a fraction α, the learning rate, exactly as in other temporal difference methods.
The update can be written as Q(S,A) ← Q(S,A) + α [R + γ Σ π(a|S′) Q(S′,a) − Q(S,A)]. The bracketed term is the temporal difference error. Because the next-action term is an expectation rather than a sample, the target depends only on the randomness of the environment, not on the randomness of the agent’s own action choice.
The following table lists the components of the update and their usual ranges.
| Component | Meaning | Typical value or form |
|---|---|---|
| Learning rate α | Step size toward the target | 0.1 to 1.0 in tabular settings |
| Discount factor γ | Weight of future rewards | 0.9 to 0.99 |
| Target policy π | Policy used for the expectation | Epsilon-greedy or softmax |
| Expected next value | Policy-weighted average of Q(S′, a) | Sum over all actions |
| TD error | Difference between target and estimate | Drives each update |
Expected SARSA compared with SARSA and Q-learning
Expected SARSA, SARSA and Q-learning differ only in how they estimate the value of the next state. That one choice determines their variance, their bias and whether they learn on-policy or off-policy.
| Algorithm | Next-state value used | Policy type | Update variance |
|---|---|---|---|
| SARSA | Q of the sampled next action | On-policy | Higher |
| Expected SARSA | Policy-weighted mean of all Q values | On-policy or off-policy | Lower |
| Q-learning | Maximum Q over next actions | Off-policy | Low, but biased upward |
Q-learning is in fact a special case of Expected SARSA in which the target policy is fully greedy, so the expectation reduces to the maximum. When the target policy is epsilon-greedy, Expected SARSA learns the value of the exploring policy itself, which keeps it safer near risky states, much as SARSA does, but with less noise.
In the classic cliff-walking task, Q-learning learns the shortest path along the cliff edge and frequently falls during exploration, while SARSA and Expected SARSA learn a safer path further from the edge. Expected SARSA reaches that safer behavior faster and remains stable across a wider range of learning rates.
Bias, variance and computational cost
The main advantage of Expected SARSA is lower variance per update. Removing the random choice of the next action means each update reflects the policy’s true expected outcome, which allows learning rates close to 1 in deterministic environments without divergence.
The price is extra computation. Each update requires evaluating Q for every action in the next state and weighting it by the policy probabilities, which costs O(|A|) per step. With a handful of discrete actions this is negligible, but it becomes impractical for continuous or very large action spaces without approximation.
| Setting | Effect of Expected SARSA | Practical consequence |
|---|---|---|
| Small discrete action space | Cheap expectation, much lower variance | Usually the preferred choice |
| Large discrete action space | Expectation becomes costly | Sampling or approximation needed |
| Continuous action space | Exact sum is impossible | Use actor-critic methods instead |
| Highly stochastic rewards | Variance from rewards remains | Smaller learning rate still required |
| Deep function approximation | Smoother targets than SARSA | Combines well with target networks |
Using Expected SARSA in practice
Expected SARSA fits problems with small discrete action spaces where stable learning matters, such as grid worlds, scheduling decisions and simple control tasks. It also serves as a drop-in replacement for Q-learning targets in deep agents when maximization bias causes overestimation.
- Choose the target policy deliberately: an epsilon-greedy target gives safe on-policy behavior, while a greedy target recovers Q-learning.
- Decay epsilon gradually so that the expectation converges toward the greedy optimum as exploration shrinks.
- Pair it with n-step returns or eligibility traces when rewards are delayed, which speeds up credit assignment.
- Use a target network in deep variants to keep the expected next value from chasing a moving estimate.
Under standard conditions, such as visiting every state-action pair infinitely often and a suitably decaying step size, tabular Expected SARSA converges to the optimal action values when the target policy becomes greedy in the limit.
Common misconceptions about Expected SARSA
Several misunderstandings appear repeatedly in tutorials and student implementations, and they lead to subtly wrong agents.
- It does not average over next states. The expectation is taken only over actions, while the next state is still a single sample from the environment.
- It is not always on-policy. The behavior policy and the target policy can differ, which makes Expected SARSA a valid off-policy method without importance sampling.
- Lower variance does not remove all noise. Stochastic rewards and transitions still add variance to every update.
- Forgetting exploration probabilities in the expectation, for example by weighting only the greedy action, silently turns the method into Q-learning.
A plain-language summary
Expected SARSA is a way for a learning agent to judge its choices by their average outcome. It learns by trial and error, like a person trying routes to work.
A simpler method looks at only the one thing it tried next. That can be misleading, because one try may be lucky or unlucky. Expected SARSA instead asks: what would happen on average, given how often I pick each option? That average is steadier.
The key benefit is calmer, more reliable learning. The cost is a little more arithmetic at every step.
An example from practice
An engineering team builds a warehouse robot controller that chooses among five discrete actions: move forward, turn left, turn right, wait or pick an item. Training happens in a simulated floor of 400 grid cells, with a reward of plus 10 for each delivered order and minus 50 for a collision with a shelf or another robot.
The team first trains with Q-learning and an exploration rate of 0.1. The robot learns short routes that pass very close to busy intersections, and during training it collides in about 6 percent of episodes. Switching the update to Expected SARSA with an epsilon-greedy target policy makes the learned values account for occasional exploratory moves near obstacles.
With the same learning rate of 0.5 and discount factor of 0.95, the new agent converges in roughly 30 percent fewer episodes and chooses routes one or two cells wider around intersections. Collisions drop below 1 percent, while average delivery time rises by only a few seconds, a trade-off the warehouse operators accept.