TL;DR
When you learn from your own choices, you only learn about the options you try. So an agent faces a dilemma. To earn the most reward now it should use the option it currently rates best (exploit). To find out whether another option is better it must try options it rates lower (explore), and that can cost reward. Every choice does a little of both, and the agent has to decide how much of each to do.
Builds on: Multi-Armed Bandit, Reinforcement Learning · Leads to: exploration bonuses in deep reinforcement learning, such as curiosity-based rewards, and adaptive experiments that shift traffic toward the better option
Where it's used
Choosing what to show. A news site or video platform must pick which item to place on the front page. Showing only the item with the highest click rate so far means newer items never get clicks, so the platform never learns whether they are better. Showing them some of the time costs clicks now and buys information for later. Recommender systems face this trade constantly.
Comparing versions of a product. When two page designs are tested, the usual experiment splits traffic evenly for a fixed time and then picks a winner. An adaptive version sends more traffic to the design that looks better as data arrives. It earns more during the test, but the decision it reaches is only as trustworthy as the evidence it gathered while shifting traffic.
Game-playing agents. In games where the reward appears only after a long chain of actions, a reinforcement-learning agent that only exploits never discovers the rewards at all. This is a sparse reward problem. Researchers add an intrinsic reward, a bonus for visiting new states, which pays the agent to explore. The bonus is then gradually weighed against the true reward.
How it works
Take two slot machines, A and B. The agent does not know their payouts. Suppose that, unknown to the agent, A pays on average and B pays on average . The agent keeps a running average of what each machine has paid, starting from for both.
- Round 1, no information yet. Both averages are , so the agent breaks the tie and plays A. A pays this time. Now A's average is and B's is .
- Round 2, exploit. The agent plays the machine with the higher average, A. It pays . A's average falls to . B is still at .
- Round 3, exploit again. A is still higher, so the agent plays A. It pays . A's average is .
- The trap. B's average is still , and A's is positive, so a purely exploiting agent never plays B again. It has learned very little: it knows A paid something, and it does not know that B pays more than twice as much on average.
- Round 4, explore. Now suppose the agent sometimes plays a random machine, and on this round it picks B. B pays . B's average becomes , above A's , and the agent is finally pointed at the better machine.
The lesson: exploiting gives the best reward for the information you have, but that information is incomplete. Exploring gives the information, at the price of the reward it might have earned from the machine you already knew.
flowchart LR
A[Current estimates of each option] --> B{Exploit or explore?}
B -- exploit --> C[Pick the best-looking option]
B -- explore --> D[Pick an uncertain option]
C --> E[Observe reward]
D --> E
E --> F[Update estimates]
F --> A
The math
Setup
There are options, called arms. Arm has an unknown expected reward . The best arm has value , and the gap of arm is . The agent keeps an estimate , the average reward it has seen from arm before round . These are the running averages of the walkthrough, written as symbols: the trap in step 4 is what the rule below must avoid, and the exploring round in step 5 is the cost it pays.
The cost of a choice
If the agent picks arm in one round, its expected loss compared with always picking the best arm is . This is the cost of exploring when is not the best arm, and it is zero when the agent picks the best arm.
Over rounds the total loss is called regret:
where is the random reward in round and is the number of times arm was picked. The second form shows the tradeoff directly: regret grows when the agent pulls arms with large gaps too often, and it grows if the agent pulls the best arm too rarely to learn which it is. See Multi-Armed Bandit for the full analysis of regret.
A rule that balances the two
The simplest rule, called greedy, sets . It always exploits. In the slot-machine trace above, the greedy rule never plays B. B's estimate stays at , and A's estimate stays above it for as long as A keeps paying at least something. The rule is trapped on A.
An epsilon-greedy rule fixes this with one parameter between and . In each round:
- with probability , pick an arm uniformly at random (explore);
- with probability , pick (exploit).
The expected loss from the exploring rounds is worked out as follows. A uniform random pick over arms loses on average , which we write as , the mean gap. So the exploration cost per round is . The exploiting rounds add a cost only when the estimates point to the wrong arm, which is what the agent must keep small by learning.
Why the estimates converge
Each is a sample average. By the Law of Large Numbers, it moves toward as the number of pulls of grows. An arm that is never pulled never gets an estimate, which is why exploration is needed at all.
Worked examples
Arm A has expected reward , so its gap is . Arm B has expected reward , so its gap is .
- Plan 1: pick A in both rounds. Each pick loses , so the regret is .
- Plan 2: pick A once and B once. The A pick loses ; the B pick loses . The regret is .
- Plan 3: pick B in both rounds. The regret is .
- Compare: Plan 1 is the worst, Plan 3 is the best. Plan 2 lies between, and it is the only plan that gathers information about both arms.
- Interpretation: if you knew the gaps you would pick B from the start, but you do not, so a plan that tries both is a reasonable compromise.
Note the calculation uses the true values, which the agent cannot see; the agent only sees its estimates.
Use the two arms of the first example: and . Set and play for rounds.
- The mean gap is .
- Exploration cost per round is .
- Over rounds, the exploration cost is .
- Check by direct count: in an exploring round the arm is A with probability , losing , so the expected loss is . Exploring happens in of rounds, so the cost per round is . The two methods agree.
- Interpretation: the random exploration adds 20 units of regret over 1000 rounds, and this is the price of learning about A. The greedy errors in the exploiting rounds come on top of this and are not included in the 20.
If is fixed, the exploration cost grows in a straight line with . This is the main weakness of the simple rule.
A news site has four headlines. Their true click rates are unknown to the editors: , , and . The site receives 10,000 impressions per day and uses epsilon-greedy with .
- The best headline has rate . The gaps are , , , and .
- The mean gap is .
- Exploration cost per impression is .
- Over 10,000 impressions, the exploration cost is clicks per day.
- Interpretation: about 32 clicks a day are the price of the exploration. A policy that never shows the weaker headlines would earn those clicks, but it could never learn that the headline is the best one if it started with a weaker headline in front.
Try it: the site lowers to and its traffic rises to 20,000 impressions per day, with the same four headlines. How many clicks per day are lost to exploration, counting only the exploring rounds? Answer: per impression, and clicks per day.
Common mistakes and tradeoffs
"Once an option has a high estimate, it is the best one." It is tempting to think a high average means a good option. In fact an average built from a few lucky draws can be far above the truth, as the first slot machine in the trace shows: one payout of made A look best, while its true mean is . Estimates from few samples need more exploration, not less.
"Exploring is always wasted reward." Exploration costs reward in the short run, but it is the only source of information about options you have not tried. Over a long horizon, a small amount of exploration usually pays for itself. Over a very short horizon, it may not, and then exploiting is the right choice.
"Random exploration is the only way." Uniform random exploration is the simplest rule, not the best one. Methods that explore in a directed way do better: an optimistic rule such as UCB1 adds a bonus to options whose estimates are uncertain, so rarely tried options look attractive until they are tested. Epsilon-greedy is the simplest rule of this kind. Bayesian Thompson sampling keeps a probability distribution over each option's value (for a click rate, usually a Beta distribution), draws one sample from each, and plays the option whose draw is highest; options that are probably best get played, and uncertain ones still get tried.
When to use a fixed exploration rate. A fixed is easy to implement and to explain, and it keeps adapting if the world changes. Its drawback is the linear cost noted in the second example.
When not to use it. If the options are known in advance, or if the horizon is so short that learning cannot pay back, exploration only costs reward. If the environment changes over time, some ongoing exploration is needed even after the estimates settle.
History
Herbert Robbins framed the sequential problem in 1952, and the question of how to allocate trials between alternatives was studied for decades before a practical rule emerged. William Thompson had proposed a rule for choosing between two treatments in 1933, which is now called Thompson sampling. In the late 1970s John Gittins showed that a simple index policy solves a discounted version of the problem exactly.
The idea caught on in computing when it became clear that websites, advertising systems and games could learn from their own actions. Reinforcement learning made the same dilemma central: an agent must explore the states it has not visited before it can know their values. Modern methods combine simple rules such as epsilon-greedy with bonuses for novelty, which are the descendants of the early studies.
Recap
- Learning from your own choices forces a choice between exploiting the best-looking option and exploring others.
- Greedy play always exploits, and it can lock onto an early lucky option forever.
- Epsilon-greedy explores a fraction of the time, at an expected cost of per round.
- Regret, , measures the total cost of the balance.
- Read next: Multi-Armed Bandit for regret bounds and directed exploration, and Intrinsic Reward for exploration bonuses in reinforcement learning.
Check yourself
QuestionRecall: what does a purely greedy agent do, and why can it get stuck?Show answer
It always picks the option with the highest current estimate. If the early estimates are noisy and an option that is actually worse looks best, the agent keeps picking it, the other options are never tried, and their estimates never improve. It stays trapped on a suboptimal option.
QuestionCompute: the mean gap over all arms is . An epsilon-greedy agent uses over rounds. What is its expected exploration cost?Show answer
The exploration cost per round is . Over 500 rounds it is .
QuestionWhy: why does the exploration cost of epsilon-greedy grow linearly with the number of rounds?Show answer
Because the agent explores a fixed fraction of the rounds forever, and each exploring round costs on average regardless of how much the agent already knows. The total cost is therefore proportional to . Rules that reduce exploration as the estimates become confident avoid this.
QuestionApplied: a music app has two playlists whose true listen rates differ by a wide margin, and it has run for only a day with few plays of each. Should the app exploit the playlist that is ahead or keep exploring, and why?Show answer
It should keep exploring. With few plays, the lead is probably noise, and a fixed playlist can look best by luck. The app has a long horizon ahead, so information gathered now pays off for many future sessions. Exploitation is the right choice once the estimates are reliable enough that the gap is clear.