Back to BlogGuide

Epsilon-Greedy vs Thompson Sampling vs UCB1: Choosing the Right Algorithm

5 min read

Three Algorithms, One Goal

Every multi-armed bandit algorithm tries to solve the same problem: maximize total reward by balancing exploration and exploitation. But they approach this trade-off with fundamentally different strategies.

Epsilon-Greedy uses randomness. UCB1 uses optimism. Thompson Sampling uses probability. Each philosophy leads to different behavior in practice, and the right choice depends on your specific situation.

Epsilon-Greedy

  • Strategy: randomness
  • Explores a random arm with probability epsilon (default 0.1)
  • Requires tuning the epsilon parameter
  • Linear regret bound

UCB1

  • Strategy: optimism
  • Picks the arm with the highest upper confidence bound
  • No tuning parameters, fully deterministic
  • Logarithmic regret bound

Thompson Sampling

  • Strategy: probability
  • Samples from each arm's Beta distribution and picks the highest
  • No tuning parameters, adapts to non-stationary data
  • Logarithmic regret bound, lowest empirical regret
The three core strategies for balancing exploration and exploitation

Epsilon-Greedy: The Simple Baseline

Epsilon-Greedy is the most intuitive bandit algorithm. With probability 1 - epsilon, it picks the arm with the highest observed reward (exploit). With probability epsilon, it picks a random arm (explore).

How it works:

  1. Generate a random number between 0 and 1
  2. If the number is less than epsilon (default 0.1), pick a random arm
  3. Otherwise, pick the arm with the highest average reward

Strengths:

  • Dead simple to implement and explain
  • Predictable exploration rate
  • Works with any reward distribution

Weaknesses:

  • Explores uniformly, wasting pulls on clearly bad arms
  • The epsilon parameter needs tuning (too high = too much exploration, too low = gets stuck)
  • Never stops exploring, even when the best arm is obvious

Tip

Epsilon-Greedy is a good starting point if you need to explain the algorithm to non-technical stakeholders. Its behavior is easy to reason about: "We show the best variant 90% of the time and try random variants 10% of the time."

UCB1: Optimism Under Uncertainty

UCB1 (Upper Confidence Bound) takes a different approach. For each arm, it computes an upper confidence bound on the true reward and picks the arm with the highest bound. Arms with less data get wider bounds, so they get explored. Arms with lots of data have tight bounds that reflect their true performance.

The UCB1 formula:

For each arm, the score is: average_reward + sqrt(2 * ln(total_pulls) / arm_pulls)

The first term is exploitation (observed performance). The second term is an exploration bonus that shrinks as you gather more data for that arm.

Strengths:

  • Zero tuning parameters
  • Deterministic: same data always produces the same choice
  • Strong theoretical regret guarantees (logarithmic regret)

Weaknesses:

  • Deterministic behavior can be a liability in non-stationary environments
  • Explores more aggressively than necessary in practice
  • Confidence bounds assume sub-Gaussian rewards
Exploration bonus: sqrt(2 * ln(total_pulls) / arm_pulls)
Observed average reward (exploitation term)
score contributionarm_pulls
UCB1 balances observed reward with an exploration bonus that shrinks over time

Thompson Sampling: Bayesian Probability Matching

Thompson Sampling maintains a probability distribution over each arm's true reward rate. At each step, it samples from each distribution and picks the arm with the highest sample. Arms with more uncertainty produce more variable samples, so they get explored naturally.

How it works (binary outcomes):

  1. For each arm, maintain a Beta distribution: Beta(successes + 1, failures + 1)
  2. Sample a value from each arm's distribution
  3. Pick the arm with the highest sampled value
  4. Update the selected arm's distribution with the outcome

Strengths:

  • No tuning parameters
  • Naturally concentrates exploration on uncertain arms
  • Lowest empirical regret across most scenarios
  • Adapts well to non-stationary environments (due to stochastic selection)

Weaknesses:

  • Requires choosing a prior distribution (Beta for binary, Normal for continuous)
  • Slightly more complex to implement than Epsilon-Greedy
  • Stochastic behavior makes exact reproducibility harder
Early: Beta(2, 2) after a few trials
Later: Beta(80, 40) after many trials
Thompson Sampling narrows uncertainty as data accumulates, shifting from exploration to exploitation

Head-to-Head Comparison

PropertyEpsilon-GreedyUCB1Thompson Sampling
Tuning requiredYes (epsilon)NoNo
Exploration strategyRandomOptimisticProbabilistic
DeterministicNoYesNo
Regret boundLinearLogarithmicLogarithmic
Empirical regretHighestMediumLowest
Non-stationary environmentsPoorPoorGood
Implementation complexityTrivialSimpleModerate
Cold start behaviorRandom explorationAggressive explorationBalanced exploration

Try It Yourself

The simulator below lets you run all three algorithms side by side against the same set of arms. Adjust the true conversion rates, set the number of rounds, and watch how each algorithm allocates traffic and accumulates regret.

Multi-Armed Bandit Simulator

Total: 0Rewards: 0

Things to experiment with:

  • Close conversion rates (e.g., 48% vs 52%): Thompson Sampling's advantage is most visible here
  • One dominant arm (e.g., 80% vs 20% vs 15%). All algorithms converge quickly, but Epsilon-Greedy wastes the most traffic
  • Many arms (5+), where UCB1's aggressive exploration becomes costly and Thompson Sampling scales better
Epsilon-Greedy (linear regret)
UCB1 (logarithmic regret)
Thompson Sampling (logarithmic, lowest empirical regret)
cumulative regretrounds (0 to 10,000)
Cumulative regret comparison across 10,000 rounds with 3 arms

Decision Framework

Choose Epsilon-Greedy when:

  • You need the simplest possible implementation
  • You want a predictable, fixed exploration rate
  • The problem is easy (large separation between arms)
  • You need to explain the algorithm to non-technical audiences

Choose UCB1 when:

  • You want deterministic behavior (important for debugging and reproducibility)
  • You prefer strong theoretical guarantees
  • The environment is stationary (reward rates don't change)
  • You don't want to tune any parameters

Choose Thompson Sampling when:

  • You want the best empirical performance (lowest regret)
  • The differences between variants are small
  • The environment might be non-stationary
  • You're working with binary outcomes (conversion, click, signup)
  • You want exploration to diminish naturally as confidence grows

Note

The Bandit platform supports all three algorithms. When creating an experiment, you can select the algorithm in the experiment settings. If you're unsure, Thompson Sampling is the recommended default for most web optimization use cases.

The Practical Answer

For most teams optimizing web experiences, Thompson Sampling is the best default. It requires no tuning, produces the lowest regret, and handles the messy realities of production environments (changing user behavior, seasonal effects, new variants) better than the alternatives.

Use UCB1 when you need determinism. Use Epsilon-Greedy when you need simplicity. Use Thompson Sampling when you need results.

Epsilon-Greedy

  • Simplest possible implementation
  • Predictable, fixed exploration rate
  • Easy problems with large separation between arms
  • Needs to be explained to non-technical audiences

UCB1

  • Deterministic behavior for debugging and reproducibility
  • Strong theoretical guarantees
  • Stationary environment (reward rates don't change)
  • No parameters to tune

Thompson Sampling

  • Best empirical performance (lowest regret)
  • Small differences between variants
  • Possibly non-stationary environment
  • Binary outcomes: conversion, click, signup
Algorithm selection flowchart based on your optimization requirements

Ready to try algorithmic testing?

Stop wasting traffic on losing variants. Bandit's multi-armed bandit algorithms automatically shift traffic to your best-performing treatments in real time.

Get Started Free
All articles
Epsilon-Greedy vs Thompson Sampling vs UCB1: Choosing the Right Algorithm — Bandit