7  A Two-armed Bandit Game

This game puts you in the place of the decision-maker in Multi-armed Bandits. There are two slot machines, A and B, so this is a bandit problem with k = 2 actions. Each machine has a fixed expected reward q_*(a), but you do not know these values; you only see the rewards from your own pulls. You have T pulls, and your goal is to collect as much reward as possible.

This game shows the numbers that the chapter’s algorithm keeps, so it is best played after reading the chapter. To play before reading it, start with the warm-up.

7.1 How to play

Click a machine to pull it. The machine pays a random reward around its expected reward q_*(a). Under each machine, you see the two numbers that the simple bandit algorithm of the chapter stores:

  • N(a), the number of times you have pulled machine a, and
  • Q(a), the average of the rewards that machine a has paid you, which is your estimate of q_*(a).

When pull t selects A_t and pays R_t, they are updated with the incremental rule

N(A_t) \leftarrow N(A_t) + 1, \qquad Q(A_t) \leftarrow Q(A_t) + \frac{1}{N(A_t)} \left( R_t - Q(A_t) \right).

A pull is greedy (exploitation) if it selects a machine with the highest current estimate, and exploratory (exploration) otherwise. A machine you have not pulled yet has the initial estimate Q(a) = 0, as in the algorithm. After your last pull, the true values q_*(a) are revealed, and your choices are compared with the \epsilon-greedy algorithm playing the same two machines.

At the start of each game, the expected rewards are drawn independently as q_*(a) \sim \mathcal{N}(0, 1), and each pull of machine a pays a reward drawn from \mathcal{N}(q_*(a), 1). All values are rounded to two decimals. This is the bandit of the chapter’s Python experiment with k = 2.

7.2 The game

7.3 Your results

7.4 Things to think about

  1. When did you stop exploring, and how sure were you at that point that you had found the better machine?
  2. Play a few games with 10 pulls and a few with 50. Did you explore more when you had more pulls? Why does that make sense?
  3. Find a game in which greedy (\epsilon = 0) does clearly worse than \epsilon = 0.1. What goes wrong for an agent that never explores? Hint: think about an unlucky first reward from the better machine.
  4. At the end of a game, compare Q(a) with q_*(a) for each machine. Which estimate is more accurate, and why?
TipPlaying together in class

Every game has a number. Everyone who enters the same game number plays the same two machines, and the first, second, third, … pull of each machine pays the same reward for everyone. With the same number of pulls as well, the results can be compared directly: differences in total reward come only from the choices made.