Thompson Sampling
Pick each arm with the probability that it is the best, by sampling from beliefs.
The idea
Keep a posterior distribution over each arm's success rate (for coin-like rewards, a Beta distribution). Each round draw one sample from every arm's posterior and play the arm with the highest sample. Uncertain arms produce widely varying samples, so they get explored, and good arms soon dominate.
θᵢ ~ Beta(αᵢ, βᵢ), play argmax θᵢ
Watch it run
This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.
- estimated value
- true value (dashed)
- arm just pulled
Pull 1: Draw one plausible value for each arm from its belief and play the best draw. Uncertain arms get drawn high often enough to be tested. Got reward 1.29.
- pulls:
- 1
- regret:
- 0.58
Bars are what the agent believes; dashed lines are the truth it is trying to discover.
Step by step
- 1Start every arm with a Beta(1, 1) prior.
- 2Sample a value from each arm's distribution.
- 3Pull the arm with the largest sample.
- 4Update that arm's Beta with the success or failure.
Where it is used
Online experiments, recommendation and ad placement.
Watch out for
Needs a sensible prior and a conjugate or approximate posterior.