This Reinforcement Learning concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Reinforcement Learning
Q-Learning and SARSA
Q-learning and SARSA both update the action just taken; SARSA bootstraps from the next action the behavior policy sampled, while Q-learning bootstraps from the largest next action value in the current table.
Concept Structure
Q-Learning and SARSA
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learner Contract
What this page should let you do.
1 prerequisite listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and test one prediction in the live demo.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Substantive review recorded
1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Temporal-difference learning updated a state value. Control needs one more question:
If I was in this state and took this action, how good was that action?
That is why Q-learning and SARSA learn , an action value, instead of only . Both methods observe one transition,
then update the value of the action that was just taken.
The split happens at the next state. SARSA asks, "What action did my behavior policy actually sample next?" Q-learning asks, "What is the best next action according to my current table?"
When exploration chooses the same action that the table already thinks is best, the two updates match. When exploration chooses a different action, SARSA learns about the exploratory path it is actually following, while Q-learning learns toward the greedy target path.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Assume a finite discounted MDP and a tabular action-value estimate . At time , the agent observes state , takes action , receives reward , and lands in .
SARSA is on-policy one-step TD control. It samples the next action from the current behavior policy, then updates with
The name SARSA comes from the quintuple
Q-learning is off-policy one-step TD control. It can act with an exploratory behavior policy, but its target uses the greedy next action under the current table:
If is terminal, the bootstrap term is zero for both algorithms.
The important comparison is not "which algorithm is always better." It is what each update is estimating from the same experience:
- SARSA target: reward plus the sampled next action value.
- Q-learning target: reward plus the largest next action value.
- Behavior policy: the policy that generated the data.
- Target policy: the policy the update is evaluating or improving toward.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
gamma = 0.90
alpha = 0.40
current_q = 1.10
reward = 0.20
next_q = {
"repeat": 2.40, # greedy under the table
"ask": 1.00, # sampled by exploration
"skim": 0.60,
}
sampled_next_action = "ask"
sarsa_target = reward + gamma * next_q[sampled_next_action]
q_learning_target = reward + gamma * max(next_q.values())
for name, target in [
("SARSA", sarsa_target),
("Q-learning", q_learning_target),
]:
error = target - current_q
updated = current_q + alpha * error
print(name, "target", round(target, 3), "error", round(error, 3), "new Q", round(updated, 3))
The same observed transition can produce different targets because the next action used by the bootstrap is different.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Use the Q-learning vs SARSA Target Lab to predict which update changes the current action value more.
Choose a transition case, inspect the current and the next-state action values, then commit to whether SARSA, Q-learning, or neither should update more. After reveal, the lab shows the sampled next action, the max next action, both targets, both TD errors, and the new value each algorithm would write.
The terminal case and sampled-greedy case are there on purpose: they show when the algorithms collapse to the same one-step target.
Live Concept Demo
Explore Q-Learning and SARSA
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Q-Learning and SARSA should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Q-learning and SARSA both update the action just taken; SARSA bootstraps from the next action the behavior policy sampled, while Q-learning bootstraps from the largest next action value in the current table.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Q-Learning and SARSA should make visible.
Visual Inquiry
Make the image answer a mathematical question
Q-learning and SARSA both update the action just taken; SARSA bootstraps from the next action the behavior policy sampled, while Q-learning bootstraps from the largest next action value in the current table.
Which visible object should carry the first intuition?
Pick the cue that should make Q-Learning and SARSA easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Canonical source for SARSA as on-policy TD control, Q-learning as off-policy TD control, the sampled next action versus max-over-actions distinction, and cliff-walking behavior contrast.
Open sourceGraduate RL source for on-policy/off-policy definitions, tabular Q-learning update, SARSA update, epsilon-greedy behavior policy, and function-approximation caveats.
Open sourceCourse-note source for model-free learning, active Q-learning, feedback-driven policy improvement, and the exploration requirement.
Open sourceClaim Review
Q-learning and SARSA both update the action just taken; SARSA bootstraps from the next action the behavior policy sampled, while Q-learning bootstraps from the largest next action value in the current table.
Claims without a substantive review badge still need exact source-support review.
sutton-barto-2018-rl, stanford-cs234-model-free-control, berkeley-cs188-model-free-learning
Use equations, runnable code, and demos to check whether the source support is operational.
The sources support finite tabular one-step action-value TD control where both algorithms update the visited state-action pair, but SARSA bootstraps from the sampled next action and Q-learning bootstraps from the greedy next action.
Sources: Reinforcement Learning: An Introduction, Second Edition, Stanford CS234: Lecture 4, Model-Free Control and Function Approximation, UC Berkeley CS188: Model-Free LearningFinite tabular teaching MDP only; excludes Expected SARSA, n-step methods, eligibility traces, Double Q-learning, DQN, replay buffers, target networks, continuous spaces, and function-approximation convergence failures beyond a caveat note.A bounded review summary is present; still check caveats and exact reference scope.Checked Sutton/Barto Chapter 6 for SARSA's quintuple update and Q-learning's off-policy max-over-next-actions update; checked Stanford CS234 Lecture 4 for on/off-policy definitions, Q-learning and SARSA equations, epsilon-greedy behavior, and tabular convergence caveats; checked Berkeley CS188 for model-free Q-learning as active reinforcement learning with exploration. GPT Pro publication critique remains pending because 127.0.0.1:51672 is unavailable.
Reviewer: codex-local-source-review; reviewed 2026-07-03Source support candidates
book 2018Reinforcement Learning: An Introduction, Second EditionCanonical source for SARSA as on-policy TD control, Q-learning as off-policy TD control, the sampled next action versus max-over-actions distinction, and cliff-walking behavior contrast.
course-notes 2026Stanford CS234: Lecture 4, Model-Free Control and Function ApproximationGraduate RL source for on-policy/off-policy definitions, tabular Q-learning update, SARSA update, epsilon-greedy behavior policy, and function-approximation caveats.
course-notes 2026UC Berkeley CS188: Model-Free LearningCourse-note source for model-free learning, active Q-learning, feedback-driven policy improvement, and the exploration requirement.
Practice Loop
Try the idea before it explains itself
Q-learning and SARSA both update the action just taken; SARSA bootstraps from the next action the behavior policy sampled, while Q-learning bootstraps from the largest next action value in the current table.
Before touching the demo, predict one visible change that should happen in Q-Learning and SARSA.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to a claim, equation, code, or demo
Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.Open the draft below to save one note and next action in this browser.
Q-Learning and SARSA
What is the smallest example that makes Q-Learning and SARSA click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays in this browser, attached to the selected learning item.
- References to inspect: attached references on this page.
- Definition, prerequisite, and contrast concept links
- The equation or runnable code that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Q-Learning and SARSA Selected item key: recorded for copy. Context: Reinforcement Learning Page anchor: recorded for copy. Open question: What is the smallest example that makes Q-Learning and SARSA click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/reinforcement-learning/q-learning-sarsa
concept:reinforcement-learning/q-learning-sarsa