class_docstr: Bayes-UCB bandit policy.
  
  Bayes-UCB is a Bayesian algorithm for the multi-armed bandit problem. It uses the posterior
  distribution of the reward of each arm to compute an upper confidence bound (UCB) on the
  expected reward of each arm. The arm with the highest UCB is then pulled. The posterior
  distribution is updated after each pull. The algorithm is described in [^1].
  
  Parameters
  ----------
  reward_obj
      The reward object that is used to update the posterior distribution.
  burn_in
      Number of initial observations per arm before using the posterior distribution.
  seed
      Random number generator seed for reproducibility.
  
  Examples
  --------
  
  >>> import gym
  >>> from river import bandit
  >>> from river import proba
  >>> from river import stats
  
  >>> env = gym.make(
  ...     'river_bandits/CandyCaneContest-v0'
  ... )
  >>> _ = env.reset(seed=42)
  >>> _ = env.action_space.seed(123)
  
  >>> policy = bandit.BayesUCB(seed=123)
  
  >>> metric = stats.Sum()
  >>> while True:
  ...     action = policy.pull(range(env.action_space.n))
  ...     observation, reward, terminated, truncated, info = env.step(action)
  ...     policy.update(action, reward)
  ...     metric.update(reward)
  ...     if terminated or truncated:
  ...         break
  
  >>> metric
  Sum: 841.
  
  Reference
  ---------
  [^1]: [Kaufmann, Emilie, Olivier Cappé, and Aurélien Garivier. "On Bayesian upper confidence bounds for bandit problems." Artificial intelligence and statistics. PMLR, 2012.](http://proceedings.mlr.press/v22/kaufmann12/kaufmann12.pdf)
class_docstr_tok: ["Bayes-UCB","bandit","policy",".","Bayes-UCB","is","a","Bayesian","algorithm","for","the","multi-armed","bandit","problem",".","It","uses","the","posterior","distribution","of","the","reward","of","each","arm","to","compute","an","upper","confidence","bound","(","UCB",")","on","the","expected","reward","of","each","arm",".","The","arm","with","the","highest","UCB","is","then","pulled",".","The","posterior","distribution","is","updated","after","each","pull",".","The","algorithm","is","described","in","[","^1","]",".","Parameters","--","--","--","--","--","reward_obj","The","reward","object","that","is","used","to","update","the","posterior","distribution",".","burn_in","Number","of","initial","observations","per","arm","before","using","the","posterior","distribution",".","seed","Random","number","generator","seed","for","reproducibility",".","Examples","--","--","--","--",">",">",">","import","gym",">",">",">","from","river","import","bandit",">",">",">","from","river","import","proba",">",">",">","from","river","import","stats",">",">",">","env","=","gym.make","(","...","'river_bandits\/CandyCaneContest-v0'","...",")",">",">",">","_","=","env.reset","(","seed=42",")",">",">",">","_","=","env.action_space.seed","(","123",")",">",">",">","policy","=","bandit.BayesUCB","(","seed=123",")",">",">",">","metric","=","stats.Sum","(",")",">",">",">","while","True",":","...","action","=","policy.pull","(","range","(","env.action_space.n",")",")","...","observation",",","reward",",","terminated",",","truncated",",","info","=","env.step","(","action",")","...","policy.update","(","action",",","reward",")","...","metric.update","(","reward",")","...","if","terminated","or","truncated",":","...","break",">",">",">","metric","Sum",":","841",".","Reference","--","--","--","--","-","[","^1","]",":","[","Kaufmann",",","Emilie",",","Olivier","Capp\u00e9",",","and","Aur\u00e9lien","Garivier",".","``","On","Bayesian","upper","confidence","bounds","for","bandit","problems",".","''","Artificial","intelligence","and","statistics",".","PMLR",",","2012",".","]","(","http",":","\/\/proceedings.mlr.press\/v22\/kaufmann12\/kaufmann12.pdf",")"]
docstr: the p-th quantile of the beta distribution for the arm
docstr_tok: ["the","p-th","quantile","of","the","beta","distribution","for","the","arm"]
code: def compute_index(self, arm_id):
      """the p-th quantile of the beta distribution for the arm"""
      p = 1 - 1 / (self._n + 1)
      posterior = self._posteriors[arm_id]
      return scipy.special.btdtri(posterior.alpha, posterior.beta, p)
  
file_path: river/river/bandit/bayes_ucb.py
imports: from __future__ import annotations
  import collections
  import random
  import scipy.special
  from river import bandit, proba
label_desc: Use image node_id 3 for calling the BayesUCB obj's underlying member method code with example usage: obj.compute_index(arm_id) and returns: scipy