Q-Learning Update Rule
Chapter 2 ended with Bellman equations. For Q-learning, the key bridge is the Bellman optimality equation for actions:
The optimal Q-value equals the expected immediate reward plus the discounted value of the best next action. In a delivery robot example, asks: if the robot takes this first move from this situation, how much return should it expect if it behaves optimally afterward?
If we knew and , we could compute the expectation by averaging over all possible next states and rewards. In real learning problems, the agent usually cannot compute that expectation. It can sample it: take action , observe reward , and see the next state .
So, we need a way to learn directly from experience, without knowing or . That is Q-learning.
After taking action in state , receiving reward , and observing next state , Q-learning updates only the table entry for the state-action pair it just used.
Q-learning update
Click the parts of the update rule
The update moves the current Q-value toward a target built from one sampled transition.
delta
-0.0050
old Q
-0.0050
new Q
-0.0075
Selected part
The discounted value of the best action available in the sampled next state.
The update rule is
The bracketed quantity is the temporal-difference error, often written It measures surprise: how different the sampled target was from the current estimate. If , the prediction matched the sampled target.
Q-table walkthrough
Build a Q-table in a 3x3 gridworld
Step through a short episode. Each sampled transition updates one state-action entry in the Q-table.
Q-learning update equation
Actions: ↑ ↓ ← →
Rewards: -0.01, +1.0 goal
γ: 0.9 α: 0.5
all Q = 0
all Q = 0
all Q = 0
all Q = 0
all Q = 0
all Q = 0
all Q = 0
all Q = 0
all Q = 0
Setup
Start with every Q(s,a) entry at 0. The agent begins at (3,1), the goal is at (1,3), each non-goal step gives -0.01, gamma is 0.9, and alpha is 0.5.
Use the buttons above to watch one sampled transition at a time update a single Q-table entry.
Which part of the Q-learning update looks into the next state?