This Reinforcement Learning concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Reinforcement Learning
Bandits
Bandits isolate the exploration problem: each pull reveals only one arm's reward, so the learner must trade sample-mean exploitation against information-gathering and regret.
Concept Structure
Bandits
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learner Contract
What this page should let you do.
1 prerequisite listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and test one prediction in the live demo.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Substantive review recorded
1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
A bandit is the smallest reinforcement-learning problem where exploration is real.
There is no state transition to model yet. You only choose an arm, receive a reward, update what you know about that one arm, and choose again. The catch is brutal: pulling Arm A tells you nothing directly about Arm B or Arm C. Your data is selected by your own past decisions.
That creates the central tension:
Should I exploit the arm that currently looks best, or explore an arm that might be better but has less evidence?
A greedy learner can get stuck because early lucky rewards make one arm look best. A purely random learner gathers information but wastes many pulls. Epsilon-greedy is the simplest compromise: usually exploit, sometimes explore. UCB is more directed: add a confidence bonus to arms with fewer samples, then choose the arm whose optimistic score is largest.
Regret makes the cost visible. If the best arm has mean reward and the chosen arm has mean reward , the expected regret of that pull is . The learner may observe a lucky reward from a bad arm or an unlucky reward from the best arm, but regret asks a cleaner question: how much expected reward did this policy give up by choosing this arm?
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Consider arms. At round , the learner chooses an arm
then observes reward . In a stationary Bernoulli bandit, each arm has an unknown mean reward
and the rewards from that arm are independent draws with the same mean. The learner does not observe the rewards it would have received from the arms it did not pull.
Let be the number of times arm has been pulled before round , and let be its sample-average estimate:
After choosing and observing reward , the sample average can be updated incrementally:
Epsilon-greedy chooses greedily with probability and explores uniformly at random with probability :
UCB chooses the arm with the largest optimistic score:
The first term exploits the current estimate. The second term explores arms whose estimate is still uncertain because is small. Pulling an arm increases its count, which usually shrinks its bonus.
Let
The expected instantaneous regret of choosing arm is
The cumulative pseudo-regret over rounds is
This is not the same as "did the learner happen to receive a reward this round?" It measures the expected cost of the action choice.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import math
import numpy as np
true_means = np.array([0.62, 0.40, 0.75])
pulls = np.array([8, 6, 2])
successes = np.array([5, 2, 1])
t, c = 16, 0.70
q = successes / pulls
ucb = q + c * np.sqrt(np.log(t) / pulls)
epsilon = 0.20
rng_draw = 0.73
if rng_draw < epsilon:
chosen = 1 # a fixed "random" draw for the teaching witness
reason = "explore"
else:
chosen = int(np.argmax(q))
reason = "exploit"
ucb_chosen = int(np.argmax(ucb))
best_mean = true_means.max()
print("sample means:", q.round(3))
print("ucb scores:", ucb.round(3))
print("epsilon-greedy chose", chosen, reason)
print("ucb chose", ucb_chosen)
print("instant regret of UCB choice:", round(best_mean - true_means[ucb_chosen], 3))
The same estimates can lead to different actions. Epsilon-greedy uses an explicit random explore/exploit switch. UCB uses the uncertainty bonus to make under-sampled arms temporarily attractive.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Use the Bandit Regret Lab to predict why the policy pulls a particular arm.
Choose a case, inspect the arm estimates, counts, policy cue, and regret ledger, then commit to whether the next pull is driven by sample-mean exploitation, random exploration, or a UCB confidence bonus. After reveal, the lab shows the selected arm, sample-mean update, UCB scores, and expected regret for that one pull.
Live Concept Demo
Explore Bandits
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Bandits should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Bandits isolate the exploration problem: each pull reveals only one arm's reward, so the learner must trade sample-mean exploitation against information-gathering and regret.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Bandits should make visible.
Visual Inquiry
Make the image answer a mathematical question
Bandits isolate the exploration problem: each pull reveals only one arm's reward, so the learner must trade sample-mean exploitation against information-gathering and regret.
Which visible object should carry the first intuition?
Pick the cue that should make Bandits easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Canonical source for the k-armed bandit problem, sample-average action-value estimates, epsilon-greedy action selection, UCB action selection, and incremental action-value updates.
Open sourceGraduate RL source for exploration, decision-dependent information, and bandits as actions that influence only immediate reward.
Open sourceGraduate source for stochastic Bernoulli bandits, regret, pseudo-regret, explore-then-commit, epsilon-greedy context, and UCB as optimism under uncertainty.
Open sourceClaim Review
Bandits isolate the exploration problem: each pull reveals only one arm's reward, so the learner must trade sample-mean exploitation against information-gathering and regret.
Claims without a substantive review badge still need exact source-support review.
sutton-barto-2018-rl, stanford-cs234-intro-rl-2026, lattimore-szepesvari-2020-bandit-algorithms
Use equations, runnable code, and demos to check whether the source support is operational.
The sources support the finite-arm setting, observed-reward-only feedback, sample mean estimates, epsilon-greedy exploration/exploitation, UCB confidence bonuses, and regret as expected reward lost against the best arm.
Sources: Reinforcement Learning: An Introduction, Second Edition, Stanford CS234: Lecture 1, Introduction to Reinforcement Learning, Bandit AlgorithmsStationary finite Bernoulli teaching lab only; excludes contextual bandits, adversarial bandits, Thompson sampling, nonstationary rewards, Bayesian regret, formal finite-time proofs, delayed feedback, and MDP state transitions.A bounded review summary is present; still check caveats and exact reference scope.Checked Sutton/Barto Chapter 2 for k-armed bandits, sample-average estimates, incremental updates, epsilon-greedy, and UCB action selection. Checked Stanford CS234 Lecture 1 for exploration as decision-dependent information and bandits as immediate-reward decision processes. Checked Lattimore/Szepesvari for stochastic Bernoulli bandits, regret/pseudo-regret definitions, explore-then-commit tradeoffs, epsilon-greedy context, and UCB optimism. GPT Pro critique remains pending because 127.0.0.1:51672 is unavailable.
Reviewer: codex-local-source-review; reviewed 2026-07-03Source support candidates
book 2018Reinforcement Learning: An Introduction, Second EditionCanonical source for the k-armed bandit problem, sample-average action-value estimates, epsilon-greedy action selection, UCB action selection, and incremental action-value updates.
course-notes 2026Stanford CS234: Lecture 1, Introduction to Reinforcement LearningGraduate RL source for exploration, decision-dependent information, and bandits as actions that influence only immediate reward.
book 2020Bandit AlgorithmsGraduate source for stochastic Bernoulli bandits, regret, pseudo-regret, explore-then-commit, epsilon-greedy context, and UCB as optimism under uncertainty.
Practice Loop
Try the idea before it explains itself
Bandits isolate the exploration problem: each pull reveals only one arm's reward, so the learner must trade sample-mean exploitation against information-gathering and regret.
Before touching the demo, predict one visible change that should happen in Bandits.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to a claim, equation, code, or demo
Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.Open the draft below to save one note and next action in this browser.
Bandits
What is the smallest example that makes Bandits click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays in this browser, attached to the selected learning item.
- References to inspect: attached references on this page.
- Definition, prerequisite, and contrast concept links
- The equation or runnable code that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Bandits Selected item key: recorded for copy. Context: Reinforcement Learning Page anchor: recorded for copy. Open question: What is the smallest example that makes Bandits click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/reinforcement-learning/bandits
concept:reinforcement-learning/bandits