Non-FictionInformativeEducational

Thompson Sampling Operator eBook

A Coursebook on Thompson Sampling Operator

by Sayre Belkis

  • English
  • 153 pages
  • 2026
  • SamEnrico

A Coursebook on Thompson Sampling Operator

Formats

Free sample

Chapter 1: The Gambler’s Dilemma--– The old man in the back corner of the casino knew something that the slot machine designers did not. While other patrons fed coins into glowing screens with mechanical optimism, he sat motionless, watching three machines. Every few minutes, he would rise, walk to one of them, pull the lever once, and return to his seat. He never played a machine twice in a row. By midnight, his coin cup was full.

By closing, the casino manager had asked him to leave.The man was not cheating. He was not lucky. He was implementing, without knowing its mathematical name, a solution to the most fundamental problem in sequential decision-making: how to balance the acquisition of new information against the exploitation of known rewards. He was, in effect, running a mental Thompson Sampler.This book argues that the principle driving that old gambler—probability matching under uncertainty—is not merely a clever trick for slot machines. It is a universal operator, a modular computational unit that can be plugged into any system that must make decisions under uncertainty.

Whether you are selecting a child solution in a genetic algorithm, routing a query to a large language model, tuning the hyperparameters of a deep neural network, or running an adaptive clinical trial, the same mathematical engine applies. Thompson Sampling is not an algorithm. It is an operator.Before we can understand why this operator works, before we can implement it in code or deploy it in production systems, we must first understand the problem it solves. That problem is the exploration-exploitation dialectic, and it is older than computing, older than statistics, older even than casinos.The Fundamental Trade-Off Every decision-maker faces a hidden adversary: time. When you choose an action, you receive an immediate reward, but you also receive information.

That information might change your future decisions. The tension is inescapable. Should you choose what you believe is best right now (exploitation), or should you choose something else to learn whether your belief is wrong (exploration)?Consider a simple example. You arrive in a new city and need dinner. There are twenty restaurants within walking distance.

You try one. The food is excellent. Do you return to that same restaurant every subsequent night, or do you try the other nineteen? If you return, you guarantee good meals but may miss a superior establishment. If you explore, you risk bad meals but might discover something transcendent.

There is no universal answer. The optimal strategy depends on how many nights you will spend in the city and how much variance exists among the restaurants.This is not an abstract puzzle. The same structure appears in medicine (which treatment to give the next patient), e-commerce (which product to display), advertising (which ad to show), robotics (which action to take), and artificial intelligence (which hypothesis to pursue). In every case, the decision-maker faces a bandit: a set of options (arms) with unknown reward distributions, a finite horizon (or discount factor), and the need to minimize regret—the cumulative loss from not always choosing the best arm.The Multi-Armed Bandit Formalized Let us make this precise. A multi-armed bandit problem consists of:A set of KKK actions, or arms.

Each arm iii has an unknown reward distribution νi\nu_iνi​.A horizon TTT, which may be finite or infinite.A decision rule that, at each time step t=1,…,Tt = 1, \ldots, Tt=1,…,T, selects an arm At A_t At​ based on all previous observations.After selecting arm At A_t At​, the decision-maker observes a reward Yt Y_t Yt​ drawn from νAt\nu_{A_t}νAt​​.The goal is to maximize the total expected reward, or equivalently, to minimize the expected regret:RT=T⋅μ∗−E[∑t=1TYt]R_T = T \cdot \mu^* - \mathbb{E}\left[ \sum_{t=1}^T Y_t \right]RT​=T⋅μ∗−E[t=1∑T​Yt​]where μ∗=max⁡i E[νi]\mu^* = \max_i \mathbb{E}[\nu_i]μ∗=maxi​E[νi​] is the expected reward of the best arm. Regret measures how much worse the decision-maker performs compared to an oracle that knows the best arm from the start.If you are accustomed to supervised learning—where the data arrives labeled and the goal is to minimize prediction error—this framing may feel strange. In supervised learning, the environment is static and the algorithm is passive. In bandit problems, the algorithm actively shapes the data it receives. Choosing arm At A_t At​ determines both the immediate reward and the information available for all future decisions.

This active, sequential nature is what makes bandit problems both challenging and powerful.Why Greedy Algorithms Fail A natural first approach is to be greedy: at each step, estimate the mean reward of each arm using all available data, then select the arm with the highest estimated mean. This is sometimes called the "current best" strategy.The problem is that greedy algorithms never explore. Once an arm has a slightly higher estimated mean—perhaps due to early lucky draws—the algorithm will select it every time. Other arms may never be tried again, even if their true means are higher. The greedy algorithm locks onto a single arm and never looks back.This failure is not merely theoretical.

Imagine a clinical trial with two treatments. Treatment A is tested on five patients. All five recover. Treatment B has not been tested at all. A greedy algorithm would declare Treatment A superior and give it to every subsequent patient.

But what if Treatment B actually has a 90% recovery rate, and Treatment A's 100% rate was a fluke due to small sample size? The greedy algorithm would never find out. It would inflict a suboptimal treatment on hundreds of patients, generating massive regret.The problem is even worse when the reward distributions are noisy. In fact, one can prove that the greedy algorithm incurs linear regret: its cumulative regret grows proportionally to TTT, the number of time steps. This is the worst possible rate.

An algorithm that simply chooses arms uniformly at random also incurs linear regret. Greedy is no better than random in the worst case. It solves the exploration problem by pretending it does not exist.The Optimism Principle One elegant solution to the exploration-exploitation trade-off is the principle of optimism in the face of uncertainty. The idea: act as if the environment is as good as it plausibly could be, given the data so far. If an arm has not been tried often, its plausible best-case reward is high, so the algorithm will try it.

As data accumulates, the plausible range narrows, and the algorithm gradually shifts toward exploitation.This principle is instantiated in algorithms like Upper Confidence Bound (UCB), which selects the arm maximizing:μ^i(t)+2log⁡tni(t)\hat{\mu}_i(t) + \sqrt{\frac{2 \log t}{n_i(t)}}μ^​i​(t)+ni​(t)2logt​​where μ^i(t)\hat{\mu}_i(t)μ^​i​(t) is the empirical mean of arm iii after ttt rounds, and ni(t)n_i(t)ni​(t) is the number of times arm iii has been pulled. The additive term is a confidence radius: it shrinks as the arm is tried more often, and grows slowly with time, ensuring that every arm is eventually tried infinitely often in the limit.UCB achieves logarithmic regret: RT=O(Klog⁡T)R_T = O(K \log T)RT​=O(Klog T). This is essentially optimal—no algorithm can achieve better than…

This is the end of the free sample. Get the eBook to keep going. Buy now

About this book

A Coursebook on Thompson Sampling Operator

Details

Author
Sayre Belkis
Publisher
SamEnrico
Language
English
Genre
Non-Fiction, Informative, Educational
Released
2026-05-04
Pages (approx.)
153
Available as
eBook, Audiobook

Read better in the ZLOADR app

Your eBooks on your phone or tablet. Sign in with your SamEnrico account and start reading.

More by Sayre Belkis

See all

You may also like

See all