Thompson sampling

From HandWiki
Concrete example of Thompson sampling applied to simulate treatment efficacy evaluation.

Thompson sampling,[1][2][3] named after William R. Thompson, is a heuristic for choosing actions that addresses the exploration-exploitation dilemma in the multi-armed bandit problem. It consists of choosing the action that maximizes the expected reward with respect to a randomly drawn belief.

Description

Consider a set of contexts [math]\displaystyle{ \mathcal{X} }[/math], a set of actions [math]\displaystyle{ \mathcal{A} }[/math], and rewards in [math]\displaystyle{ \mathbb{R} }[/math]. The aim of the player is to play actions under the various contexts, such as to maximize the cumulative rewards. Specifically, in each round, the player obtains a context [math]\displaystyle{ x \in \mathcal{X} }[/math], plays an action [math]\displaystyle{ a \in \mathcal{A} }[/math] and receives a reward [math]\displaystyle{ r \in \mathbb{R} }[/math] following a distribution that depends on the context and the issued action.

The elements of Thompson sampling are as follows:

  1. a likelihood function [math]\displaystyle{ P(r|\theta,a,x) }[/math];
  2. a set [math]\displaystyle{ \Theta }[/math] of parameters [math]\displaystyle{ \theta }[/math] of the distribution of [math]\displaystyle{ r }[/math];
  3. a prior distribution [math]\displaystyle{ P(\theta) }[/math] on these parameters;
  4. past observations triplets [math]\displaystyle{ \mathcal{D} = \{(x; a; r)\} }[/math];
  5. a posterior distribution [math]\displaystyle{ P(\theta|\mathcal{D}) \propto P(\mathcal{D}|\theta)P(\theta) }[/math], where [math]\displaystyle{ P(\mathcal{D}|\theta) }[/math] is the likelihood function.

Thompson sampling consists in playing the action [math]\displaystyle{ a^\ast \in \mathcal{A} }[/math] according to the probability that it maximizes the expected reward; action [math]\displaystyle{ a^\ast }[/math] is chosen with probability

[math]\displaystyle{ \int \mathbb{I} \left[ \mathbb{E}(r|a^\ast,x,\theta) = \max_{a'} \mathbb{E}(r|a',x,\theta) \right] P(\theta|\mathcal{D}) d\theta, }[/math]

where [math]\displaystyle{ \mathbb{I} }[/math] is the indicator function.

In practice, the rule is implemented by sampling. In each round, parameters [math]\displaystyle{ \theta^\ast }[/math] are sampled from the posterior [math]\displaystyle{ P(\theta|\mathcal{D}) }[/math], and an action [math]\displaystyle{ a^\ast }[/math] chosen that maximizes [math]\displaystyle{ \mathbb{E}[r|\theta^\ast,a^\ast,x] }[/math], i.e. the expected reward given the sampled parameters, the action, and the current context. Conceptually, this means that the player instantiates their beliefs randomly in each round according to the posterior distribution, and then acts optimally according to them. In most practical applications, it is computationally onerous to maintain and sample from a posterior distribution over models. As such, Thompson sampling is often used in conjunction with approximate sampling techniques.[3]

History

Thompson sampling was originally described by Thompson in 1933.[1] It was subsequently rediscovered numerous times independently in the context of multi-armed bandit problems.[4][5][6][7][8][9] A first proof of convergence for the bandit case has been shown in 1997.[4] The first application to Markov decision processes was in 2000.[6] A related approach (see Bayesian control rule) was published in 2010.[5] In 2010 it was also shown that Thompson sampling is instantaneously self-correcting.[9] Asymptotic convergence results for contextual bandits were published in 2011.[7] Thompson Sampling has been widely used in many online learning problems including A/B testing in website design and online advertising,[10] and accelerated learning in decentralized decision making.[11] A Double Thompson Sampling (D-TS) [12] algorithm has been proposed for dueling bandits, a variant of traditional MAB, where feedback comes in the form of pairwise comparison.

Relationship to other approaches

Probability matching

Probability matching is a decision strategy in which predictions of class membership are proportional to the class base rates. Thus, if in the training set positive examples are observed 60% of the time, and negative examples are observed 40% of the time, the observer using a probability-matching strategy will predict (for unlabeled examples) a class label of "positive" on 60% of instances, and a class label of "negative" on 40% of instances.

Bayesian control rule

A generalization of Thompson sampling to arbitrary dynamical environments and causal structures, known as Bayesian control rule, has been shown to be the optimal solution to the adaptive coding problem with actions and observations.[5] In this formulation, an agent is conceptualized as a mixture over a set of behaviours. As the agent interacts with its environment, it learns the causal properties and adopts the behaviour that minimizes the relative entropy to the behaviour with the best prediction of the environment's behaviour. If these behaviours have been chosen according to the maximum expected utility principle, then the asymptotic behaviour of the Bayesian control rule matches the asymptotic behaviour of the perfectly rational agent.

The setup is as follows. Let [math]\displaystyle{ a_1, a_2, \ldots, a_T }[/math] be the actions issued by an agent up to time [math]\displaystyle{ T }[/math], and let [math]\displaystyle{ o_1, o_2, \ldots, o_T }[/math] be the observations gathered by the agent up to time [math]\displaystyle{ T }[/math]. Then, the agent issues the action [math]\displaystyle{ a_{T+1} }[/math] with probability:[5]

[math]\displaystyle{ P(a_{T+1}|\hat{a}_{1:T}, o_{1:T}), }[/math]

where the "hat"-notation [math]\displaystyle{ \hat{a}_t }[/math] denotes the fact that [math]\displaystyle{ a_t }[/math] is a causal intervention (see Causality), and not an ordinary observation. If the agent holds beliefs [math]\displaystyle{ \theta \in \Theta }[/math] over its behaviors, then the Bayesian control rule becomes

[math]\displaystyle{ P(a_{T+1}|\hat{a}_{1:T}, o_{1:T}) = \int_{\Theta} P(a_{T+1}|\theta, \hat{a}_{1:T}, o_{1:T}) P(\theta|\hat{a}_{1:T}, o_{1:T}) \, d\theta }[/math],

where [math]\displaystyle{ P(\theta|\hat{a}_{1:T}, o_{1:T}) }[/math] is the posterior distribution over the parameter [math]\displaystyle{ \theta }[/math] given actions [math]\displaystyle{ a_{1:T} }[/math] and observations [math]\displaystyle{ o_{1:T} }[/math].

In practice, the Bayesian control amounts to sampling, at each time step, a parameter [math]\displaystyle{ \theta^\ast }[/math] from the posterior distribution [math]\displaystyle{ P(\theta|\hat{a}_{1:T}, o_{1:T}) }[/math], where the posterior distribution is computed using Bayes' rule by only considering the (causal) likelihoods of the observations [math]\displaystyle{ o_1, o_2, \ldots, o_T }[/math] and ignoring the (causal) likelihoods of the actions [math]\displaystyle{ a_1, a_2, \ldots, a_T }[/math], and then by sampling the action [math]\displaystyle{ a^\ast_{T+1} }[/math] from the action distribution [math]\displaystyle{ P(a_{T+1}|\theta^\ast,\hat{a}_{1:T},o_{1:T}) }[/math].

Upper-Confidence-Bound (UCB) algorithms

Thompson sampling and upper-confidence bound algorithms share a fundamental property that underlies many of their theoretical guarantees. Roughly speaking, both algorithms allocate exploratory effort to actions that might be optimal and are in this sense "optimistic". Leveraging this property, one can translate regret bounds established for UCB algorithms to Bayesian regret bounds for Thompson sampling[13] or unify regret analysis across both these algorithms and many classes of problems.[14]

References

  1. 1.0 1.1 Thompson, William R. "On the likelihood that one unknown probability exceeds another in view of the evidence of two samples". Biometrika, 25(3–4):285–294, 1933.
  2. Thompson, W. R. (1935). On the theory of apportionment. American Journal of Mathematics, 57(2), 450-456.
  3. 3.0 3.1 Daniel J. Russo, Benjamin Van Roy, Abbas Kazerouni, Ian Osband and Zheng Wen (2018), "A Tutorial on Thompson Sampling", Foundations and Trends in Machine Learning: Vol. 11: No. 1, pp 1-96. https://web.stanford.edu/~bvr/pubs/TS_Tutorial.pdf
  4. 4.0 4.1 J. Wyatt. Exploration and Inference in Learning from Reinforcement. Ph.D. thesis, Department of Artificial Intelligence, University of Edinburgh. March 1997.
  5. 5.0 5.1 5.2 5.3 P. A. Ortega and D. A. Braun. "A Minimum Relative Entropy Principle for Learning and Acting", Journal of Artificial Intelligence Research, 38, pages 475–511, 2010.
  6. 6.0 6.1 M. J. A. Strens. "A Bayesian Framework for Reinforcement Learning", Proceedings of the Seventeenth International Conference on Machine Learning, Stanford University, California, June 29–July 2, 2000, http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.140.1701
  7. 7.0 7.1 B. C. May, B. C., N. Korda, A. Lee, and D. S. Leslie. "Optimistic Bayesian sampling in contextual-bandit problems". Technical report, Statistics Group, Department of Mathematics, University of Bristol, 2011.
  8. Chapelle, Olivier, and Lihong Li. "An empirical evaluation of thompson sampling." Advances in neural information processing systems. 2011. http://papers.nips.cc/paper/4321-an-empirical-evaluation-of-thompson-sampling
  9. 9.0 9.1 O.-C. Granmo. "Solving Two-Armed Bernoulli Bandit Problems Using a Bayesian Learning Automaton", International Journal of Intelligent Computing and Cybernetics, 3 (2), 2010, 207-234.
  10. Ian Clarke. "Proportionate A/B testing", September 22nd, 2011, http://blog.locut.us/2011/09/22/proportionate-ab-testing/
  11. Granmo, O. C.; Glimsdal, S. (2012). "Accelerated Bayesian learning for decentralized two-armed bandit based decision making with applications to the Goore Game". Applied Intelligence 38 (4): 479–488. doi:10.1007/s10489-012-0346-z. 
  12. Wu, Huasen; Liu, Xin; Srikant, R (2016), Double Thompson Sampling for Dueling Bandits, Bibcode2016arXiv160407101W 
  13. Russo, Daniel J.; Van Roy, Benjamin (2014). "Learning to Optimize Via Posterior Sampling". Mathematics of Operations Research 39 (4): 1221–1243. doi:10.1287/moor.2014.0650. 
  14. Daniel J. Russo and Benjamin Van Roy (2013), "Eluder Dimension and the Sample Complexity of Optimistic Exploration", Advances in Neural Information Processing Systems 26, pp. 2256-2264. https://proceedings.neurips.cc/paper/2013/file/41bfd20a38bb1b0bec75acf0845530a7-Paper.pdf