Search

Search papers and lessons

Exploration–Exploitation Tradeoff

Level 3 · 12 min read

An agent that learns from its own choices must either use the option it currently thinks is best (exploit) or try others to learn more (explore); every choice does a little of both, so the agent must balance them.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Reinforcement learning
  • Linear algebra
  • Stochastic processes
  • ReadReady to readNot yet

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 0.30.3 and B pays on average 0.70.7. The agent keeps a running average of what each machine has paid, starting from 00 for both.

  1. Round 1, no information yet. Both averages are 00, so the agent breaks the tie and plays A. A pays 11 this time. Now A's average is 11 and B's is 00.
  2. Round 2, exploit. The agent plays the machine with the higher average, A. It pays 00. A's average falls to (1+0)/2=0.5(1 + 0)/2 = 0.5. B is still at 00.
  3. Round 3, exploit again. A is still higher, so the agent plays A. It pays 00. A's average is (1+0+0)/3=1/3(1 + 0 + 0)/3 = 1/3.
  4. The trap. B's average is still 00, 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.
  5. Round 4, explore. Now suppose the agent sometimes plays a random machine, and on this round it picks B. B pays 11. B's average becomes 11, above A's 1/31/3, 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 KK options, called arms. Arm aa has an unknown expected reward q(a)q(a). The best arm has value q∗=max⁡aq(a)q^* = \max_a q(a), and the gap of arm aa is Δa=q∗−q(a)\Delta_a = q^* - q(a). The agent keeps an estimate Qt(a)Q_t(a), the average reward it has seen from arm aa before round tt. 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 aa in one round, its expected loss compared with always picking the best arm is Δa\Delta_a. This is the cost of exploring when aa is not the best arm, and it is zero when the agent picks the best arm.

Over TT rounds the total loss is called regret:

RT=Tq∗−E[∑t=1Trt]=∑aΔa E[na(T)],R_T = T q^* - \mathbb{E}\Big[\sum_{t=1}^{T} r_t\Big] = \sum_a \Delta_a\, \mathbb{E}[n_a(T)],

where rtr_t is the random reward in round tt and na(T)n_a(T) is the number of times arm aa 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 at=arg⁡max⁡aQt(a)a_t = \arg\max_a Q_t(a). It always exploits. In the slot-machine trace above, the greedy rule never plays B. B's estimate stays at 00, 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 ε\varepsilon between 00 and 11. In each round:

  • with probability ε\varepsilon, pick an arm uniformly at random (explore);
  • with probability 1−ε1 - \varepsilon, pick arg⁡max⁡aQt(a)\arg\max_a Q_t(a) (exploit).

The expected loss from the exploring rounds is worked out as follows. A uniform random pick over KK arms loses on average 1K∑aΔa\frac{1}{K}\sum_a \Delta_a, which we write as Δˉ\bar\Delta, the mean gap. So the exploration cost per round is εΔˉ\varepsilon \bar\Delta. 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 Qt(a)Q_t(a) is a sample average. By the Law of Large Numbers, it moves toward q(a)q(a) as the number of pulls of aa grows. An arm that is never pulled never gets an estimate, which is why exploration is needed at all.

Worked examples

Example
1. Two arms, two rounds, hand-computable

Arm A has expected reward 0.30.3, so its gap is ΔA=0.7−0.3=0.4\Delta_A = 0.7 - 0.3 = 0.4. Arm B has expected reward 0.70.7, so its gap is 00.

  1. Plan 1: pick A in both rounds. Each pick loses ΔA=0.4\Delta_A = 0.4, so the regret is 0.4+0.4=0.80.4 + 0.4 = 0.8.
  2. Plan 2: pick A once and B once. The A pick loses 0.40.4; the B pick loses 00. The regret is 0.40.4.
  3. Plan 3: pick B in both rounds. The regret is 00.
  4. 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.
  5. 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.

Example
2. Standard case: the cost of epsilon-greedy with two arms

Use the two arms of the first example: ΔA=0.4\Delta_A = 0.4 and ΔB=0\Delta_B = 0. Set ε=0.1\varepsilon = 0.1 and play for T=1000T = 1000 rounds.

  1. The mean gap is Δˉ=(0.4+0)/2=0.2\bar\Delta = (0.4 + 0) / 2 = 0.2.
  2. Exploration cost per round is εΔˉ=0.1×0.2=0.02\varepsilon \bar\Delta = 0.1 \times 0.2 = 0.02.
  3. Over T=1000T = 1000 rounds, the exploration cost is 0.02×1000=200.02 \times 1000 = 20.
  4. Check by direct count: in an exploring round the arm is A with probability 1/21/2, losing 0.40.4, so the expected loss is 0.5×0.4=0.20.5 \times 0.4 = 0.2. Exploring happens in 0.10.1 of rounds, so the cost per round is 0.1×0.2=0.020.1 \times 0.2 = 0.02. The two methods agree.
  5. 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 ε\varepsilon is fixed, the exploration cost grows in a straight line with TT. This is the main weakness of the simple rule.

Example
3. Realistic: choosing a headline

A news site has four headlines. Their true click rates are unknown to the editors: 0.050.05, 0.080.08, 0.120.12 and 0.100.10. The site receives 10,000 impressions per day and uses epsilon-greedy with ε=0.1\varepsilon = 0.1.

  1. The best headline has rate 0.120.12. The gaps are 0.12−0.05=0.070.12 - 0.05 = 0.07, 0.12−0.08=0.040.12 - 0.08 = 0.04, 00, and 0.12−0.10=0.020.12 - 0.10 = 0.02.
  2. The mean gap is Δˉ=(0.07+0.04+0+0.02)/4=0.13/4=0.0325\bar\Delta = (0.07 + 0.04 + 0 + 0.02)/4 = 0.13/4 = 0.0325.
  3. Exploration cost per impression is εΔˉ=0.1×0.0325=0.00325\varepsilon \bar\Delta = 0.1 \times 0.0325 = 0.00325.
  4. Over 10,000 impressions, the exploration cost is 0.00325×10000=32.50.00325 \times 10000 = 32.5 clicks per day.
  5. 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 0.120.12 headline is the best one if it started with a weaker headline in front.

Try it: the site lowers ε\varepsilon to 0.020.02 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: 0.02×0.0325=0.000650.02 \times 0.0325 = 0.00065 per impression, and 0.00065×20000=130.00065 \times 20000 = 13 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 11 made A look best, while its true mean is 0.30.3. 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 ε\varepsilon 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 ε\varepsilon of the time, at an expected cost of εΔˉ\varepsilon \bar\Delta per round.
  • Regret, RT=∑aΔaE[na(T)]R_T = \sum_a \Delta_a \mathbb{E}[n_a(T)], 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 Δˉ=0.25\bar\Delta = 0.25. An epsilon-greedy agent uses ε=0.2\varepsilon = 0.2 over T=500T = 500 rounds. What is its expected exploration cost?Show answer

The exploration cost per round is εΔˉ=0.2×0.25=0.05\varepsilon \bar\Delta = 0.2 \times 0.25 = 0.05. Over 500 rounds it is 0.05×500=250.05 \times 500 = 25.

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 ε\varepsilon of the rounds forever, and each exploring round costs on average Δˉ\bar\Delta regardless of how much the agent already knows. The total cost is therefore proportional to TT. 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.

Sources