Epsilon-Greedy Bandit

medium
Unit 18 · Correlation & Forecasting0/2 to milestone

Implement an epsilon-greedy multi-armed bandit simulation epsilon_greedy(true_rates, n_rounds, epsilon, seed=0):

  • each round, with rng.random() < epsilon pick an arm uniformly with rng.integers(len(arms)); otherwise pick the arm with the highest estimated rate (ties to the lower index; unplayed arms have estimate 0)
  • draw the reward as rng.random() < true_rates[arm] and update that arm's count and running mean
  • use one np.random.default_rng(seed) with calls in exactly this order each round

Return (pulls, total_reward) where pulls counts plays per arm.

#bandits#experimentation#reinforcement-learning2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Epsilon-Greedy Bandit · TechGradify