UCB & UCT
The selection phase of MCTS lives or dies on the exploration–exploitation tradeoff: spend too much time on the best-looking branch and you miss a better one; spread compute uniformly and you barely make progress on the best line. UCB1 is the simplest principled answer.
The Multi-Armed Bandit Setup
Section titled “The Multi-Armed Bandit Setup”Forget trees for a moment. Imagine slot machines (“arms”), each returning rewards from an unknown distribution with mean . You have pulls. Goal: maximize total reward — equivalently, minimize regret relative to always pulling the best arm.
A purely greedy strategy (pull the arm with the highest current sample mean) can lock onto a suboptimal arm forever. A purely uniform strategy wastes pulls on obviously bad arms. UCB1 is the elegant middle.
For each arm after total pulls, with pulls of that arm and sample mean :
Pull .
| Term | Role |
|---|---|
| Exploit — what we currently believe | |
| Explore — confidence radius shrinks as grows | |
| Knob trading off the two |
The bound comes from Hoeffding’s inequality: with high probability, the true mean lies within . Picking the arm with the highest upper bound is the principle of “optimism in the face of uncertainty” — try things that might be better, weighted by how plausible that is.
Regret bound. UCB1 achieves , which matches the lower bound up to log factors — you can’t do much better without distributional assumptions.
UCT: UCB Applied to Trees
Section titled “UCT: UCB Applied to Trees”UCT (Kocsis & Szepesvári, 2006) is “UCB applied to Trees”: at every internal node of the MCTS tree, treat the children as a bandit problem and use UCB1 to pick which to descend into.
The first term is the empirical mean reward through that edge; the second is the exploration bonus shrinking with visits.
For a two-player zero-sum game with rewards in (win-rate), the conventional choice is . For other reward ranges, scale to match — the exploration term must be the same order of magnitude as the empirical mean, or one term dominates and you collapse to pure exploit or pure explore.
Worked Numerical Example
Section titled “Worked Numerical Example”Imagine an MCTS node with three children. After 10 root iterations:
| Child | |||
|---|---|---|---|
| A | 6 | 4.0 | 0.667 |
| B | 3 | 1.2 | 0.400 |
| C | 1 | 0.8 | 0.800 |
With and :
UCT picks C, even though A has the best empirical mean. Why? C has only been tried once — its confidence interval is huge, and we cannot rule out that it’s the best. After C is sampled a few more times its exploration bonus shrinks, and selection naturally redistributes.
This is the magic of UCB: the most-visited node is the one we are most confident is best, not necessarily the one with the highest mean right now.
Interactive: Tweak Your Own Scenario
Section titled “Interactive: Tweak Your Own Scenario”Edit the visit counts and reward totals to construct edge cases. Slide c to watch which arm wins under different exploration regimes.
Practical Tweaks
Section titled “Practical Tweaks”Real MCTS implementations rarely use plain UCT. Three common modifications:
FPU (First-Play Urgency). A child with has an undefined exploitation term. Set it to a sensible default — sometimes the parent’s value, sometimes a fixed optimistic constant.
PUCT (Predictor + UCT). Add a prior probability from a learned policy network:
This is what AlphaZero uses. The prior biases search toward moves the policy net thinks are good, dramatically improving sample efficiency in deep trees. Note the missing — the form is the “PUCT-variant” introduced by Rosin (2011) and refined for AlphaGo.
Virtual loss. When running MCTS in parallel across many threads, temporarily decrement along the descended path. This discourages other threads from following the exact same route and de facto parallelizes selection. Reverse the virtual loss in backprop.
Why and Not Something Else?
Section titled “Why lnN/n\sqrt{\ln N / n}lnN/n and Not Something Else?”The functional form is not magic — it comes directly from a Hoeffding bound on -armed bandits with bounded rewards. Different bandit assumptions yield different bounds (e.g. KL-UCB, Thompson sampling). Empirically, plain UCT works well across many domains, and the cost of the simpler formula matters when you run hundreds of thousands of simulations per move.
The next page walks through MCTS end-to-end on tic-tac-toe.