Most steps exploit the best estimate so far, while a fixed random-exploration rate prevents early lock-in.
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.
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.
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?
Greedy
The simplest algorithm: greedy. Always pull the handle whose estimate is highest. What could go wrong? The best handle pays little on its first pull. Just bad luck. Its estimate drops below an average handle. Greedy never pulls it again. Never. So it never finds out. Stuck forever on the wrong handle, regret grows in a straight line. In the real world, nobody hands you the true expectations. It would be nice. It doesn't happen. Greedy isn't stupid. It's just confident, too early.
ε-greedy
So, a small fix. And if you remember one thing from this course, remember this one. Epsilon-greedy. Seriously: the most important algorithm in the course. Most of the time, with probability one minus epsilon, pull the best-looking handle. With probability epsilon, pull any handle at random. That random pull is what saves you from getting stuck. And the random pull can land on the best handle too. With epsilon at 0.1 and ten handles, the best-looking one gets picked 91% of the time. Epsilon is the knob: zero is plain greedy, one is pure chaos.
Is it perfect?
Is it perfect? With a constant epsilon, Bit keeps exploring forever, so regret still grows in a straight line. Just a gentler one. Linear sounds bad. But who remembers running times? Linear is really fine. What you'd really like is a big epsilon at the start, that shrinks over time. That's what people do in practice. Can you know the best schedule in advance? Practically, no. You try. And if epsilon shrinks at the right speed, regret can grow much slower than a straight line.
It's everywhere
And it's everywhere. Most RL algorithms today have epsilon-greedy somewhere inside. I recently published a paper with epsilon-greedy right inside. Works great. Not because it's clever. Because it's simple, and it works.
A simulation
Here's a real simulation: ten handles, two thousand runs, averaged. Greedy settles early, on whatever it found first. Epsilon-greedy keeps learning, and pulls ahead. The exact numbers depend on the problem. The shape is the point.
Learn the policy directly
Now a different idea. Instead of estimating values, learn the policy directly. Each handle gets a preference: just a number. A softmax turns the preferences into probabilities. Why? Rewards live on an arbitrary scale. Double them, halve them, I don't care, as long as the order stays. Arbitrary scales are hard to work with. Probabilities, between zero and one, I understand. If you did deep learning: it's the same softmax as in classification. So the policy is the softmax of the preferences. Big preference, big probability.
Climb the gradient
Then we climb. Gradient ascent, not descent. Plus, not minus: we're maximising reward, so we walk up the hill. Pull a handle and get a reward. Push that handle's preference up in proportion to the reward, and the others down. Why does this climb the right hill? Picture two handles at fifty-fifty. Shift a little probability to the first: the expected reward changes by how much better the first one is. Handles that pay more climb faster. And the math has a neat trick: this gradient is something you can sample, one pull at a time. It's called the log-likelihood trick, or the REINFORCE trick, from 1992. The price: the steps are noisy. Stochastic gradient ascent.
Three ways to explore
So: greedy gets stuck. Epsilon-greedy explores on purpose. Gradient bandits learn the policy itself. Three ways to explore: none at all, at random, or by following the gradient of your own policy. And all three share one loop: pull, observe, update. Only the update changes. Next time: can we explore smarter than a coin flip? Cool?
Luck or uncertainty?
Three handles, and Bit's beliefs about each one. Red looks best on average. Green is lower, but very uncertain. If you want the highest expected reward right now, you pick red. That's the theory so far. Now suppose Bit is famously lucky. Wakes up, wins the lottery, walks into the bakery right as the croissants come out of the oven. Now which one? The wide green one: it might be amazing. We can't build on luck. But we can build on uncertainty. Why do we keep talking about expectations? Sample enough, and you get close to them. And luck is not a strategy.
Optimism
The idea is called optimism in the face of uncertainty. Don't pick what looks great. Pick what could be great. For each handle, take the estimate, plus a bonus for how unsure you are. An upper confidence bound. Pulled a lot: small bonus. Barely pulled: big bonus. So a handle wins either because it's good, or because we don't know it well yet. Does the bonus ever reach zero? Not necessarily. The world's own randomness never goes away. Notice what changed: we're not maximising the estimate anymore. We're maximising an upper bound on
Hoeffding's inequality
it. Just saying be optimistic is nice. Let's do better than nice. Hoeffding's inequality: the chance that your average plus the bonus is still below the truth shrinks exponentially, in the number of pulls, and in the bonus squared. Choose how small that chance should be, solve for the bonus, and you get a formula: the square root of the log of time, over twice the number of pulls. Time ticks on its own, and the number of pulls you control. So you can ask: how many pulls until I'm this sure? Say you want to be within 0.1, after a thousand steps. You need about 350 pulls of that handle. Within 0.01? About 35,000. Precision is expensive. And as time goes on, we keep shrinking the chance of being wrong: one over t.
The UCB algorithm
Put it together: the UCB algorithm. Pull the handle with the highest estimate plus bonus, scaled by a constant, c. With c equal to the square root of two, the regret grows only logarithmically. Logarithmic! Steep while you explore, almost flat once you know. Why does it work? Regret is the gap of each handle, times how often you pulled it. UCB makes sure that for every handle, either the gap is small, or the count is small. Big gap, few pulls. That's the whole trick. So UCB explores a lot at first, then less and less, without anyone setting a
Can anyone do better?
schedule. Can anyone do better? Lai and Robbins proved that, in the long run, no algorithm beats logarithmic regret. Nice, and not nice. You're guaranteed never to be perfect. But you know your boundaries. The bound depends on how close the handles are. Similar handles are hard to tell apart, and cost more regret.
A simulation
Same simulation as last time. Epsilon-greedy: a straight line. UCB: it bends, and flattens. Same ten handles, same two thousand runs. Only the algorithm changed.
In practice
By the way, plain greedy isn't a real method. Nobody uses it. And should you add UCB to your agent? You can't know in advance. Try it with and without. One more variant: if Bit keeps a belief for each handle, he can use the belief's spread as the bonus. Mean plus c times the spread. Greedy, epsilon-greedy, UCB: each is a different answer to the same question. How much do I explore?
Try what might be great
So: try what might be great, not just what looks great. Optimism isn't wishful thinking. It's a bonus with a proof. Next time: what if Bit keeps a whole belief instead of one number? With me so far?
A belief, not a number
So far, Bit kept one number per handle: his best guess. Today he keeps a belief. Not what the value is, but how much he believes in each possible value. If Bit believes it's 8 with 99% confidence, then practically, it's 8. A distribution over distributions. I know, it's confusing. Stay with me. Why bother? Because one number throws away how sure you are. A belief keeps it.
Win or lose: the Beta belief
Simplest case: each handle either pays one, or nothing. Win or lose. Before any pull, Bit knows nothing, so his belief is flat: every win rate from zero to one is equally likely. Win: the belief leans right. Win again: further right. Then lose, lose. If he just counted, two and two, it would look like he's back at the start. But the belief remembers. It's now a hump around one half. He knows more than when he began. This curve is called a Beta distribution. Count the wins, count the losses, and that's all you need to keep. Flat at the start is Beta one, one. Two wins and two losses later: Beta three, three. And if you're so smart that you know the right belief from the start? Start there. Everything converges much faster. Four pulls, two wins: a wide hump. Four hundred pulls, two hundred wins: a narrow spike. Same average, very different certainty.
A confession about the real world
And a confession about the real world. Outside of math, in engineering, in physics, nobody ever hands you the true distribution. We estimate it from what we observe. A belief is honest about that. And Beta is the natural belief for win-or-lose: a rate between zero and one.
Thompson sampling
Now the algorithm: Thompson sampling. It's old: 1933, older than most of computer science. Each round, every handle draws one random guess from its own belief. Bit pulls the handle with the highest guess, sees the result, and updates that belief. So a handle gets pulled about as often as Bit believes it's the best one. That's called probability matching. Unsure handles draw wild guesses, so they get tried. Handles known to be bad almost never win the draw. And for win-or-lose bandits, it matches the Lai and Robbins bound. It's optimal. No bonus to tune, no epsilon to schedule. The uncertainty does the exploring.
Watch it learn
Watch the beliefs. The best handle's curve gets narrow and tall, and wins almost every draw. Same kind of simulation: a win-or-lose bandit, two thousand runs. UCB bends. Thompson sampling bends even lower. Different paths, same lesson: explore where you're unsure, exploit where you're sure. And beliefs only narrow where Bit pulls. The bad handles stay a bit uncertain, and that's fine. They're bad.
The information state
One more idea, to close the module. We said a bandit has one state. But what Bit knows keeps changing. So treat his knowledge as part of the state: the wins and losses of every handle. Each pull moves him to a new information state. Even in a bandit, actions affect the future, through learning. Now it's a full decision problem, and you can plan to explore. It's called Bayes-adaptive RL. Optimal, in theory. Unwieldy, in practice. Every pull is worth what it pays, plus what it teaches. Planning to explore puts a price on the teaching. That's why it's rarely used directly. But it tells you what exploration is worth.
Module two, done
Two lectures in, and you already have algorithms that provably find the best handle, with only logarithmic regret along the way. That some of them would finish after the universe collapses into itself? That's another conversation. Because a bandit has one state, and real problems have many. In chess, I take your queen, and on the next move, you checkmate me. Next module: states, and consequences. So, module two in one line: explore where you're unsure, exploit where you're sure. With me so far? See you in module three.
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.
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.
Arms with less data receive a larger confidence bonus, so uncertainty itself becomes a reason to sample them.
This strategy explores by acting on a plausible reward-rate sample from each arm's posterior rather than by adding an explicit bonus.
Arm estimates and pull counts
Each row compares the learned estimate with the current hidden reward chance used by the simulator.
Reward trail
Compare realized reward with an oracle baseline that always picks the current best arm.
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.




