In this appendix for the multi-armed bandit writeups, I thought I’d revisit my final year project in a relatively readable manner, demonstrating how -Thomoson Sampling is asymptotically optimal for Bernoulli bandits (that is, for each ). This is the instantiation of my final year project.
As a set-up, we initialise with p.d.f.
since the conjugate prior of a Bernoulli distribution is the Beta distribution. For the update function, we use
and . At each time , we sample and pull the arm
Observe that the map induces a unique map given by . Following the Thompson sampling strategy, we need to obtain useful tail concentration bounds. We will impose some technical conditions on the risk functional to make this happen.
Definition 1. Call a risk functional continuous if is continuous.
If is continuous, then by the extreme value theorem, is compact. Hence, there exists such that for any ,
Lemma 1. If is continuous, then for any and , there exists such that
Proof. By definition,
By a direct computation,
so that is continuous on .
If , then we may simply choose . If , then the constraint set is empty and the left-hand side is infinite, so we choose if and otherwise.
Suppose . If or , then identically, so that we can choose .
Suppose instead that . Fix . Then is compact, so that
is closed and bounded, and thus compact by the Heine-Borel theorem. Since the sets
are also compact, we can define their extrema
At least one of these sets will always be non-empty, since and . If is always empty, then we can omit its discussion later on. However, if for some , then for any . Without loss of generality then, we assume both sets are non-empty for some sufficiently small .
Using monotonicity properties, for any . Therefore,
Now it is clear that whenever . By the monotone convergence theorem, there exist such that and
Define . Since smaller sets yield larger infimums, for sufficiently large ,
Taking , by the squeeze theorem,
Finally, choose
to deduce that
Remark 1. Most arguments in Lemma 1 boils down to the compactness of , and by extension, the space of Bernoulli distributions, as well as the relative continuity properties of and . Here are some proposed steps for further exploration:
Generalise the risk functional to , where is a space of probability distributions that is compact under a suitable metric or topology.
We would probably need to partition into compact sets, then define the compact sets .
During the sequential argument, we could use sequential compactness to concoct a convergent subsequence in place of a by-default convergent subsequence. That way, we might still be able to infimise over via .
Since we only care about infimising, we do not need the strength of full continuity for ; rather we would only require its lower semi-continuity property, which could be conceived as the “lower half” of vanilla continuity.
Thanks to the continuity of , we can obtain the pleasant tail upper bounds below.
Theorem 1. Fix and natural numbers , . Then there exists a universal constant such that for any random variable with Beta distribution ,
Proof. Denote the closed (and thus, compact) sets and . Use Lemma 1 to construct such that
for brevity. Using the conjugate-prior connection between Beta distributions and Bernoulli distributions, since the sum of i.i.d. Bernoullis yield a Binomial,
where for i.i.d. . By Bayes’ rule and the law of total probability, using the uniform distribution prior with p.d.f. :
In particular,
In what follows, set and follow the proof of Lemma 13 in Riou and Honda (2020) to obtain the upper bound
where using Stirling’s approximation. We remark that in the live algorithm, at time ,
would be a somewhat confusing random variable, and the tail concentration bounds are conditioned on .
Remark 2. The challenge to generalise this result comes in require concrete distributions to work with, and so our general version would need to be “simplified” into, or expressed in terms of, a more computationally tractable option. One possible area for exploration would be considering the compact set of bounded-mean Gaussian distributions
where is compact, then applying meaningful tail-bounds of the Gaussian to derive the risk version of said concentration bounds.
These upper bounds are, with more technical bookkeeping, ultimately responsible for the asymptotically optimal regret bounds. And since contiunity is a relatively benign condition, many risk functionals enjoy the tail upper bound of Theorem 1, and potentially, the asymptotically optimal regret bound for -Thompson Sampling.
Example 1. Given continuous risk functionals and constants , the linear combination is also a continuous risk functional. See Examples 2 and 3 for myriads of continuous risk functionals that can be combined.
However, a proper proof of the Thompson sampling algorithm requires tail lower bounds. To achieve that goal, we introduce the notion of a dominant risk functional.
Definition 2. For any , define
We say that a risk functional is dominant if for any and , there exists and such that
and . We remark that by Lemma 1, if is continuous, then we are guaranteed the optimised KL-divergence result.
In the original version, it was this concept that I dreamt of while struggling to solve the bandit problem. I prayed long and hard, and solved the problem in my dream thrice. I was shocked, and said to myself, “I must be dreaming. I will wake up and write down my solution.” And so at 4.30am sometime in February 2022, I did just that, and after a sanity check at 8.30am the next morning, concluded that the solution was correct.
In any case, the dominant risk functional property guarantees for us a much-needed tail lower bound.
Theorem 2. Fix and natural numbers , . If is dominant, then there exists another universal constant such that for any random variable with Beta distribution ,
Proof. Fix . Since is dominant, there exists and such that
and , where the last inclusion holds by . Assume for simplicity. Taking probabilities, and denoting
The rest of the calculation follows from the proof of Lemma 2 in Baudry et al (2021) by using Stirling’s approximation, and yields the desired lower bound
Remark 3. This tail bound eventually bounds all other terms by constants, once the exponentials cancel other exponentials out in subsequent calculations. The dream dealt with the slightly more general case , where . I couldn’t dream of the higher-dimensional scenarios. Nor did I need to, to be very honest. See Remark 2 for the computational challenge of generalising Theorem 2 to more general forms for the theoretical use of -Thompson Sampling.
Remark 4. The bounds in Theorems 1 and 2 work precisely for a special class of distributions, namely Bernoulli bandits (or slightly more generally, multinomial bandits). For other common classes of distributions, like Gaussians for example, we would need different tail lower bounds. Moreover, we would need to work with specific conjugate pairs of distributions, and approximate non-parametric bandits using parametric ones, which leads to messier approximation-controlling calculations when evaluating the regret bound.
But you might wonder—what functionals could pass the dominant risk functional criteria?
Lemma 2. Let be continuous and be a constant pivot point. Suppose is non-increasing and is non-decreasing. Then is dominant.
Proof. Fix and . Use Lemma 1 to produce such that
Set . First suppose . Either or . In the former, for , which implies
as required. In the latter, for , which implies
as required. If , then is non-decreasing, and the second case holds. Finally, if , then is non-increasing, and the previous argument holds.
Remark 5. For two risk functionals satisfying the hypotheses of Lemma 2 with the same pivot point and non-negative constants such that , is dominant.
Example 2. Given , denote . The following risk functionals are continuous and satisfy the hypotheses of Lemma 2 (here, let , have total integral , and denote the c.d.f. of the standard Gaussian):
Expected value: ,
Conditional value-at-risk:
Proportional hazard:
Lookback:
Spectral risk:
Entropic risk:
Dual power distortion:
Wang transform:
Logarithmic distortion:
-Sharpe ratio:
Remark 6. Since the Sharpe ratio is not well-defined at , we do not have the nice compactness property of Lemma 1 for the vanilla Sharpe ratio. The dilation by allows the Sharpe ratio to be defined for . Given a -armed Bernoulli bandit with maximum probability ,
satisfies the requirements of Lemma 1, and we recover its useful tail bounds.
Lemma 3. If is differentiable on with non-decreasing derivative , then is dominant.
Proof. We claim that no matter what, will satisfy the hypotheses of Lemma 2.
If , then is non-decreasing.
If , then is non-increasing.
If there exists such that , then the intermediate value property of derivatives yields such that . Since is non-decreasing, is non-increasing and .
In all three cases, satisfies the hypotheses of of Lemma 2, and thus are dominant.
Remark 7. More generally, if is convex (which generalises Lemma 3), i.e. for any and ,
the risk functional will be dominant. Furthermore, for any two risk functionals satisfying the hypotheses of Lemma 3 and non-negative constants such that , is dominant.
Example 3. Given , denote . The following risk functionals satisfy the hypotheses of Lemma 2 (here, let ):
Second moment:
Negative variance:
Mean-variance:
Target semi-variance:
Exponential tilt:
Quadratic utility:
Furthermore, for two risk functionals and non-negative constants satisfying the hypotheses of Lemma 2, is dominant.
Therefore, most risk functionals as listed in Examples 1, 2, and 3 are the ones that most people care about are in fact continuous and dominant, and therefore, by passing the relevant arguments through much book-keeping, enjoy the asymptotically optimal regret bound for -TS on the Bernoulli bandit environment.
Theorem 3. The regret bound of -TS over a Bernoulli bandit environment is asymptotically optimal, and given by
Proof. Follow the proof of Theorem 1 in Chang and Tan (2022), and apply Theorems 1 and 2 in the analysis. Left as an exercise (effectively) in algebra and mildly clever calculus.
Oh, by the way, with the help of ChatGPT, here’s a Jupyter writeup of the implemented algorithm and some pretty pictures!
The red curve indicates the theoretical asymptotic lower bound, and each diagram reflects the algorithm running for a fixed -armed Bernoulli bandit, with different risk functionals, even combinations of them:
And for them all, the asymptotic lower bound lies happily in their -sigma bands. (Yes, each algorithm was averaged across runs!)
And with that, we are truly done. Happy lunar new year!
These problems arise from my actual experience, but numbers have been fudged to protect confidentiality.
Problem 1 (Population Mean). As I taught my classes, I noticed that students are exceedingly taller than I. My height is 160 cm, so I suspect that the average height of students is not 160 cm. By collecting the heights cm of 30 randomly chosen students, I obtained the following data:
Test at the 5% significance level to determine whether my suspicion is justified.
(Click for Solution)
Solution. Let denote the height of a randomly chosen student in cm, and .
We first set up the null and alternative hypotheses:
Denote the population variance by and . Assume holds, so that . Since , by the central limit theorem,
Since is unknown, we need to estimate it using :
Furthermore, we estimate using :
Hence, our calculated test statistic will be
Since , , so that using either a – or a -test would yield similar results. Denote and the significance level .
Using a -table, .
Using a -table, .
Whether we let or , it is true that . Therefore, there is sufficient evidence to reject and conclude that Joel’s suspicion is justified, i.e. the average height of students is larger than cm.
Problem 2 (Confidence Intervals). Keep the scenario as Problem 1 but denote the true population mean by . Use the -test for simplicity. Determine the interval of values that can take such that there is insufficient evidence to reject the null hypothesis at the 5% significance.
(Click for Solution)
Solution. By definition,
We do not reject if and only if . Therefore,
Therefore,
Remark 1. We call this calculated interval the -confidence interval for . Denoting a specific sample , let denote the corresponding computed unbiased estimators for respectively. Then the computed corresponding confidence interval will equal
Hence, different samples would yield different confidence intervals. Since is random, so is . Furthermore, defining , mimicking the computation above yields
Thus, we have the following interpretation of a -confidence interval: the probability that a randomly chosen confidence interval will contain the (deterministic though unknown) population mean is .
Problem 3 (Population Proportion). I went to a nearby café, and noticed that there were more women than men in the café. Out of 50 people present, 32 were women.
I suspect that it is true in general that there were more women than men in Starbucks on average. Test at the 5% significance level to determine whether my suspicion is justified.
(Click for Solution)
Solution. Let be a Bernoulli random variable that represents the gender of a person. Here denotes that the person is a man and denotes that the person is a woman. Denote , which yields the proportion of women in the café.
We first set up the null and alternative hypotheses:
Assume holds, so that . We next estimate using :
Since and , by the central limit theorem,
Hence, our calculated test statistic, the -value, will be as follows:
Using a -table, , which holds. Therefore, there is sufficient evidence to reject and conclude that Joel’s suspicion is justified, i.e. there are more women than men on average.
Problem 4 (Goodness-of-Fit). A total of 750 students took an assessment worth marks. For each , let denote the number of students who scored marks out of 10. We have the following data:
Assuming that scores are continuous, determine at the 5% significance level if the scores can be well-approximated using a normal distribution.
(Click for Solution)
Solution. Let denote the score of a randomly chosen student with and . We first set up the null and alternative hypotheses:
We first estimate and using and respectively. Denoting the scores by , the summary statistics are
Hence,
Now we assume holds, so that . Denoting
we will use the test statistic
which follows a -distribution with degrees of freedom. For a proof for why this distribution works, refer to this document. Using relevant -table look-up values (or a spreadsheet application), we obtain the following values for (rounded to the nearest integer for readability, but whose original value we use in the final computation):
Piecing all of the values together,
Using a -table, , which does not hold. Therefore, there is (woefully) insufficient evidence to reject and we cannot conclude that does not follow a normal distribution.
Problem 5 (Population Variance). Using the data in Problem 4, and assuming that the scores are normally distributed, test at the 5% significance level to determine if the standard deviation of assessment scores is greater than 2.
(Click for Solution)
Solution. We first set up the null and alternative hypotheses:
We use the test statistic :
Using a spreadsheet application, . Therefore, there is sufficient evidence to reject and conclude that , which implies .
Definition 1. A continuous random variable is said to follow an exponential distribution with rate parameter, denoted , if
Suppose .
Problem 1. Prove the following properties:
,
,
,
satisfies the memoryless property.
(Click for Solution)
Solution. The c.d.f. of for is given by
Hence,
For the second result, we use the tail-probability characterisation of the expectation, where the interchange of integrals is valid by Fubini’s theorem:
Hence, for ,
For the variance, we adopt a similar approach:
Therefore,
For the memoryless property,
Problem 2. Suppose is independent to .
Calculate the distribution of .
If , evaluate the p.d.f. of .
(Click for Solution)
Solution. Denoting ,
Hence, . To evaluate the p.d.f. of , we compute the convolution of their individual p.d.f.s:
Definition 2. A continuous random variable is said to follow a gamma distribution with shape parameter and rate parameter, denoted if it has a p.d.f. given by
Problem 3. Prove the following properties:
if , then , ,
if are i.i.d., then ,
if and , then .
(Click for Solution)
Solution. Suppose . By definition of the expectation,
Hence, , and
We prove the second result by induction. Suppose and are independent. To evaluate the p.d.f. of , we compute the convolution of their individual p.d.f.s:
Therefore, . Inductively, if are i.i.d.,
For the final property, denoting ,
Hence, .
Given probability distributions , write if there exists a random variable such that and .
Problem 4. Prove the following properties:
,
,
for i.i.d. , ,
for any fixed , if , then .
(Click for Solution)
Solution. We note that if , since ,
so that . If , then
The last two results are immediate corollaries of Problem 3.
These probability distributions are examples of the exponential family of probability distributions.
Feynman’s trick in differentiating under the integral sign has been creatively wielded to evaluate otherwise intractable integrals. In this exercise, we prove Feynman’s trick and use it to evaluate the seemingly intractable Dirichlet integral
Let be a measure space and be a function such that for each , is measurable.
Problem 1. Suppose the following conditions:
For any , is continuous.
There exists some non-negative integrable such that for any , .
Prove that the map defined by is continuous.
(Click for Solution)
Solution. Fix . For any , since is continuous,
so that pointwise. Furthermore,
so that and are all integrable.
Since is integrable, by Lebesgue’s dominated convergence theorem,
so that is continuous, as required.
Problem 2. Suppose the following conditions:
There exists some such that is integrable.
For each , is differentiable with derivative at denoted by .
There exists some non-negative integrable such that for any , .
Prove that the map defined by is differentiable on and
(Click for Solution)
Solution. We first check that is well-defined. By hypothesis, is well-defined. Fix . By the mean value theorem, there exists between and latex t$ such that
By performing more analysis, is integrable, so that is well-defined.
Now fix . For any , since each is measurable,
is measurable. Furthermore, pointwise. We claim that , since the mean value theorem gives between and such that
By algebruh and the triangle inequality, each is integrable. Hence, by Lebesgue’s dominated convergence theorem,
On the other hand, by bookkeeping
Therefore,
Remark 1. Thanks to Problem 2, our proof that in the study of differential equations becomes a logically correct one.
Problem 3. Use Problem 2 to evaluate .
(Click for Solution)
Solution. Define the function by
that satisfies the hypotheses of Problem 2, and our goal is to evaluate . Applying Problem 2 and integrating by parts,
Integrating and applying the first fundamental theorem of calculus,
Problem 1. Let be i.i.d.. Let denote the permutation
such that . Denoting , evaluate for each .
(Click for Solution)
Solution. Since whenever , we can assume .
We will obtain the distribution of . Fix . Let denote the number of sample points that are less than , which follows a binomial distribution. It follows that , so that
Hence, by recalling the properties of the Beta distribution,
Problem 2. Calculate the average number of rolls of a fair six-sided die that you need to roll in order for the sum of all rolls to be a multiple of .
(Click for Solution)
Solution. Let denote the -th roll and denote the sum of the first rolls. Define the stopping time by
$latex\displaystyle N := \inf_{n \in \mathbb N} \{6 \mid X_n\}.$
We claim that . For any ,
For each ,
which is one of the six possible numbers with equal probability:
Therefore, so that as well.
Problem 3. What is the probability of getting an odd number of heads out of independent flips of a fair coin?
(Click for Solution)
Solution. Let denote the number of heads out of independent flips of a fair coin. Then the required probability is
Using properties involving the binomial coefficient,
Therefore,
In particular,
Since , we must have , as required.
Problem 4. Given , calculate .
(Click for Solution)
Solution. Denoting , we observe that
Therefore, by the tail integral for expectation,
Problem 5. You’re the second-best player in a single-elimination tournament with players. Assume the brackets are randomly seeded, and the better player always wins each match. What is the probability you reach the finals?
(Click for Solution)
Solution. Each tournament will have stages, and at stage , there will be players. In order to reach the final stage, we need to be in a different “bracket” with the best player. At stage , there are two “brackets”, and each bracket has players. Therefore, the required probability is
Problem 6. Consider the sample space and the sequence of random variables with the property that
Assuming that has identical distribution, evaluate .
(Click for Solution)
Solution. Denote . By the law of total probability,