TL;DR
An epsilon-greedy policy is a rule for choosing actions. With probability it picks the action with the highest estimated value, and with probability it picks an action uniformly at random. The small random share keeps the agent trying options it has not yet learned enough about, so it does not lock onto an early lucky choice.
Builds on: Value Function, Multi-Armed Bandit, Uniform Distribution · Leads to: Deep Q-Network, Double Q-Learning
Where it's used
Learning to play Atari games. The deep Q-network of 2015 learned to play dozens of Atari games from screen pixels. Its agent chose actions with an epsilon-greedy rule, and it started with near 1 (almost every action random) and lowered it over the first part of training. Early in training the agent knows little, so random play gathers the experience it needs.
Recommendations and ads. A system that shows one item from a set has estimated click rates for each item. Showing only the best-known item stops it finding out whether a new item is better. Showing the best item most of the time, and a random item a small share of the time, keeps the estimates improving while still earning most of the clicks.
Textbook reinforcement learning. Tabular Q-Learning on small grid worlds is usually taught with a fixed such as 0.1. It is the default exploration rule in many introductory examples, because it works with any method that estimates action values.
How it works
Take an agent with three actions, A, B and C. Its current estimates of their values are , and . Set .
- Find the greedy action. The highest estimate is , so B is the greedy action. Check: no other estimate is above 0.8.
- Decide whether to explore. Draw a random number between 0 and 1. If , explore. Otherwise exploit. Check: exploring happens in about one step in five.
- If exploring, pick at random. Each of A, B and C gets probability one third. Check: the three probabilities add to 1.
- If exploiting, pick B. Check: the agent now takes the action with the highest estimate.
- Combine the two branches. The chance of picking B is the chance of exploiting (0.8) plus the chance that exploring picks B (0.2 times one third): 0.8 + 0.0667 = 0.8667. The chance of picking A is 0.2 times one third, about 0.0667, and the same for C. Check: 0.8667 + 0.0667 + 0.0667 = 1.
The picture: with a large , the policy is close to random; with , it is purely greedy, and it never tries anything but its current favourite.
The math
Step 2 in symbols: the exploration coin
Let be the exploration rate. The policy can be written as a mixture of two distributions:
Here is 1 when its condition is true and 0 otherwise. The first term is the exploit branch; the second is the explore branch, a uniform draw over the actions. The probabilities add to 1, because .
Step 5 in symbols: the example
With , and :
Check: .
Why a fixed epsilon costs something
Suppose the agent acts for steps with a fixed . About of those steps are random, whatever the agent has learned. If the best action is worth and the policy's average value is , the total shortfall against always playing the best action is about . For a policy that explores a fixed share of the time, stays positive, so the shortfall grows in proportion to . This accumulated shortfall is called the regret. A fixed- rule has linear regret, meaning regret proportional to ; the bandit setting in which regret is defined is covered in Multi-Armed Bandit.
A decaying schedule such as lets the exploration share shrink, so the shortfall grows more slowly.
Worked examples
- Actions L and R. Estimates and . Set .
- The greedy action is L.
- The chance of L is .
- The chance of R is .
- Check: .
Interpretation: the policy takes the better action 95 times in 100, and the other action 5 times in 100.
- Four actions with true values , , and . Assume the estimates are correct and set .
- The greedy action is 2, with value 3.5.
- Its probability is .
- Each of actions 1, 3 and 4 has probability .
- Check: .
- Expected reward of the policy: .
- A purely greedy policy would earn 3.5, so exploring costs per step.
Interpretation: the cost of exploring is small per step, but it is paid every step for as long as stays fixed.
- A shop shows one of three items. Estimated click rates are 0.12, 0.08 and 0.05. The best item has rate 0.12. Set .
- The probability of showing the best item is .
- Each other item is shown with probability .
- Expected clicks per 1000 impressions: for the best item, plus for the others. Total: , or about 116 clicks per 1000.
- A purely greedy shop would earn clicks per 1000.
- The exploration costs about 4 clicks per 1000 impressions, and in return the shop keeps learning whether the other items have improved.
- Try it: with , how often is the best item shown? Answer: , so the best item is shown 80 times in 100.
Common mistakes and tradeoffs
It is tempting to think is the chance of picking the best action. In fact the best action gets plus its share of the random draws, so the greedy action is chosen more often than and each other action gets divided by the number of actions.
It is tempting to think a fixed is a good setting forever. In fact a fixed rate keeps paying the exploration cost after the agent knows its options well. A schedule that lowers over time, such as the decay in the Atari example, usually does better in the long run.
It is tempting to think random exploration is always informative. In fact in tasks with sparse rewards, where most random actions earn nothing, epsilon-greedy explores almost uselessly. Methods that use uncertainty, such as the UCB rule or Thompson sampling in Multi-Armed Bandit, direct exploration to the actions that are least known.
Epsilon-greedy is a good choice when the action set is small or moderate, the value estimates are reasonable, and you want a rule with one knob that is easy to explain and debug. It is a poor choice when rewards are rare, when actions are very numerous, or when a bad random action is costly, such as in a physical robot. In those cases use a directed exploration method or a rule that explores by uncertainty.
History
The problem is old: a bandit player must decide whether to use what they know or try something new, and the early work on this trade-off goes back to the 1930s and to Robbins's 1952 paper on sequential choice. Epsilon-greedy as a named rule became standard in reinforcement learning through the textbook Reinforcement Learning: An Introduction by Sutton and Barto, whose first edition appeared in 1998. Its simplicity and the single knob made it the default exploration rule for early Q-Learning experiments.
It stayed popular when function approximators replaced tables. The 2013 and 2015 Atari papers on deep Q-networks used it with a decaying , and the rule is still a baseline against which newer exploration methods are compared.
Recap
- An epsilon-greedy policy picks the highest-valued action with probability and a uniformly random action with probability .
- The chance of the greedy action is , and each other action gets .
- A fixed gives a steady exploration cost, which grows linearly with the number of steps.
- Decaying over training is the usual fix, as in the Deep Q-Network.
- Read next: Double Q-Learning, which changes how the action values are estimated, and Reinforcement Learning for the wider setting.