Reinforcement Learning Lab

Eight reinforcement-learning labs: classical, deep, policy optimisation, bandits, planning and multi-agent, with experiments trained for real in your browser.

39interactive experiments

UCB and Thompson Sampling

Multi-Armed Bandits · bandits

Learning objectives

  • Compute the UCB1 bound.
  • Understand sampling from a belief.

The idea

UCB adds an exploration bonus that is large for rarely pulled arms and picks the most optimistic.

Explanation

Thompson keeps a belief (posterior) per arm, draws a sample from each and plays the highest; uncertain arms get a chance automatically. Both achieve logarithmic regret under standard conditions.

Equations

A_t=\arg\max_a\Big[\hat\mu_a+c\sqrt{\tfrac{\ln t}{N_a}}\Big]

c scales the optimism; the original UCB1 uses a fixed constant.

Worked example

μ̂=(0.5, 0.4), N=(10, 2), t=12, c=1: bonuses √(ln12/10)=0.50 and √(ln12/2)=1.11, so the second wins (1.51 vs 1.00).

Common mistakes

A large c over-explores.

Assuming the wrong distribution in Thompson.

Summary

UCB is optimism under uncertainty; Thompson samples from belief.

Related experiments

Assessment questions

References

  1. Auer, P.; Cesa-Bianchi, N.; Fischer, P. (2002). Finite-time analysis of the multiarmed bandit problem. Machine Learning 47:235-256. doi:10.1023/a:1013689704352