Introduction to Reinforcement LearningPart 1 · Foundations

Lecture 2Exploration and exploitation

The simplest place to study the trade-off between trying something new and using what you already know: the multi-armed bandit. Regret, greedy and ε-greedy, optimism and UCB, Thompson sampling, and gradient bandits with softmax preferences.

By the end you should be able to explain why exploration is needed, compute regret, and run greedy, ε-greedy, UCB and Thompson sampling by hand.

Key ideas, one per episode

  • Ep. 6Every pull earns or teaches.
  • Ep. 7Explore a little, on purpose.
  • Ep. 8Try what might be great.
  • Ep. 9Explore where you're unsure, exploit where you're sure.

Based on: Lecture 2: Exploration and Exploitation, 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 2: Exploration and exploitation

47 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.6 MB.

Watch

4 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 6 · 4:24

Explore or exploit

Keep pulling the slot machine that paid best, or try another one? Welcome to the multi-armed bandit.

Every pull earns or teaches.

TranscriptEpisode 6

Explore, then exploit

Module two! And we start with something you already do every day. You want to learn a new field. So you google, read the first site, then the third, a bit here, a bit there. Slowly you learn the right words, and who to read. That's exploration: gathering knowledge. Then you use what you learned to write your paper. That's exploitation: using knowledge to decide well. Usually you explore first, then exploit. But it's not that linear: you go back and forth. Or ants. I know watching ants is something you do a lot in your day. They leave the nest and wander, more or less at random, until one finds food. She goes back, tells her friends, and you get the line. That line is exploitation of new knowledge.

A world with one state

To study this, we simplify the world to a single state. With one state, does order matter? No. Nothing I did yesterday changes today. Actions still give rewards. They just don't move us anywhere. I know, I said RL is for sequences of decisions. One state removes that, on purpose. We'll fill the gap later.

The bandit

Long, long ago, in a land far away, there was a machine with many handles. At fairs and theatres, you'd pull a handle and get a prize, or a punishment. It was dressed up as a bandit. Many arms, one bandit: the multi-armed bandit. Pull a handle, let it go. The machine doesn't change. One state. Perfect for us. Fun fact: the bandit problem is older than RL itself.

A circus thought experiment

Thought experiment. I run a circus, which isn't far from my reality right now. Bit comes to win lots of money. My bandit has ten handles. Bit starts by pulling each handle once. Smart: he knows nothing, so he explores. Then he keeps pulling the one that paid the most. Is he sure it's the best? No! One pull is noise. Maybe a quiet handle pays a fortune once every hundred pulls. And notice: the goal isn't just to find the best handle. It's to win the most money along the way.

Expected reward

So what are we really after? The expected reward of each handle. We call it q of a. Why expected? Pull the same handle again and again, and the average settles on it. That's the law of large numbers. Bit can't know q. But he can estimate it: the average reward he got from that handle. A capital Q. And we count how many times Bit pulled each handle: N of a. Pulled a handle a hundred times? N is a hundred. The best Bit could ever do? Pull the best handle every single time. That's the optimal value, v star. With one state, the value is just one number per handle. We can drop the s.

Learning one pull at a time

And he can update it one pull at a time: new estimate equals old estimate, plus a step times the surprise. Look familiar? It's gradient descent. With a step of one over the number of pulls, the first pull moves you a lot, and the thousandth barely at all. Slower, but stable: at pull one thousand, one crazy value doesn't throw you around. That's the trade-off in the step size: big steps learn fast and shake, small steps learn slowly and stay calm.

Regret

Now we need a score for the learner itself. It's called regret. Regret is the gap between the best handle and the handle you actually pulled. Pull the best one: zero regret. Pull a worse one: you pay the difference. Add it up over all your pulls and you get the total regret. Maximising total reward and minimising total regret are the same thing. If you like loss functions: in our world, the loss is called regret. Regret uses something Bit doesn't know: the best handle. So it's a score for us, the designers, not a signal for Bit.

The tension

And here's the tension. Exploring raises your regret. We explore because we must, not because it's fun. Exploiting should raise it less. Ideally, not at all. Watch the curve: steep while Bit explores, flatter once he knows. A good learner keeps the steep part short.

A problem, not an algorithm

One last thing: the multi-armed bandit is not an algorithm. It's a problem, the simplest RL problem there is. And because it's so simple, it's where nearly every exploration idea gets tried first. Next time, the algorithms, starting with the greediest one. With me so far?

Interactive lab

Bandit lab

Pull the arms of a multi-armed bandit with ε-greedy, UCB or Thompson sampling. Change the number of arms, let the hidden reward chances drift, and watch estimates, regret and the gap to an oracle evolve.

The bandit setting isolates the exploration problem: there is no map, no future state and no path planning. Each pull simply asks whether your current estimates are good enough to exploit, or whether you should keep probing the alternatives.

Simple Math

How the bandit strategies decide which arm to pull

Each method keeps a running estimate for every arm, then balances value and uncertainty in a different way when it picks the next action.

epsilon-greedy
Explore with probability epsilon.
Otherwise choose arg max_a q_hat(a).

Most steps exploit the best estimate so far, while a fixed random-exploration rate prevents early lock-in.

UCB
q_hat(a) + c * sqrt(log t / n(a))

Arms with less data receive a larger confidence bonus, so uncertainty itself becomes a reason to sample them.

Thompson sampling
Sample theta_a ~ Beta(alpha_a, beta_a)
Choose arg max_a theta_a

This strategy explores by acting on a plausible reward-rate sample from each arm's posterior rather than by adding an explicit bonus.

Pulls
0
Cumulative reward
0.00
Regret
0.00
Average reward
0.00
Best arm now
Arm 1

Arm estimates and pull counts

Each row compares the learned estimate with the current hidden reward chance used by the simulator.

Estimated value Latent mean

Reward trail

Compare realized reward with an oracle baseline that always picks the current best arm.

History shown
0 pulls
Cumulative reward Oracle reward

Oracle gap summary

This compares oracle minus learner over the whole run and over the most recent 50 pulls.

Recent decisions

Use the log to spot when the policy commits or deliberately re-explores.

Ready