The Thompson Sampling Playbook
Master Multi-Armed Bandits and Make Smarter Decisions Under Uncertainty
Make better decisions when facing uncertainty by mastering Thompson Sampling and multi-armed bandit algorithms.
222 pages10 chaptersJan 2, 2026Thompson Sampling
About this book
This practical guide bridges the gap between theory and real-world application, showing you how to implement these powerful techniques to optimize outcomes in A/B testing, recommendation systems, resource allocation, and beyond. You'll learn why Thompson Sampling outperforms simpler approaches, how to set up and update Bayesian models for your specific problems, and how to measure algorithm performance through regret analysis. Whether you're optimizing marketing campaigns, personalizing user experiences, or allocating limited resources, this book provides the conceptual foundation and practical tools you need. Discover how leading companies use these algorithms to make smarter decisions faster, and gain the confidence to apply them to your own challenges. No advanced mathematics required—just clear explanations, intuitive examples, and actionable strategies.
Table of contents
- IntroductionWhy Decision-Making Under Uncertainty Matters, What You'll Learn in This Book, How to Use This BookRead below
- Chapter 1: The Exploration-Exploitation DilemmaThe Fundamental Tradeoff, Real-World Examples of the Dilemma, Why Naive Approaches Fail
- Chapter 2: Introduction to Multi-Armed BanditsThe Bandit Framework Explained, Arms, Rewards, and Regret, Bandit Problems in Practice
- Chapter 3: Simple Bandit AlgorithmsThe Epsilon-Greedy Strategy, Upper Confidence Bound (UCB) Methods, Comparing Simple Approaches
- Chapter 4: Bayesian Thinking and Posterior DistributionsBayesian Fundamentals, Priors, Likelihood, and Posterior, Updating Beliefs with Data
- Chapter 5: Thompson Sampling FoundationsThe Thompson Sampling Principle, Why Thompson Sampling Works, Thompson Sampling vs. Other Methods
- Chapter 6: Implementing Thompson SamplingChoosing Prior Distributions, Sampling from Posterior Distributions, Step-by-Step Implementation Guide
- Chapter 7: Regret Analysis and Performance MetricsUnderstanding Regret, Measuring Algorithm Efficiency, Thompson Sampling Regret Bounds
- Chapter 8: Contextual Bandits and PersonalizationBeyond Basic Bandits, Incorporating Context Information, Personalized Decision-Making
- Chapter 9: Real-World ApplicationsA/B Testing and Continuous Optimization, Recommendation Systems, Clinical Trials and Healthcare, Dynamic Pricing and Resource Allocation
- Chapter 10: Advanced Topics and ExtensionsHandling Non-Stationary Environments, Batch and Offline Learning, Combining Bandits with Deep Learning
- ConclusionKey Takeaways, Next Steps for Your Journey
- Glossary
- Further Reading and Resources
Introduction
Every day, you face decisions where the outcomes are uncertain. Should you invest resources in a new marketing campaign or stick with the proven approach? Which product recommendation will resonate most with a particular customer? How should you allocate limited budget across competing initiatives? These questions share a common challenge: you must choose between options without knowing which will perform best, and every choice carries both opportunity and risk. Traditional decision-making approaches often force you to choose between two extremes—either commit fully to what seems best based on limited information, or spend excessive time and resources testing every possibility before taking action. Neither extreme serves you well in fast-moving, competitive environments.
Thompson Sampling and multi-armed bandit algorithms offer a fundamentally different approach. Rather than treating learning and earning as separate phases, these methods seamlessly blend exploration and exploitation. They help you make decisions that balance gathering new information with maximizing immediate returns. The algorithms adapt continuously as new data arrives, shifting resources toward better-performing options while maintaining enough exploration to discover when circumstances change. This approach has transformed how leading technology companies optimize user experiences, how healthcare researchers design more ethical clinical trials, and how businesses allocate resources across uncertain opportunities. The mathematical foundations are elegant, but the practical impact is what matters most.
This book bridges the gap between theoretical understanding and practical application. You won't need advanced mathematics or specialized software to benefit from these techniques. Instead, you'll gain intuitive understanding of why these algorithms work, when to apply them, and how to implement them for your specific challenges. Whether you're optimizing digital experiences for millions of users or making resource allocation decisions in a small organization, the principles remain the same. By the end of this book, you'll have both the conceptual framework and practical tools to make smarter decisions under uncertainty. You'll understand not just what Thompson Sampling does, but why it outperforms simpler approaches and how to adapt it to your unique context.
Why Decision-Making Under Uncertainty Matters
Uncertainty pervades nearly every meaningful decision you encounter. When launching a new product feature, you don't know how users will respond until you release it. When choosing between advertising channels, past performance provides clues but doesn't guarantee future results. When allocating research funding across projects, you can't predict which investigations will yield breakthroughs. This uncertainty isn't a temporary inconvenience that better planning could eliminate—it's an inherent feature of complex, dynamic environments. The question isn't whether you'll face uncertainty, but how effectively you'll navigate it. Poor approaches to uncertainty lead to missed opportunities, wasted resources, and competitive disadvantage. Effective approaches transform uncertainty from a liability into a source of advantage.
Traditional decision-making frameworks often handle uncertainty poorly. The most common approach is to run extensive tests before committing to a decision, gathering data until you feel confident about the best option. This seems prudent, but it carries hidden costs. While you're testing, you're not fully capitalizing on what you already know. If one option shows early promise, continuing to split traffic equally across all alternatives means deliberately choosing inferior options for many users. Consider an e-commerce company testing five different homepage designs. If one design clearly outperforms the others after the first week, continuing to show the inferior designs to 80% of visitors for another month represents a substantial opportunity cost. The testing phase itself becomes expensive, not just in time and resources, but in foregone revenue and user satisfaction.
The opposite extreme—committing quickly based on limited information—creates different problems. If you choose the option that performs best in a small initial sample and never reconsider, you risk locking into a suboptimal choice. Early results are noisy, and what appears best initially may not be truly superior. Perhaps more importantly, environments change over time. User preferences shift, competitive dynamics evolve, and seasonal patterns emerge. A decision that was optimal last quarter may be suboptimal today. Organizations that commit too quickly often find themselves stuck with outdated strategies, unaware that better alternatives have emerged. They've eliminated the cost of exploration but also eliminated the ability to adapt.
The cost of poor decision-making under uncertainty compounds over time. Each suboptimal choice represents not just a single missed opportunity, but a failure to learn that could inform future decisions. When you don't systematically explore alternatives, you accumulate ignorance about your environment. You don't know which marketing messages resonate with different customer segments, which product features drive engagement, or which operational changes improve efficiency. This ignorance constrains future decisions, creating a vicious cycle where poor information leads to poor choices, which in turn generate poor information. Organizations trapped in this cycle often don't realize how much opportunity they're missing because they've never experienced the alternative.
Effective decision-making under uncertainty requires a different mindset. Rather than viewing exploration and exploitation as competing priorities, you need frameworks that integrate them. Every decision should simultaneously advance your immediate objectives and improve your understanding of the environment. This integration isn't just philosophically appealing—it's mathematically optimal. Algorithms like Thompson Sampling achieve this integration by treating uncertainty as information to be incorporated into decisions, not an obstacle to be eliminated before deciding. They recognize that the value of information depends on context: learning about a potentially superior option is valuable, while learning about clearly inferior options is not. This nuanced approach to exploration enables dramatically better performance than simpler strategies.
The stakes of decision-making under uncertainty have increased dramatically in recent years. Digital environments enable rapid experimentation and real-time optimization, but they also intensify competition. Your competitors are running their own experiments and optimizations, creating a dynamic landscape where standing still means falling behind. The organizations that master decision-making under uncertainty gain compounding advantages. They learn faster, adapt more quickly, and allocate resources more efficiently. These advantages manifest in higher conversion rates, better user engagement, more efficient marketing spend, and faster innovation cycles. The gap between organizations that handle uncertainty well and those that don't continues to widen, making these skills increasingly critical for competitive success.
Beyond competitive advantage, better decision-making under uncertainty has ethical implications. In healthcare, adaptive trial designs using bandit algorithms can reduce the number of patients assigned to inferior treatments while still generating valid scientific conclusions. In education, personalized learning systems can more quickly identify effective teaching approaches for individual students. In public policy, adaptive interventions can allocate limited resources more effectively to address social challenges. These applications demonstrate that the techniques in this book aren't just about optimizing business metrics—they're about making better use of limited resources to improve outcomes that matter. When you make decisions more efficiently under uncertainty, you create value not just for your organization but for the people your decisions affect.
What You'll Learn in This Book
This book provides a comprehensive journey from fundamental concepts to practical implementation. You'll start by understanding the exploration-exploitation dilemma that underlies all decision-making under uncertainty. This isn't abstract philosophy—you'll see concrete examples of how this dilemma manifests in business, technology, and everyday life. You'll learn why naive approaches fail and what characteristics distinguish effective solutions. This foundation is essential because Thompson Sampling isn't just a technique to memorize; it's a principled approach to a fundamental problem. Understanding the problem deeply enables you to adapt the solution to your specific context and recognize when you're facing a situation where these methods apply.
The multi-armed bandit framework provides the mathematical structure for thinking about sequential decision-making under uncertainty. You'll learn how to formalize decision problems in terms of arms, rewards, and regret. This formalization might seem academic, but it's intensely practical. Once you can frame a problem as a bandit, you can apply a rich toolkit of algorithms and analysis techniques. You'll see how diverse problems—from A/B testing to clinical trials to recommendation systems—all fit this framework. The key concepts you'll master include:
- Arms: The options or actions available to you at each decision point
- Rewards: The outcomes you observe after taking actions, which may be noisy or delayed
- Regret: The cumulative cost of not always choosing the optimal action, which measures algorithm performance
- Stationarity: Whether the underlying reward distributions remain constant or change over time
Before diving into Thompson Sampling, you'll explore simpler bandit algorithms. The epsilon-greedy strategy provides an intuitive baseline: exploit the best-known option most of the time, but explore randomly with some small probability. Upper Confidence Bound (UCB) methods offer a more sophisticated approach, choosing actions based on both estimated value and uncertainty. Understanding these simpler methods serves two purposes. First, they're sometimes appropriate for your problem—Thompson Sampling isn't always necessary or optimal. Second, comparing these approaches illuminates why Thompson Sampling works so well. You'll see concretely how different algorithms balance exploration and exploitation, and you'll develop intuition for when each approach excels or struggles.
Bayesian thinking forms the conceptual foundation for Thompson Sampling. You'll learn how to represent uncertainty using probability distributions, how to update beliefs as you observe data, and how posterior distributions capture everything you know about unknown parameters. This might sound intimidating if you haven't worked with Bayesian methods before, but the book presents these concepts accessibly. You'll see concrete examples with specific numbers, visualizations that make abstract concepts tangible, and step-by-step walkthroughs of belief updating. The Bayesian framework isn't just mathematically elegant—it's intuitive once you grasp the core ideas. It formalizes how you naturally think about uncertainty and learning in everyday life.
Thompson Sampling itself receives thorough treatment across multiple chapters. You'll understand the core principle: sample from your posterior distribution over which action is best, then choose the action that appears best in that sample. This probability matching approach naturally balances exploration and exploitation without requiring you to manually tune exploration parameters. You'll learn why this works theoretically, with intuitive explanations of the mathematical results. More importantly, you'll learn how to implement Thompson Sampling practically. This includes:
- Choosing appropriate prior distributions for different types of problems
- Updating posterior distributions efficiently as data arrives
- Sampling from posterior distributions using standard statistical tools
- Handling common complications like delayed feedback or non-binary rewards
- Monitoring algorithm performance and diagnosing issues
Regret analysis provides the framework for evaluating and comparing bandit algorithms. You'll learn how to measure cumulative regret, understand regret bounds, and interpret what these theoretical results mean for practical performance. Thompson Sampling achieves near-optimal regret bounds, but understanding what this means requires unpacking several concepts. You'll see how regret accumulates over time, why logarithmic regret represents excellent performance, and how different problem characteristics affect achievable regret. This analysis isn't just theoretical—it helps you set realistic expectations for algorithm performance and make informed choices between different approaches for your specific problem.
Contextual bandits extend the basic framework by incorporating side information about each decision. Rather than treating all decisions identically, contextual bandits adapt choices based on features of the current situation. This enables personalization and dramatically improves performance in many applications. You'll learn how to incorporate context into Thompson Sampling, how to model relationships between context and rewards, and how to handle high-dimensional context spaces. The chapter includes concrete examples from recommendation systems, personalized medicine, and dynamic pricing that illustrate the power of contextual approaches.
Real-world applications receive extensive attention throughout the book, with an entire chapter dedicated to detailed case studies. You'll see how companies use Thompson Sampling for A/B testing and continuous optimization, how recommendation systems balance exploration and exploitation, how adaptive clinical trials improve patient outcomes, and how dynamic pricing algorithms respond to changing market conditions. These aren't toy examples—they're realistic scenarios with real complications. You'll learn how to handle common practical challenges like delayed feedback, non-stationary environments, multiple objectives, and computational constraints. Each application includes implementation guidance and lessons learned from practitioners.
Advanced topics in the final chapters prepare you to handle sophisticated scenarios. You'll learn techniques for non-stationary environments where reward distributions change over time, approaches for batch and offline learning when you can't interact with the environment in real-time, and methods for combining bandit algorithms with deep learning for complex, high-dimensional problems. These chapters also discuss current research directions and open problems, giving you a sense of where the field is heading. By the end of the book, you'll have both a solid foundation in established techniques and awareness of cutting-edge developments.
How to Use This Book
This book is designed for sequential reading, with each chapter building on concepts from previous chapters. If you're new to multi-armed bandits and Thompson Sampling, start at the beginning and work through systematically. The early chapters establish essential foundations that later chapters assume you understand. Skipping ahead might leave you confused about terminology or missing key intuitions. That said, the book is also structured to support different reading paths depending on your background and goals. If you're already familiar with basic bandit algorithms and Bayesian inference, you might skim the early chapters and focus on Thompson Sampling implementation and applications. If you're primarily interested in a specific application area, you can read the relevant sections of the applications chapter after completing the foundational chapters.
Each chapter follows a consistent structure designed to support learning. Chapters begin with motivation and context, explaining why the topic matters and how it connects to previous material. The core content presents concepts progressively, starting with intuitive explanations before introducing mathematical formalism. Concrete examples appear throughout, not just at the end. These examples serve multiple purposes: they make abstract concepts tangible, they demonstrate practical application, and they reveal common pitfalls and how to avoid them. Pay attention to these examples—they often contain insights that aren't explicit in the main text. Many readers find it helpful to work through examples with pen and paper or by implementing them in code, even when complete code isn't provided.
The book balances intuition and rigor carefully. You'll find mathematical notation and formulas where they clarify concepts or enable implementation, but the book doesn't require advanced mathematical background. If you're comfortable with basic probability, statistics, and algebra, you have sufficient preparation. When more sophisticated mathematics appears, the text provides intuitive explanations alongside formal statements. Don't let the formulas intimidate you—they're tools for precision, not obstacles to understanding. If a mathematical section feels overwhelming, focus first on the intuitive explanation and concrete examples. Return to the formal treatment later once you've grasped the core ideas. Understanding the concepts matters more than memorizing formulas.
Implementation guidance appears throughout the book, not just in dedicated implementation chapters. You'll find pseudocode, code snippets, and detailed algorithms that you can translate into your preferred programming language. The book doesn't commit to a specific language or framework because the concepts transcend particular tools. Whether you work in Python, R, Java, or another language, you'll be able to implement the techniques described. That said, some familiarity with scientific computing libraries (like NumPy in Python or similar tools in other languages) will make implementation easier. The book assumes you can sample from standard probability distributions and perform basic numerical operations, which all major scientific computing environments support.
Active engagement dramatically improves learning outcomes. As you read, consider how the concepts apply to problems you face in your work. Can you frame a current challenge as a multi-armed bandit? What would the arms, rewards, and context be? How would you measure success? This mental translation from abstract concepts to concrete applications deepens understanding and reveals aspects of your problem you might not have considered. Keep a notebook or document where you record these connections, questions that arise, and ideas for applications. Many readers find that their best insights come not while reading but while reflecting on how the material applies to their specific context.
The book includes exercises and thought experiments, though not in a traditional textbook format. Instead, you'll find questions embedded in the text that invite you to pause and think before reading further. Take these seriously—they're not rhetorical. Spending a minute considering a question before seeing the answer significantly improves retention and understanding. Some sections also suggest implementation projects or experiments you can conduct. These are optional but highly valuable. There's no substitute for implementing an algorithm yourself and seeing how it behaves with real or simulated data. Even simple implementations reveal nuances that reading alone doesn't convey. If you have time for only one implementation project, make it a basic Thompson Sampling algorithm for Bernoulli bandits—this will solidify your understanding of the core concepts.
Different readers will have different goals, and the book supports multiple use cases. If you're a data scientist or machine learning engineer, you'll find detailed implementation guidance and performance analysis that enables you to deploy these algorithms in production systems. If you're a product manager or business analyst, you'll gain conceptual understanding that helps you recognize opportunities for these techniques and communicate effectively with technical teams. If you're a researcher or student, you'll find rigorous treatment of theoretical foundations along with pointers to academic literature for deeper exploration. If you're an executive or decision-maker, the applications chapter and case studies demonstrate business value and strategic implications. Regardless of your role, focus on the sections most relevant to your needs while maintaining enough breadth to understand how the pieces fit together.
The book's companion resources extend your learning beyond the text. The glossary provides quick reference for terminology, which is especially helpful when you return to the book after time away. The further reading section points you toward academic papers, textbooks, and online resources for deeper exploration of topics that interest you. These resources are curated to be accessible and high-quality—they're not just a comprehensive bibliography but a guided path for continued learning. The book also references open-source implementations and datasets you can use for experimentation. Taking advantage of these resources transforms the book from a one-time read into an ongoing reference and learning tool.
Finally, remember that mastery comes from application, not just understanding. Reading this book will give you knowledge, but applying that knowledge to real problems will give you skill. Start small—identify a low-stakes decision problem where you can experiment with these techniques. Implement a simple algorithm, run it on real or simulated data, and observe what happens. You'll encounter complications the book didn't anticipate and develop intuitions that reading alone can't provide. This experiential learning is invaluable. As you gain confidence, tackle more complex problems and more sophisticated algorithms. The journey from understanding to mastery is iterative, and each application deepens your expertise. This book provides the foundation and the roadmap, but you'll build the skill through practice and experimentation.
This is the end of the free sample. The full book has 10 chapters.
Want this book written for you?
Tell us your goals and background, and get your own version of this book, tailored by AI to you.
Benefits of AI-tailored books
- Read one book, not ten:
- all the Thompson Sampling knowledge you need, gathered into a single book.
- Save days of learning:
- tell us your goals, choose your topics, and the whole book is built around them.
- Learn effortlessly:
- Thompson Sampling book written for your specific background and expertise.
- Understand at a glance:
- includes charts, tables, timelines, checklists, decision trees, and more.
- Stay current:
- written the day you order it, not years ago.
- Trust what you read:
- every book is checked for accuracy, with real research when your subject needs it.
Create your unique book in 3 steps
- 1. Select your focus
Select the focus of your Thompson Sampling book and share your background
- 2. Personalize your book
Specify your goals and choose sub-topics to include
- 3. Get your tailored book
Your book is ready in 10 minutes. Read it online, download as EPUB or PDF, or send to Kindle.
Frequently asked questions
- What is TailoredRead?
TailoredRead creates complete, full-length nonfiction ebooks, written specifically for you. Tell us what you want to learn and why, and TailoredRead writes you a complete ebook on it, with charts, tables, and diagrams throughout. Read it online, on Kindle, or on any e-reader, or download it as a PDF or EPUB. Every book is written fresh the day you order it.
- How is the book tailored to me?
Before anything is written, you answer a few short questions about your goals, your background, and the topics you care about. Your book is then planned around your answers: written at your level, focused on your goals, and covering the topics you chose, instead of the one-size-fits-all book a store sells everyone.
- Will it read like generic AI content?
No. Your book isn't a chat transcript: it's planned chapter by chapter before a single word is written, told in a clear book voice, and explains ideas visually with charts, tables, and diagrams. After writing, every book goes through an editorial pass that polishes chapters so the book reads consistent from start to finish. Judge for yourself: browse thousands of sample books on our Explore Books page.
- How accurate is the content?
Our AI first checks whether your subject needs live research. Niche and fast-moving subjects are researched before writing, and the book plan and chapters are grounded in what it finds. After writing, every book goes through a quality pass that checks its facts and consistency, and researched books list their sources in a Notes section at the back.
- How long is the book?
You choose the length: Comprehensive (250-300 pages), Detailed (150-200 pages), Essential (70-100 pages), or Short (30-50 pages).
- Does the book include visuals?
Yes. Every book includes charts, tables, and diagrams: timelines, checklists, step-by-step guides, decision trees, comparison tables, matrices, and bar charts. A typical book includes dozens of these visual elements.
- Can I read it on Kindle? What formats can I download?
Yes. Every book can be read in our online reader or downloaded as a PDF or EPUB. The EPUB can be opened with Kindle, Apple Books, Kobo, and any e-reader. The Commercial and Author licenses also include an editable Word (DOCX) and Markdown download.
- How much does it cost?
About the price of a regular ebook. The exact price depends on your book's length and complexity, from $2 for the shortest books to $35 for the most comprehensive, and it's shown when you review your book, before you commit to anything. Each book is a one-time purchase, yours to keep, no subscription. Licenses that let you share, teach, or publish your book range from $35.99 to $49.99.
- Can I preview the book before purchasing?
Before you pay, you'll see what your book will cover: the title, a detailed description, the estimated length, and the complete chapter-by-chapter table of contents, so you know what you're getting before you decide. The full text itself is written after you purchase.
- How long does it take to create a book?
About 10 minutes. You can start reading the opening chapters while the rest is still being written.


