Multi-arm Bandit Problem

Warren Mar

January 21, 2023

1 Introduction

When you have different options with an unknown reward rate, how do you explore the different options to maximize rewards. The name multi-arm bandit comes from considering multiple slot machines with unknown payouts. This problem comes up a lot in the area of web optimization when you are trying to measure if a user takes an action or not. There are many approaches to solving this problem such as ϵ-greedy, softmax, UCB1 and Thompson sampling [1]. The differences between these algorithms is how they decide to explore/exploit arms based on previous results. I’ll go over ϵ-greedy to motivate the basic concept and Thompson sampling for a mathematically precise objective.

2 ϵ-greedy

The best arm is the arm with the highest historical success rate. At each trial, choose an arm with probability,

P(best arm) = 1 - ϵ
P(other arms) = ϵ

The best arm is recomputed after each trial. Each of the other arms are sampled with equal probability. ϵ controls how much time you spend exploring versus exploiting, it is typically chosen to be 0.1. The problem with ϵ-Greedy is that it can get stuck on the bad solution for a while.

3 Bernoulli distribution

A Bernoulli random variable is 1 with a probability p and 0 with a probability q = 1 - p. Usually 1 represents the event occur and 0 represent an event not occurring. This can be expressed with the probability mass function,

f(k;p) = pk(1 - p)1-k for k ∈ 0,1

For a fair coin, p = 0.5 is the probability of a head appearing (k = 1).

4 Confidence interval

The confidence interval tells you how likely the true p is in a range. We can estimate p by conducting repeated Bernoulli trials.

       ∘  ---------------
ˆp ± zα ∕2  ˆp(1 --ˆp)N----n-
             n    N  - 1

where N is the total population size, n is the sample size, ˆp is the measured proportion and zα∕2 is the confidence level desired by looking up n in the t-distribution table.

N is usually large, so finite population correction factor term,

N---n--
N -  1 →  1

leaving

        ∘ ---------
ˆp ± z     ˆp(1---ˆp)
     α∕2     n

where zα∕2 is read from the normal error integral table as show in Table 1 instead of the t-distribution. For 95% confidence interval, zα∕2 = 1.96, from adding row 1.9 and column 0.06 together.

5 β distribution

The next building block is the β distribution. The β distribution is the probability distribution of what the true p is based on observations. The probability density function is

            Γ (α + β)
f(x;α, β) = ---------x α-1(1 - x)β-1
            Γ (α )Γ (β)

where α,β > 0. Figure 1 shows the distribution for different values of α and β. α - 1 can be thought of as the number of times a trial succeeded and β - 1 the number of times a trial failed. In the beginning, we can assume maximum ignorance. We have no idea if the even always occurs, never occurs or what the chances of occurring would be, so the probability is uniform across all possibilities. If we assume there is chance for the event to occur and a chance for it to not occur, then we can start with α,β = 2. If in the next trial, the even doesn’t occur, we increment β to 3. So, we have 1 event occurring from 3 trials and our β distribution peaking at 1/3. As we get more information from each successful trial, our β distribution shifts.


PIC

Figure 1: Probability density function of β distribution for different values of α and β.


6 Thompson sampling

Thompson sampling is when arms are sampled according the probability that each arm is the best arm [2]. This avoids getting stuck on bad arms and the algorithm will explore arms to get more information about which one is the best.

Each arm can be represented by a β distribution. If we randomly sample each distribution, we can get an estimated value of p. We choose the arm with the highest p. This minimizes the regret since we are choosing the arms with the best chance of being the best. Bad arms will be avoided once enough information is collected and arms with close distributions will be sampled equally until their distributions diverge.

In Python, numpy.random.beta draws samples from a β distribution. The results of a simulation using Thompson sampling is shown in Figure 2. The confidence interval decreases with increasing number of trials as -1-
√n.


PIC

Figure 2: Thompson sampling of 3 arms for 50,000 trials with the confidence intervals reported every 5,000 trials.



Table 1: Normal error integral

t 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09
0.00.00 0.80 1.60 2.39 3.19 3.99 4.78 5.58 6.38 7.17
0.17.97 8.76 9.55 10.3411.1311.9212.7113.5014.2815.07
0.215.8516.6317.4118.1918.9719.7420.5121.2822.0522.82
0.323.5824.3425.1025.8626.6127.3728.1228.8629.6130.35
0.431.0831.8232.5533.2834.0134.7335.4536.1636.8837.59
0.538.2938.9939.6940.3941.0841.7742.4543.1343.8144.48
0.645.1545.8146.4747.1347.7848.4349.0749.7150.3550.98
0.751.6152.2352.8553.4654.0754.6755.2755.8756.4657.05
0.857.6358.2158.7859.3559.9160.4761.0261.5762.1162.65
0.963.1963.7264.2464.7665.2865.7966.2966.8067.2967.78
1.068.2768.7569.2369.7070.1770.6371.0971.5471.9972.43
1.172.8773.3073.7374.1574.5774.9975.4075.8076.2076.60
1.276.9977.3777.7578.1378.5078.8779.2379.5979.9580.29
1.380.6480.9881.3281.6581.9882.3082.6282.9383.2483.55
1.483.8584.1584.4484.7385.0185.2985.5785.8486.1186.38
1.586.6486.9087.1587.4087.6487.8988.1288.3688.5988.82
1.689.0489.2689.4889.6989.9090.1190.3190.5190.7090.90
1.791.0991.2791.4691.6491.8191.9992.1692.3392.4992.65
1.892.8192.9793.1293.2893.4293.5793.7193.8593.9994.12
1.994.2694.3994.5194.6494.7694.8895.0095.1295.2395.34
2.095.4595.5695.6695.7695.8695.9696.0696.1596.2596.34
2.196.4396.5196.6096.6896.7696.8496.9297.0097.0797.15
2.297.2297.2997.3697.4397.4997.5697.6297.6897.7497.80
2.397.8697.9197.9798.0298.0798.1298.1798.2298.2798.32
2.498.3698.4098.4598.4998.5398.5798.6198.6598.6998.72
2.598.7698.7998.8398.8698.8998.9298.9598.9899.0199.04
2.699.0799.0999.1299.1599.1799.2099.2299.2499.2699.29
2.799.3199.3399.3599.3799.3999.4099.4299.4499.4699.47
2.899.4999.5099.5299.5399.5599.5699.5899.5999.6099.61
2.999.6399.6499.6599.6699.6799.6899.6999.7099.7199.72

References

[1]   John Myles White. Bandit Algorithms for Website Optimization. O’Reilly Media, 2013.

[2]   Shipra Agrawal and Navin Goyal. Analysis of thompson sampling for the multi-armed bandit problem. JMLR: Workshop and Conference Proceedings, 23:39.1–39.26, 2012.