Expected Sarsa and double learning
Expected Sarsa is an on-policy temporal-difference control method that uses the expectation over next actions to reduce variance; double learning (double Q-learning) uses two value estimates to reduce maximization (overestimation) bias in action-value methods.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Reinforcement-learning engineers use Expected Sarsa and double learning when designing stable, sample-efficient control algorithms that learn action values (Q-values) from interaction with an environment. Expected Sarsa reduces update variance by using the expected next-action value under a policy; double learning (e.g., Double Q-learning) reduces the overestimation bias that appears when using a max operator in value updates. These methods are practical for robotics, resource allocation, and any control task where stable value estimates matter.
Key ideas
Start from a Markov decision process (MDP): a tuple (S, A, P, R, γ) where S is a finite set of states, A a finite set of actions, P(s'|s,a) transition probabilities, R(s,a,s') reward (possibly random), and 0 ≤ γ ≤ 1 is the discount factor (use γ < 1 for continuing tasks; γ = 1 is allowed for episodic tasks). We assume finite MDP and episodic or continuing tasks with bounded rewards.
Define an action-value function (Q) for a policy π: Qπ(s,a) = E[ sum_{t=0}^∞ γ^t R_{t+1} | S0=s, A0=a, policy π ]. This is the expected discounted return after taking action a in state s and thereafter following policy π.
Define the TD-target and TD-error for one-step updates. For a general one-step update to Q(s,a) we use a target G and error δ = G − Q(s,a). Temporal-difference methods update Q(s,a) ← Q(s,a) + α δ, where 0 < α ≤ 1 is the step-size (learning rate).
Sarsa, Q-learning and Expected Sarsa differ in the target G they use:
- Sarsa (on-policy sample update) uses the sampled next action A' drawn from policy π, so G = R + γ Q(S', A').
- Q-learning (off-policy) uses the greedy max over actions at S': G = R + γ max_{a'} Q(S', a').
- Expected Sarsa uses the expectation under policy π at S': G = R + γ E_{a'~π}[ Q(S', a') ] = R + γ Σ_{a'} π(a'|S') Q(S',a').
Expected Sarsa reduces sampling variance because it replaces a single sampled next-action value with its expectation under π. It is an on-policy, bootstrapping, TD control method: on-policy because it uses the same policy π to choose actions and compute the expectation; bootstrapping because it uses existing Q estimates in the target.
Define maximization bias (overestimation bias): when estimating the maximum expected value over noisy estimates, the expected value of the maximum estimator exceeds the maximum of the expected values (E[max(X_i)] ≥ max(E[X_i])). In Q-learning this causes positive bias in target R + γ max_a' Q(S',a').
Define Double Q-learning (double learning): maintain two independent action-value estimates Q1 and Q2. On each update, randomly choose to update Q1 or Q2. When updating Q1, select action a* = argmax_a Q1(S',a) but evaluate with Q2: target = R + γ Q2(S', a*). This separates selection (argmax) from evaluation, reducing maximization bias. The same symmetric rule applies when updating Q2 (roles swapped).
Convergence assumptions (standard, state briefly): finite MDP, all state-action pairs visited infinitely often under the behaviour policy (exploration), step-sizes α_t satisfy Robbins–Monro: Σ_t α_t = ∞ and Σ_t α_t^2 < ∞, and for on-policy control use GLIE (greedy in the limit with infinite exploration) policy schedules. Under these conditions Sarsa and Expected Sarsa converge to the correct action-value function for the limiting policy; Q-learning converges to Q* under its own conditions. Double Q-learning converges similarly for finite MDPs with proper exploration and step-size schedules.
Derivation of Expected Sarsa update (step-by-step):
- Start with TD-target defined by expectation under policy π: G = R + γ E_{a'~π}[ Q(S', a') ].
- TD-error δ = G − Q(S,A) = R + γ Σ_{a'} π(a'|S') Q(S',a') − Q(S,A).
- Update rule: Q(S,A) ← Q(S,A) + α δ.
Describe what to draw for a diagram (exam style): draw two states S and S' as circles. From S draw an arrow labeled action a to S'. At S' draw two outgoing arrows to possible next states or loop back, label possible actions a1', a2' and label their policy probabilities π(a1'|S'), π(a2'|S'). Next to the arrow from S to S' write reward R and show Q(S,A) and Q(S',a1'), Q(S',a2') values.
Derivation of Double Q-learning update (step-by-step):
- Maintain Q1 and Q2. When sample (S,A,R,S') occurs, flip a fair coin. If updating Q1: a* = argmax_a Q1(S',a) target = R + γ Q2(S', a*) Q1(S,A) ← Q1(S,A) + α [target − Q1(S,A)].
- If updating Q2, roles of Q1 and Q2 are swapped. This reduces bias because the argmax uses one estimator while evaluation uses an independent estimator.
Explain relation between Expected Sarsa and Double Learning: they address different problems—Expected Sarsa reduces variance of the TD-target by taking expectation over the policy at S', while Double Q-learning reduces the systematic positive bias introduced by the max operator in greedy updates. You can combine ideas (e.g., double Expected Sarsa variants), but keep the basic separation clear.
Formulas
Qπ(s,a) = Eπ[ Σ_{t=0}^∞ γ^t R_{t+1} | S0=s, A0=a ] — Qπ(s,a) is the action-value for policy π; γ is unitless discount factor (unit: 1), rewards R measured in their units (e.g., joules) but commonly treated as unitless; applies for infinite-horizon discounted MDP or until termination.
δ = R + γ Σ_{a'} π(a'|S') Q(S',a') − Q(S,A) — TD-error for Expected Sarsa; R reward (units of reward), γ unitless, π(a'|S') probability (unitless), Q values same units as R; applies for one-step Expected Sarsa update (if S' is terminal, the bootstrapped term is taken as 0).
Q(S,A) ← Q(S,A) + α · δ — usual TD update; α unitless step-size (0<α≤1); applies whenever you perform a one-step update.
Q(S,A) ← Q(S,A) + α [ R + γ Q(S', A') − Q(S,A) ] — Sarsa update (sampled A' from π); A' is sampled next action. If S' is terminal, omit the γ Q(S',A') term (treat it as 0).
Q(S,A) ← Q(S,A) + α [ R + γ max_{a'} Q(S',a') − Q(S,A) ] — Q-learning update (off-policy), applies when using greedy target. If S' is terminal, omit the γ max term (treat it as 0).
Q1(S,A) ← Q1(S,A) + α [ R + γ Q2(S', argmax_a Q1(S',a)) − Q1(S,A) ] — Double Q-learning update when updating Q1; Q2 symmetric when updating Q2. If S' is terminal, the bootstrapped term is 0. Applies for double-learning algorithm.
E[max_i X_i] ≥ max_i E[X_i] — inequality showing maximization bias; X_i random variables (unitless expectation depending on units of X).
Worked examples
Example 1 — Numerical single-step Expected Sarsa vs Sarsa vs Q-learning Problem: Single transition S --(a)--> S'. Reward R = 2. Discount γ = 0.9. Current estimates: Q(S,A)=1.0, Q(S',a1)=3.0, Q(S',a2)=2.0. Policy π at S' is ε-greedy with ε=0 (greedy) so π(a1|S')=1, π(a2|S')=0. Learning rate α=0.1.
Compute updates.
Sarsa (sampled A'=a1 since greedy): target = R + γ Q(S',a1) = 2 + 0.9·3.0 = 2 + 2.7 = 4.7 δ = 4.7 − 1.0 = 3.7 Q ← 1.0 + 0.1·3.7 = 1.0 + 0.37 = 1.37
Expected Sarsa (expectation under π gives same because deterministic): Σ π(a')Q = 1·3.0 + 0·2.0 = 3.0 so target = 4.7, same δ and same update → 1.37
Q-learning (max over Q(S') is 3.0): target = 4.7 → same result here because greedy policy aligned. Q ← 1.37
Note: with non-deterministic π, Expected Sarsa would compute a weighted sum and may differ from Sarsa's single sample.
Example 2 — Demonstrating maximization bias and double Q-learning (small MDP) Problem: Single-step transition to a nonterminal next state S'. Two actions a and b from state S. True optimal next-state values are equal: Q*(S',a)=Q*(S',b)=0. Agent has noisy estimates: suppose current estimates Q(S',a)=+0.8 and Q(S',b)=+0.6 (both upward by chance). Let immediate reward R=0 and discount γ=0.9.
Q-learning target uses the max over next-state estimates: target = R + γ max_{a'} Q(S',a') = 0 + 0.9·max(0.8,0.6) = 0.9·0.8 = 0.72, which is a positive overestimate relative to the true target 0.
Double Q-learning: let Q1(S',a)=0.8, Q2(S',b)=0.6 (uncorrelated estimates). If updating Q1, a* = argmax_a Q1(S',a) = a, and evaluate with Q2: target = R + γ Q2(S',a) ≈ 0 + 0.9·0.0 = 0.0 in expectation (since Q2's noise is independent and zero-mean for action a). Thus the update avoids reinforcing the noisy high value in expectation.
Model answer style explanation: the argmax on the same estimator produces a positive expected error because E[max(Q_estimates)] > max(E[Q_estimates]) = 0; double learning separates selection and evaluation to reduce this bias.
Example 3 — (Short theory answer) Show expected Sarsa reduces variance of the update compared to Sarsa Model answer: write δ_sarsa = R + γ Q(S', A') − Q(S,A) where A' ~ π, and δ_exp = R + γ E[Q(S',A')] − Q(S,A) = E[δ_sarsa | S,S',R]. By the law of total variance, Var(δ_sarsa) = E[Var(δ_sarsa | S,S',R)] + Var(E[δ_sarsa | S,S',R]) = E[Var(δ_sarsa | S,S',R)] + Var(δ_exp) ≥ Var(δ_exp). Thus Expected Sarsa has variance no larger than Sarsa (and typically lower) because it removes the randomness due to sampling A' (at the cost of summing over actions).
Common mistakes
- Saying Expected Sarsa is always better than Sarsa: expected Sarsa reduces variance but may be more computationally expensive; bias properties depend on policy used.
- Saying double Q-learning eliminates all bias: it reduces overestimation bias from the max operator, but does not make estimates unbiased; it trades some variance for reduced bias.
- Forgetting conditions for convergence: you must state Robbins–Monro conditions on α and sufficient exploration (GLIE or all state-action pairs visited infinitely often) depending on the method.
- Mis-placing units: Q-values are in units of cumulative reward; usually treated as unitless in exam arithmetic — state this.
For your exam
Typical question types:
- Definitions: define Expected Sarsa, TD-error, double Q-learning, maximization bias. Full marks: concise definitions and context.
- Short notes: compare Sarsa, Expected Sarsa and Q-learning. Full marks: explain targets, on/off-policy, variance and bias trade-offs, computational cost.
- Derivations: derive Expected Sarsa update and show its TD-error. Full marks: stepwise derivation from expectation and insertion into TD update.
- Numericals: compute single-step updates (provide numbers). Full marks: show all steps, units of reward, compute δ then update.
- Diagrams: draw MDP transition for one-step update and label which values are used for each algorithm. Full marks: clean diagram with labels Q(S,A), Q(S',a'), π(a'|S'), R and γ.
- Longer theory: explain overestimation bias and derive double Q-learning update; show simple proof that E[max] ≥ max(E). Full marks: include inequality proof or reasoning and algorithm update rules.
Quick check
- Write the Expected Sarsa one-step update formula.
- Why does maximization bias occur in Q-learning? Give the inequality name or expression.
- Give the Double Q-learning target used when updating Q1.
Answers: 1) Q(S,A) ← Q(S,A) + α [ R + γ Σ_{a'} π(a'|S') Q(S',a') − Q(S,A) ]. 2) Because E[max_i X_i] ≥ max_i E[X_i], noise in estimates makes the max operator produce a positive bias. 3) target = R + γ Q2(S', argmax_a Q1(S',a)) when updating Q1.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?