5.1.12 · D5Reinforcement Learning Foundations

Question bank — SARSA algorithm

1,771 words8 min readBack to topic

Before the questions, one shared vocabulary reminder so no symbol here is unearned:


True or false — justify

TF1. SARSA converges to the optimal greedy policy regardless of the exploration used.
False. SARSA converges to for the behaviour policy it follows (e.g. -greedy). Only if you decay over time does that behaviour policy become greedy and .
TF2. If , the SARSA update ignores the next state-action entirely.
True. With the target collapses to , so just learns the immediate reward — the term vanishes and becomes irrelevant to the update.
TF3. A positive TD error always means the reward was positive.
False. . Even with you can get if the discounted next value beats a very pessimistic current estimate — exactly the Windy Gridworld case where .
TF4. SARSA and Q-learning give identical updates when the policy is fully greedy ().
True. If then , so and the two update targets coincide.
TF5. Because SARSA is on-policy, it can never learn a value for an action it did not take.
True for that transition. SARSA only updates the taken pair using the taken next action ; actions never chosen in a state get no update from that step and keep their initial value until visited.
TF6. Increasing the learning rate makes SARSA both faster and more stable.
False. Larger moves faster but is less stable — each noisy sample yanks the estimate harder. Stability wants small ; the trade-off is exactly why moves only 10% toward the target.
TF7. Setting is just a convenience; any value would do.
False. It must be because there is no future beyond a terminal state — a nonzero terminal value would inject phantom future return into every episode-ending update and bias all upstream Q-values.

Spot the error

SE1. "SARSA update uses so it always aims for the best next move."
That is Q-learning. SARSA uses with the actual sampled next action; swapping in the max makes it off-policy and changes what it converges to.
SE2. "Take action A, update , then choose A' from S'."
The update needs , but hasn't been chosen yet. You must select before the update, or you'll reference an undefined / stale action.
SE3. " discounts future rewards a little more strongly."
A discount factor must satisfy for the return to converge. amplifies future rewards and can make Q-values diverge to infinity — it doesn't discount at all.
SE4. "After the update, we set but re-sample a fresh action next loop anyway."
Then you'd throw away the you already committed to. On-policy SARSA must take the very it used in the update — re-sampling breaks the ‘learn what you do' guarantee.
SE5. "."
The old estimate dropped off the front. The correct rule adds the scaled error to the current value: , not .
SE6. "With a bad slip, SARSA punishes only the slip state , not the choice ."
Wrong. In the Slip world the slip is baked into the transition out of ; the update lands on , lowering it so ‘forward' reflects the average including slip risk.
SE7. "Since SARSA is safer, its learned Q-values are always higher (less negative) than Q-learning's near a cliff."
Backwards. SARSA's cliff-edge Q-values are more negative because it folds in the chance of exploring into the cliff; that pessimism is precisely what steers it to the safe path.

Why questions

WHY1. Why does SARSA need five pieces of experience while a one-step reward learner seems to need only three?
Because bootstrapping the target needs the value of the next pair — that requires knowing both the next state and the next action , adding two letters to .
WHY2. Why is the TD target called a "target" if it's built from an estimate we're still learning?
It's a moving target: mixes real reward with our current guess. We nudge toward it anyway because, in expectation over many samples, it pulls Q toward the true Bellman value.
WHY3. Why does using the actual make SARSA "safer" than the max?
The actual action includes the occasional exploratory (possibly bad) move. Averaging those in makes SARSA value states realistically as ‘what happens if I sometimes act imperfectly', so it avoids fragile optimal-but-risky paths.
WHY4. Why do we choose before the episode loop but inside it?
The very first step needs an action to execute, so is chosen up front; thereafter each iteration produces the next action needed for the current update, then hands it off as the next step's .
WHY5. Why can SARSA's update be read as stochastic gradient descent?
We minimise the squared error ; its gradient points along , and stepping by is one noisy gradient step toward the Bellman-consistent value.
WHY6. Why does the sign of decide the direction of the Q change, not the sign of the reward?
The update moves by . A negative reward with an even-more-negative old estimate gives , so rises — the comparison to expectation drives the direction, not the raw reward.

Edge cases

EC1. What is the SARSA update on the very first step when all Q-values are initialised to ?
The target is and , so — the first real reward is the seed for everything downstream.
EC2. What happens to the update if is terminal?
Then by definition, so the target is just — no next action is sampled and the future term drops, correctly stopping the return at the episode's end.
EC3. If , what does the SARSA update do to the estimate?
It replaces entirely with the target , discarding all prior learning — full trust in one noisy sample, usually far too jumpy.
EC4. If , what does SARSA learn?
Nothing. The change , so never moves from its initialisation regardless of experience.
EC5. In a deterministic environment with , does SARSA still differ from Q-learning?
No. Greedy behaviour makes the argmax action, so the SARSA and Q-learning targets coincide and both converge to the same values.
EC6. What if the policy at picks an action whose Q-value is currently a bad initial guess?
SARSA uses that (possibly wrong) anyway — early updates are biased by initialisation, but repeated visits correct it as those next-state values themselves get updated.
EC7. Two different runs with the same start diverge in learned Q-values — is SARSA broken?
Not necessarily. -greedy exploration is stochastic, so different action samples yield different on-policy values; both can be valid estimates for their own realised experience.
Recall Quick self-test

One target, one direction, one guarantee. SARSA's update target uses which next action? ::: The action actually chosen by the current policy, not . SARSA converges to the value of which policy? ::: The behaviour (on-)policy it follows, e.g. — only if .