Every model in this course so far learned from a fixed dataset that already existed before training started. What if the only way to get more data was to act — and every action costs you the chance to have tried something else instead?
Three arms, three unknown reward rates. Pull one — its estimate updates. Pull it again, and it either supports or undermines what you just learned. There's no dataset to hand you upfront here; the only way to find out anything is to spend a pull finding out.
Each arm's estimated value is just the running average of what it's paid out so far:
- — the running-average estimate of arm 's value, updated after every pull.
- — one of the arms (actions) available to pull.
- — the number of times arm has been pulled so far.
- — the reward received on the -th pull of that arm.
- Pure greedy can get stuck
Always pulling whichever arm currently looks best can lock in a wrong estimate: an early lucky (or unlucky) run of pulls can convince the policy an inferior arm is best, before enough evidence comes in to correct it.
- Epsilon-greedy: mostly exploit, sometimes explore
Epsilon-greedy fixes this with the simplest possible patch: most of the time pull the current best arm (exploit), but some fraction of the time pull a different one anyway, just to keep checking (explore).
Step through a fixed 8-pull run. The first three pulls explore all three arms once each — arm A and arm B both come back showing , a tie. From here, a purely greedy policy could pull only A forever and never find out B is actually the better arm.
Arms A, B, C have fixed (but hidden from the policy) true means , , . The script explores A, B, C once each, then exploits:
- After the first three explore steps
- A:
- B:
- C:
A and B are tied for best, purely by chance on a single pull each.
- Exploiting the tie
Ties break alphabetically, so the policy exploits A next: A. Now B is the clear leader and gets exploited: B.
- One more explore step saves it
A scheduled explore step revisits A a third time: A. Two more exploit steps follow, landing on B — tied with A again, by coincidence, after just 8 pulls total.
Even this short run shows the whole tension: without that one extra explore step, the policy might have kept exploiting A on a stale, lucky-looking estimate.
Pull arms until one arm's estimate exceeds 0.7, backed by at least 3 pulls of it.
A bandit is reinforcement learning with everything stripped away except the one tension that defines the whole field: acting changes what you know, and what you know should change how you act. There's no state to track yet — every pull starts from the same "state" the last one did. The next chapter adds exactly that: a world where the action you take also decides what situation you're in next.