Multi-Armed Bandit

Principles

  • Naive exploration - add randomization to greed policy (e.g., ϵ\epsilon-greedy)
  • Optimistic initialization - assume the best until proven otherwise
  • Optimism in the face of uncertainty - prefer actions with uncertain values
  • Probability matching - select actions according to probability they are best

Overview

A multi-armed bandit is a tuple ⟨A,R⟩\langle \mathcal{A},\mathcal{R} \rangle. A\mathcal{A} is a known set of MM actions or arms.

Ra(r)=P[r∣a]\mathcal{R}^a(r)=\mathbb{P}[r|a] is unknown probability distribution of rewards. At each step t the agent selects an action at∈Aa_t \in \mathcal{A}.

The environment generates a reward rt∼Ratr_t \sim \mathcal{R}^{a_t} and the goal is to maximize total reward ∑T=1trt\sum_{\mathcal{T}=1}^t{r_{\mathcal{t}}}.

Regret

The action-value is the mean reward for action a, Q(a)=E[r∣a]Q(a)=\mathbb{E}[r|a]. The optimal value V∗V^* is V∗=Q(a∗)=max⁡a∈AQ(a)V^*=Q(a^*)=\max\limits_{a\in\mathcal{A}}Q(a).

Regret is the opportunity loss for one step. Regret is a function of gaps Δa=V∗−Q(aT)\Delta_a = V^* - Q(a_{\mathcal{T}}): Total regret is the total opportunity loss: Lt=∑a∈AE[Nt(a)Δa]L_t = \sum\limits_{a \in \mathcal{A}} \mathbb{E}[N_t(a)\Delta_a]. Maximizing total reward is equivalent to minimizing total regret.

Average sampling and ϵ\epsilon-greedy have linear total regret. Decaying ϵ\epsilon-Greedy has logarithmic regret, which is a theoretical lower bound on complexity of regret. UCB also achieves logarithmic regret. Thompson sampling hits theoretical minimum.

Strategies

Objective is find a policy π\pi that maximizes total cumulated reward, π∗=arg⁡max⁡π∑t=0Trπt,t\pi^*= \arg\max_\pi \sum\limits_{t=0}^{T} r_{\pi_t,t} , where πt∈{1,…,K}\pi_t \in \{1,\dots,K\} is the arm selected by π\pi at time tt, and ri,tr_{i,t} is the reward obtained at time tt after selecting the arm i∈{1,…,K}i \in \{1,\dots,K\}.

e-greedy

The ϵ\epsilon-greedy strategy sometimes acts greedily, and sometimes selects a random action to improve exploration:

∀t,πtgreedy={arg⁡max⁡iμ^i,twith probability 1-ϵi∼U{1,K}with probability ϵ\forall t,\pi^\mathrm{greedy}_t = \begin{cases} \arg \max_i \hat\mu_{i,t} & \text{with probability 1-}\epsilon \\ i \sim \mathcal{U}\{1,K\} & \text{with probability }\epsilon \\ \end{cases}

Incremental Implementation of Sample Averaging

Qn+1=1n∑i=1nRi=Qn+1n[Rn−Qn]Q_{n+1} = \frac{1}{n}\sum\limits^n_{i=1}R_i = Q_n + \frac{1}{n}[R_n - Q_n]

The fraction 1n\frac{1}{n} has nice convergence properties–diverging at ∞\infty while its square 1n2\frac{1}{n^2} converges at ∞\infty .

An ϵ\epsilon-greedy average-sampling bandit algorithm from the Sutton book:

  • Initialize, for a = 1 to kk:

    • Q(a)←0Q(a) \gets 0

    • N(a)←0N(a) \gets 0

  • Loop forevers:

    • A←{arg⁡max⁡nQ(a)with probability 1-ϵ (breaking ties randomly)a random actionwith probability ϵA \gets \begin{cases} \arg \max_n Q(a) & \text{with probability 1-}\epsilon \text{ (breaking ties randomly)} \\ \text{a random action} & \text{with probability }\epsilon \end{cases}
    • R←bandit(A)R \gets bandit(A)
    • N(A)←N(A)+1N(A) \gets N(A) + 1
    • Q(A)←Q(A)+1N(A)[R−Q(A)]Q(A) \gets Q(A) + \frac{1}{N(A)}[R - Q(A)]

Discounting

We can use discounting instead of averaging to overcome nonstationarity.

Qn+1≐Qn+α[Rn−Qn]Q_{n+1} \doteq Q_n + \alpha[R_n - Q_n]

Qn+1=Qn+α[Rn−Qn]=αRn+(1−α)Qn=(1−α)nQ1+∑i=1nα(1−α)n−iRi\begin{align}Q_{n+1} &= Q_n + \alpha[R_n - Q_n]\\ &= \alpha R_n + (1-\alpha)Q_n \\ &= (1-\alpha)^nQ_1 + \sum_{i=1}^n \alpha(1-\alpha)^{n-i} R_i\end{align}

Upper Confidence Bounds (UCB)

UCB follows an optimistic strategy and selects the best arm in the best case scenario, i.e., according to the upper bounds Bt(i)B_t(i) on the arms value estimates:

πt=arg⁡max⁡iBt(i)withBt(i)=μ^i,t+2ln⁡tTiorμ^i,t+cln⁡tTi\pi_t = \arg \max_i B_t(i) \quad \text{with} \quad B_t(i)= \hat\mu_{i,t} + \sqrt{\frac{2 \ln t}{T_i}} \quad \text{or} \quad \hat\mu_{i,t} + c\sqrt{\frac{\ln t}{T_i}}

At=arg⁡max⁡(Qt(a)+cln⁡(t)Nt(a))A_t = \arg\max (Q_t(a) + c\sqrt{\frac{\ln(t)}{N_t(a)}})

Gradient Bandit

Ht(a)H_t(a) is a preference function in which only the relative ranking order matters. The function has no other interpretability. The function is updated using a stochastic gradient ascent process. The policy function uses the softmax probabilities of H over all actions.

πt(a)≐Pr{At=a}≐eHt(a)∑b=1keHt(b)\pi_t(a) \doteq Pr\{A_t=a\} \doteq \frac{e^{H_t(a)}}{\sum^k_{b=1} e^{H_t(b)}}

Ht(a)H_t(a) is updated on each step after selecting action AtA_t by:

Ht+1(a)≐Ht(a)+αδE[Rt]δHt≐Ht(a)+α(Rt−Rˉt)(1a=At−πt(At))H_{t+1}(a) \doteq H_t(a) + \alpha\frac{\delta\mathbb{E}[R_t]}{\delta H_t} \doteq H_t(a) + \alpha(R_t - \bar R_t)(\mathbb{1}_{a=A_t}-\pi_t(A_t))

Rˉt\bar R_t is the average of rewards up to but not including time t and Rˉ1=R1\bar R_1 = R_1. α\alpha is the step-size parameter.

The expected reward is the probability weighted reward of each action: E[Rt]=∑xπt(x)q∗(x)\mathbb{E}[R_t] = \sum\limits_x \pi_t(x)q_*(x)

Baselines reduce variance by subtracting the mean and centering values at zero and reducing the magnitudes. We are not subtracting from the gradient but from a number that multiplies the gradient.

Thompson Sampling

“Thompson Sampling follows a Bayesian approach and considers a parametric model P(D∣θ)P(\mathcal{D}|\theta) with a prior P(θ)P(\theta). For instance, in the linear case: P(ri,t∣θ)=N(θTxi,v2)P(r_{i,t}|\theta) = \mathcal{N}(\theta^Tx_i, v^2) and P(θ)=N(0,σ2)P(\theta) = \mathcal{N}(0, \sigma^2). Then, at each iteration t, we sample θ\theta from P(θ∣D)∝P(D∣θ)P(θ)P(\theta | \mathcal{D}) \varpropto P(\mathcal{D}|\theta)P(\theta) and select the arm πt=arg⁡max⁡iE[ri,t∣xi,t,θ]\pi_t = \arg \max_i \mathbb{E}[r{i,t} | x_{i,t},\theta].”

In other words, Thompson sampling constructs a sample distribution or rewards for each arm based on sampling statistics from past rewards such as mean and variance. Then, at each iteration, a sample item is taken from each arm based on its distribution and the policy is the choose the arm with the highest sampled value.

Thompson sampling is useful for multi-armed bandits but does not easily extend to other reinforcement learning techniques.