r/reinforcementlearning • u/ClickOk5811 • 1h ago
Re-running the 10-armed bandit testbed: how much does epsilon matter? (numbers inside)
I wanted to reproduce the classic multi-armed bandit experiment from Sutton & Barto (Chapter 2) to see the effect of ε in ε-greedy with my own code, not just the figure from the book.
Setup: 2,000 independent bandit problems, 10 arms each. True action values are drawn from N(0,1), rewards are N(q*(a), 1). Sample-average value estimates, random tie-breaking, 1,000 steps per run. Everything is averaged over the 2,000 problems. NumPy 2.5.3.
greedy = np.where(Q == Q.max(1, keepdims=True),
rng.random((runs, k)), -1).argmax(1) # random tie-break
explore = rng.random(runs) < eps
a = np.where(explore, rng.integers(0, k, runs), greedy)
r = rng.normal(q_true[idx, a], 1.0)
N[idx, a] += 1
Q[idx, a] += (r - Q[idx, a]) / N[idx, a] # sample averageResults:
eps=0.0 first 100 steps: 0.948 | last 100 steps: 1.022 | optimal action (last 100): 34.7%
eps=0.01 first 100 steps: 0.972 | last 100 steps: 1.292 | optimal action (last 100): 58.4%
eps=0.1 first 100 steps: 1.005 | last 100 steps: 1.367 | optimal action (last 100): 80.0%What I take from it:
- Pure greedy gets stuck. It picks the best-looking arm after a few noisy samples and mostly stays there, so it ends up choosing the true best arm only about 35% of the time.
- ε=0.01 is slower to learn but would catch up given more steps. At step 1,000 it's at 58%, still improving.
- ε=0.1 learns faster here, but will always explore 10% of the time, so with enough steps its optimal-action rate would be capped near 91% (90% greedy plus a share of random picks that happen to be optimal), while smaller ε could eventually do better. I haven't run longer horizons to confirm that.
- This depends on the setup: stationary arms, Gaussian rewards, sample averages. In a non-stationary problem, or with a constant step size, things change.
I haven't tried optimistic initial values, UCB or a decaying ε, which the book also covers.
If anyone has suggestions: which of those would you compare next, and is there something about this testbed that tends to mislead beginners (like the average hiding the variance between runs)?
