Skip to content
StackDecode
AI & ML Atlas
Reinforcement LearningalgorithmInteractive simulation

Upper Confidence Bound (UCB)

Choose the action whose average reward plus an uncertainty bonus is highest.

The idea

"Optimism in the face of uncertainty." Each arm is scored by its mean reward plus a bonus that is large for arms tried few times. Rarely tried arms get a big bonus and so are tried; as an arm is sampled its bonus shrinks. UCB1 achieves logarithmic regret without any randomness.

UCB = x̄ᵢ + c·√(ln t / nᵢ)

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

total regret (reward lost by not always playing the best arm)pulled 1×arm 1pulled 0×arm 2pulled 0×arm 3pulled 0×arm 4pulled 0×arm 5
  • estimated value
  • true value (dashed)
  • arm just pulled

Pull 1: Arm 1 has never been tried, so its bonus is infinite: try it. Got reward 1.06.

pulls:
1
regret:
0.84
1/40

Bars are what the agent believes; dashed lines are the truth it is trying to discover.

Step by step

  1. 1Pull each arm once.
  2. 2For every arm compute mean + c·√(ln t / nᵢ).
  3. 3Pull the arm with the highest score.
  4. 4Update its count and mean; repeat.

Where it is used

A/B testing, ad selection, and tree search (UCT in MCTS).

Watch out for

Assumes rewards are stationary and the constant c needs tuning.

Related