Skip to content
AI360Xpert

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
Episode0Episode: 0
Current Reward0.00Current Reward: 0.00

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 Q(s,a)Q(s, a), the expected cumulative reward for taking action aa in state ss.

The Bellman Update

The agent uses the Bellman equation to update its Q-values iteratively as it explores:

Q(s,a)Q(s,a)+α[r+γmaxaQ(s,a)Q(s,a)]Q(s, a) \leftarrow Q(s, a) + \alpha \left[ r + \gamma \max_{a'} Q(s', a') - Q(s, a) \right]
  • rr is the immediate reward received.
  • γ\gamma is the discount factor, which determines how much the agent cares about future rewards versus immediate ones.
  • α\alpha is the learning rate, controlling how much new information overwrites old information.
  • maxaQ(s,a)\max_{a'} Q(s', a') is the agent's current estimate of the best possible future value from the next state ss'.

By continually exploring using an ϵ\epsilon-greedy strategy (picking a random action with probability ϵ\epsilon 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: argmaxaQ(s,a)\arg\max_a Q(s, a).

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.