Reinforcement Learning / Modern RL
The dilemma at the heart of learning to act.
Reviewed by Yuvaraj
Every learning agent faces the same dilemma at every step: should it exploit the option that looks best given what it knows, or explore an uncertain option that might turn out better? Exploit too eagerly and you lock onto a mediocre choice forever; explore too much and you waste opportunities on options you already know are bad. This lesson studies the exploration–exploitation tradeoff in its cleanest setting, the multi-armed bandit, introduces regret as the way to measure the cost of learning, and builds up the three classic strategies: epsilon-greedy, optimism under uncertainty, and UCB. We close with why exploration becomes dramatically harder in deep RL.
Strip RL down to its simplest core and you get the multi-armed bandit: options ("arms"), each returning a random reward from an unknown fixed distribution with mean . There are no states and no transitions, just repeated choices. On each round you pull one arm and observe its reward. Your only goal is to accumulate as much reward as possible over many rounds.
This toy problem isolates the tradeoff perfectly. To find the best arm you must try each one enough to estimate its mean, that is exploration. But every round spent on an inferior arm is reward forgone, the pull that goes to information could have gone to a known-good arm. The bandit is where the tension lives with nothing else to distract from it.
Ask about this lesson, or about anything in AI. Answers cite the lessons they draw on.
Finished this lesson?
Mark it complete to earn XP, keep your streak, and schedule a review.
Why start with bandits?
Bandits are the "hydrogen atom" of RL. Real applications abound, A/B testing, ad selection, clinical trial design, recommendation, and every exploration idea used in full RL (epsilon-greedy, optimism, uncertainty bonuses) first appears here in its purest form.
How do we score an exploration strategy? Not by raw reward, that depends on the arms' values, but by regret: how much reward we lost compared to an oracle that always pulls the best arm. If the best arm has mean , the total regret after rounds is:
Every time you pull a suboptimal arm you add its gap from the best arm to the regret total. Good strategies make regret grow sublinearly, the per-round regret shrinks toward zero as you learn, while a strategy that never stops exploring uniformly (or never explores at all and got unlucky) suffers regret growing linearly forever.
Suppose two arms with true means and , so the gap is . Over rounds a strategy pulls the worse arm on of them and the best arm on the other . The regret is simply the gap times the number of mistaken pulls:
An oracle would have scored ; this strategy expects . The whole game of exploration design is driving that "6" down by making the bad-arm pulls both few and concentrated early, while still pulling enough to be sure it is worse.
The simplest workable rule. Maintain an estimate of each arm's mean. Most of the time act greedily (pick the highest estimate); occasionally, with small probability , pick a random arm to keep gathering information.
def epsilon_greedy(Q, epsilon=0.1):
if random.random() < epsilon:
return random.randrange(len(Q)) # explore: any arm
return argmax(Q) # exploit: best estimate so far
Epsilon-greedy is trivial to implement and surprisingly effective, but it has a flaw: its exploration is undirected. It is equally likely to re-test an arm it already knows is terrible as one it is genuinely unsure about. And with a fixed it keeps making random pulls forever, so its regret grows linearly. The usual fix is to decay over time, explore hard early, then increasingly exploit.
A smarter principle: be optimistic about what you have not yet tried. Initialize every arm's estimate to a high value. Then the agent, acting greedily, is naturally drawn to under-explored arms because their inflated estimates make them look attractive, until real data pulls the estimate down to its true level. Exploration becomes a built-in consequence of greedy behavior, requiring no randomness at all.
The slogan "optimism in the face of uncertainty" captures the intuition: assume the untried option might be great, try it, and let evidence correct you. Arms that really are good stay attractive; arms that are bad get demoted quickly. This directs exploration toward genuinely uncertain options instead of scattering it uniformly.
UCB makes optimism precise. Instead of a one-time optimistic initialization, it adds an explicit uncertainty bonus to each arm's estimate every round, larger for arms pulled fewer times. It then picks the arm with the highest optimistic upper bound:
where is the number of times arm has been pulled, is the current round, and tunes exploration strength. Read the two terms:
For a curious beginner
UCB judges each arm not by its average alone but by its best plausible value given how little you know. An arm you have barely tried gets the benefit of the doubt, a big bonus, so you try it. Once you have tried it a lot, the doubt shrinks and you judge it on its merits.
How it is actually used
UCB is deterministic and self-tuning: no epsilon schedule to hand-design. It concentrates exploration exactly on high-uncertainty arms, so it typically beats epsilon-greedy in the bandit setting. The bonus is cheap to compute; the main knob is c, which trades faster convergence against more aggressive early exploration.
The underlying mechanism
The bonus derives from a Hoeffding concentration bound: with high probability the true mean lies within of the empirical mean. Acting on the upper confidence bound guarantees that either you pull a near-optimal arm or you pull one whose uncertainty is large enough to be worth resolving. This yields logarithmic regret, , provably close to the optimal lower bound for the stochastic bandit.
Bandits are gentle: one decision, immediate feedback, a handful of arms. Full deep RL breaks all three assumptions, and exploration becomes one of its central open problems.
These pressures gave rise to modern methods: intrinsic motivation and curiosity (reward the agent for reaching surprising or novel states), count-based bonuses with pseudo-counts for high-dimensional states, and noise-in-parameters approaches like NoisyNets. The core principle you learned here, optimism and uncertainty-directed exploration, survives, but scaling it to rich environments remains an active research frontier.
Common mistakes