Evaluation & RL
Q-Learning
Watch an agent learn to navigate a grid using Q-Learning and the Bellman equation.
Watch an agent learn a grid world through trial, error, and delayed rewards. See the Q-values propagate backward from the goal, and adjust hyperparameters to change how the agent explores.
Stage 1 of 3: The Environment
- Positive Q-Value
- Negative Q-Value
- Policy Direction
- Agent
A grid world with walls, a goal, and a penalty tile. The agent interacts with states and receives rewards.
Challenge
Can you get the policy arrows to propagate from the start position all the way to the goal?
Let the agent run enough episodes with an appropriate discount factor so the path is fully learned.
Challenge not yet solved.
Check your understanding
2 questions in the bank. Each attempt draws a fresh set in a fresh order, so a second go is a real second go.
Q-Learning Grid-World
An agent learns to navigate an environment not by being handed a map, but by exploring, acting, and observing rewards. In reinforcement learning, the environment is modeled as a Markov Decision Process (MDP).
The agent's goal is to learn a policy—a rule for what action to take in every state—that maximizes its total future reward. Since future rewards are uncertain and delayed, the agent learns , the expected cumulative reward for taking action in state .
The Bellman Update
The agent uses the Bellman equation to update its Q-values iteratively as it explores:
- is the immediate reward received.
- is the discount factor, which determines how much the agent cares about future rewards versus immediate ones.
- is the learning rate, controlling how much new information overwrites old information.
- is the agent's current estimate of the best possible future value from the next state .
By continually exploring using an -greedy strategy (picking a random action with probability to discover new paths) and updating its Q-values, the agent eventually discovers the optimal policy. The optimal action in any state is simply the one with the highest Q-value: .
Reference
- Bellman Update
- Q(s,a) ← Q(s,a) + α [r + γ max Q(s',a') - Q(s,a)]
- ε-Greedy
- With probability ε, explore randomly. Otherwise, pick argmax Q(s,a).
- Discount Factor (γ)
- 0 = short-sighted, 1 = far-sighted.
Break it on purpose
Setting the discount factor (γ) to 0 makes the agent completely short-sighted. It only learns values for states immediately adjacent to the goal; the policy arrows never propagate back to the start.