Introduction to Reinforcement LearningPart 2 · Learning from experience

Lecture 6Model-free control

From predicting to improving, still without a model: Monte Carlo control and GLIE, SARSA, Q-learning and off-policy learning, the overestimation that double Q-learning fixes, importance sampling and expected SARSA.

By the end you should be able to run SARSA and Q-learning by hand, explain why they find different paths, and say what double learning and importance sampling fix.

Key ideas, one per episode

  • Ep. 21Learn q, explore, then shrink the exploration.
  • Ep. 22Learn the greedy policy while you explore.
  • Ep. 23Don't let the same numbers pick and score.

Based on: Lecture 6: Model-Free Control, DeepMind × UCL Reinforcement Learning Lecture Series (2021), by Hado van Hasselt. The slides follow that order of topics, in our own words, figures and examples; they are not official material of the original course.

The title slide of Lecture 6: Model-free control

44 slides, written to be read on your own, with worked examples, “try it” boxes, small simulations and check-yourself questions (answers at the end). PDF, 1.3 MB.

Watch

3 short episodes of ACML Explains for this lecture. Pick one from the list, and open the transcript to read along: each timestamp plays the episode from there. The narration is generated with a voice clone of Teddy, used with his permission.

Episode 21 · 5:12

Learning to act

Bit can tell you how good a policy is. Today he learns to find a better one, with no model at all.

Learn q, explore, then shrink the exploration.

TranscriptEpisode 21

From predicting to acting

Five modules in, Bit can predict. Give him a policy, and he'll tell you how good it is. But nobody wants a critic. We want Bit to act, and to get better at it. Today he learns to act. No model, no map. Just experience. Remember the recipe from dynamic programming? Evaluate the policy. Improve it. Repeat. That loop is called generalised policy iteration. Today we run it without a model.

Why q, not v

Here's the snag. To improve greedily with v, you need to know where each action leads. Which states come next, and how likely each one is. That's a model, and we don't have one. So learn q instead. q of s and a: how good is this action, right here. With q, improving is easy. Look at the row for your state, and take the biggest number. Like choosing a dish from reviews. You don't need to know what happens in the kitchen. Monte Carlo and TD can learn q from experience. Same methods as before, one letter different. So for control, we learn q, not v. That's the whole trick of this module.

Greedy is a trap

But pure greedy is a trap. Say the first action you tried paid off a little. Greedy will pick it forever. The other actions never get a chance to show what they're worth. So we explore. ε-greedy: most of the time, take the best action. Once in a while, a random one. And the theory backs it up. An ε-greedy policy built on your q is never worse than the policy you had. Small detail: the random move can land on the best action too. Exploring includes the obvious.

The cleaning robot

Now, how big should ε be? In class, I used a cleaning robot. Fix ε at point one, and ten percent of the time it does random things in your living room. That's not why you bought it. You want ε to shrink. One over k works well, where k counts the episodes. Day one, it explores a lot. By the two hundredth run, it should know the house. And one over k never quite reaches zero. A sliver of curiosity stays, and keeps shrinking. Nobody wants a robot that's still curious about the couch after a year.

GLIE

That gives us a condition with a funny name: GLIE. Greedy in the limit, with infinite exploration. Two promises. Every state and action gets tried infinitely often. And in the end, the policy becomes greedy. Keep both, and Monte Carlo control finds the optimal action values. A strong guarantee. But notice the second half. I do ask you to stop exploring eventually. At the optimum, every random move is a wrong move.

SARSA

Monte Carlo waits for the end of an episode. We already know the fix: TD. TD on q has a name you can pronounce: SARSA. The name is the data it needs: a state and an action, the reward, then the next state and the next action. Nudge q of S and A toward the reward, plus γ times q of the next pair. Start the table at zeros. The start state is given, like in chess, or random, like the cards you're dealt. Then act ε-greedily on q, and update after every single step. Update the policy after every step, or after every few episodes? Every step is smoother, but noisier. Which is better? There's no way to know in advance. Solve that in general, and that's great. If not, I won't be mad.

Step sizes that behave

Does SARSA find the optimum? Yes, with GLIE, and with step sizes that behave. Two conditions on the step sizes. Their sum must be infinite. The sum of their squares must be finite. α equal to one over t passes both. The harmonic series grows forever. After a million steps it's only about fourteen point four, but it never stops. The squares add up to π squared over six. About one point six four. Big enough to get anywhere. Small enough to settle

Ten lines and a windy gridworld

down. All those slides of maths. And in code, it's about ten lines of Python. Borderline funny how simple it is. That's how good ideas usually look. We ran it on a windy gridworld. In the middle columns, the wind pushes Bit upwards. The first episode takes about seven hundred steps. Bit gets blown around a lot. After a hundred and seventy episodes, about eight thousand steps in all, an episode takes about twenty two steps. The shortest possible path is fifteen. Our own runs: fifty of them, ε at point one, step size one half. The curve gets steeper as Bit learns. Why not fifteen? Because ε still throws in a random move now and then, and the wind punishes every one.

On-policy

SARSA is on-policy. It learns the value of the policy it actually follows, random moves included. That sounds like a detail. It isn't. It changes which path Bit thinks is best. Learn q, explore, shrink the exploration slowly, and update with SARSA. That's model-free control. Next time: learning about one policy while following another. Q-learning, and a walk along a cliff.

Interactive lab

Gridworld lab

Train Q-learning or SARSA on a small gridworld with hazards and walls. Tune ε, the step size and the discount, add slippery actions, and watch the value map and the greedy policy sharpen episode by episode.

The gridworld keeps the idea compact but brings in state, path dependence and delayed rewards. Watch the agent trade immediate moves against long-run return while the learned policy map gradually sharpens. It starts by connecting the bandit of Lecture 2 to sequential decisions.

From isolated action choice to sequential decision making

A bandit can be read as reinforcement learning with only one state: there are multiple actions, but every pull returns you to the same decision point. A gridworld adds many states, delayed consequences, and transitions, so the cost of a choice can propagate several steps into the future.

Bandit = one state, many actions

Exploration asks: which option seems best when feedback is immediate and the decision context never changes?

Gridworld = many states, delayed consequences

Now each move changes the next state. A poor exploratory step can lead toward a trap or away from the goal.

Exploration still matters

The same tension remains, but decisions now shape future opportunities. Learning a policy means learning where each action leads.

Simple Math

How the gridworld learner updates its action values

In reinforcement learning the estimate is attached to a state-action pair. After each move, the learner nudges that estimate toward a target built from the immediate reward and the next state's value.

Q-learning
Q(s,a) <- Q(s,a) + alpha [r + gamma max_a' Q(s',a') - Q(s,a)]

Q-learning looks ahead to the best possible next action, even if the behavior policy is still exploring.

SARSA
Q(s,a) <- Q(s,a) + alpha [r + gamma Q(s',a') - Q(s,a)]

SARSA updates toward the action the agent actually expects to take next, so it learns under its own exploratory behavior.

Exploration policy
Choose the greedy action most of the time, but explore with epsilon.

Optional epsilon decay makes the learner search broadly at first and then become more stable once it has mapped the environment.

Episodes trained
0
Current epsilon
0.18
Last reward
0.00
Last episode length
0
Goal rate (last 20)
0%

Policy and value map

Cell shading reflects the current value estimate. Icons show the greedy action, and numbered badges mark the latest trajectory.

Greedy action Path marker

Episode reward history

Returns should rise as the policy discovers a safer, shorter route to the goal.

History shown
0 episodes

Most recent trajectory

This makes the last episode legible as a path rather than only as a scalar reward.

Ready

Play

A game that goes with this lecture, and what to look for while you play.

Echo Heist

Teach a little robot. Steal back a city.

In this lecture: One of the learners Echo Heist trains in your browser is a tabular one. Change what Echo can sense or what it is rewarded for, train, and watch the route it learns change.

Choose what your partner Echo senses, which actions it can take and what success means, then let a real learner train in your browser: tabular, planning, policy-gradient, deep-RL or imitation. When the door opens, the policy is frozen and Echo runs with what it learned.