r""" A conjugate Thompson sampling [1]_ [2]_ policy for multi-armed bandits with Bernoulli likelihoods. Notes ----- The policy assumes independent Beta priors on the Bernoulli arm payoff probabilities, :math:`\theta`: .. math:: \
(self, alpha=1, beta=1)
| 275 | |
| 276 | class ThompsonSamplingBetaBinomial(BanditPolicyBase): |
| 277 | def __init__(self, alpha=1, beta=1): |
| 278 | r""" |
| 279 | A conjugate Thompson sampling [1]_ [2]_ policy for multi-armed bandits with |
| 280 | Bernoulli likelihoods. |
| 281 | |
| 282 | Notes |
| 283 | ----- |
| 284 | The policy assumes independent Beta priors on the Bernoulli arm payoff |
| 285 | probabilities, :math:`\theta`: |
| 286 | |
| 287 | .. math:: |
| 288 | |
| 289 | \theta_k \sim \text{Beta}(\alpha_k, \beta_k) \\ |
| 290 | r \mid \theta_k \sim \text{Bernoulli}(\theta_k) |
| 291 | |
| 292 | where :math:`k \in \{1,\ldots,K \}` indexes arms in the MAB and |
| 293 | :math:`\theta_k` is the parameter of the Bernoulli likelihood for arm |
| 294 | `k`. The sampler begins by selecting an arm with probability |
| 295 | proportional to its payoff probability under the initial Beta prior. |
| 296 | After pulling the sampled arm and receiving a reward, `r`, the sampler |
| 297 | computes the posterior over the model parameters (arm payoffs) via |
| 298 | Bayes' rule, and then samples a new action in proportion to its payoff |
| 299 | probability under this posterior. This process (i.e., sample action |
| 300 | from posterior, take action and receive reward, compute updated |
| 301 | posterior) is repeated until the number of trials is exhausted. |
| 302 | |
| 303 | Note that due to the conjugacy between the Beta prior and Bernoulli |
| 304 | likelihood the posterior for each arm will also be Beta-distributed and |
| 305 | can computed and sampled from efficiently: |
| 306 | |
| 307 | .. math:: |
| 308 | |
| 309 | \theta_k \mid r \sim \text{Beta}(\alpha_k + r, \beta_k + 1 - r) |
| 310 | |
| 311 | References |
| 312 | ---------- |
| 313 | .. [1] Thompson, W. (1933). On the likelihood that one unknown |
| 314 | probability exceeds another in view of the evidence of two samples. |
| 315 | *Biometrika, 25(3/4)*, 285-294. |
| 316 | .. [2] Chapelle, O., & Li, L. (2011). An empirical evaluation of |
| 317 | Thompson sampling. *Advances in Neural Information Processing |
| 318 | Systems, 24*, 2249-2257. |
| 319 | |
| 320 | Parameters |
| 321 | ---------- |
| 322 | alpha : float or list of length `K` |
| 323 | Parameter for the Beta prior on arm payouts. If a float, this value |
| 324 | will be used in the prior for all of the `K` arms. |
| 325 | beta : float or list of length `K` |
| 326 | Parameter for the Beta prior on arm payouts. If a float, this value |
| 327 | will be used in the prior for all of the `K` arms. |
| 328 | """ |
| 329 | super().__init__() |
| 330 | self.alphas, self.betas = [], [] |
| 331 | self.alpha, self.beta = alpha, beta |
| 332 | self.is_initialized = False |
| 333 | |
| 334 | @property |