Thompson Sampling is a Bayesian algorithm that solves the exploration-exploitation dilemma by maintaining a probability distribution over the expected reward of each action. At each decision step, it samples a value from each action's posterior distribution and selects the action with the highest sample, naturally balancing the testing of uncertain price points against the exploitation of known high-performers.
Glossary
Thompson Sampling

What is Thompson Sampling?
A probabilistic algorithm for the multi-armed bandit problem that selects actions based on their probability of being optimal, efficiently balancing price exploration and exploitation.
In dynamic pricing, the algorithm models demand uncertainty using a prior distribution—often a Beta or Gaussian distribution—and updates it with observed purchase data. This approach converges to an optimal pricing policy faster than epsilon-greedy methods, making it ideal for real-time revenue optimization where the cost of a suboptimal price is immediate and measurable.
Key Characteristics of Thompson Sampling
Thompson Sampling is a Bayesian algorithm for the multi-armed bandit problem that selects actions in proportion to their probability of being optimal, providing an elegant and efficient balance between exploring uncertain price points and exploiting known high-reward ones.
Bayesian Foundation
Thompson Sampling operates on a Bayesian framework, maintaining a probability distribution over the unknown reward of each action rather than a point estimate. For each pricing decision, the algorithm samples a value from each posterior distribution and selects the action with the highest sample. This intrinsic randomness ensures that actions with high uncertainty are explored proportionally to their chance of being optimal. As data accumulates, the posterior distributions narrow, naturally shifting behavior from exploration to exploitation without requiring an explicit exploration parameter like epsilon in epsilon-greedy strategies.
Probability Matching Mechanism
The core mechanism is probability matching: an action is selected with a frequency equal to the probability that it is the best action given current knowledge. This is fundamentally different from optimistic initialization or epsilon-greedy approaches. Key properties include:
- Uncertainty-driven exploration: Actions with wide posterior distributions are selected more frequently
- Automatic annealing: Exploration naturally decreases as confidence grows
- No hyperparameter tuning: The exploration-exploitation trade-off emerges from the Bayesian update process itself
- Regret minimization: Achieves logarithmic expected regret, matching the theoretical lower bound for stochastic bandits
Conjugate Priors for Efficient Updating
Thompson Sampling achieves computational efficiency through the use of conjugate priors, which allow posterior distributions to be updated analytically rather than through expensive numerical methods. Common pairings include:
- Beta-Bernoulli: For binary outcomes like click/no-click or purchase/no-purchase at a given price point
- Gaussian-Gaussian: For continuous rewards like revenue per transaction, assuming known variance
- Gamma-Poisson: For count-based rewards like units sold per time period
- Dirichlet-Multinomial: For categorical outcomes with more than two possible results This analytical tractability makes Thompson Sampling suitable for real-time pricing systems requiring sub-millisecond decision latency.
Contextual Extension with Linear Models
The basic Thompson Sampling framework extends naturally to contextual bandits, where pricing decisions depend on observable features like customer segment, time of day, or inventory level. In the linear contextual variant, the algorithm maintains a multivariate Gaussian posterior over the coefficient vector of a linear reward model. For each decision, it samples a coefficient vector from this posterior and selects the price that maximizes the predicted reward given the current context. This enables personalized dynamic pricing that adapts to individual customer characteristics while maintaining the elegant exploration properties of the base algorithm.
Regret and Convergence Guarantees
Thompson Sampling provides strong theoretical guarantees that make it attractive for revenue-critical pricing applications:
- Logarithmic regret bound: The cumulative difference between the algorithm's rewards and the optimal policy grows only logarithmically with time, proven for Bernoulli and many other reward distributions
- Asymptotic optimality: Converges to selecting the truly optimal action with probability approaching 1 as data accumulates
- Finite-time bounds: Recent research provides explicit bounds on performance after a finite number of trials, enabling practical risk assessment
- Robustness to non-stationarity: When combined with discounting or sliding windows, adapts to slowly changing market conditions while maintaining theoretical guarantees
Implementation in Production Pricing Systems
Deploying Thompson Sampling in production dynamic pricing requires careful engineering considerations:
- Prior specification: Weakly informative priors (e.g., Beta(1,1) for Bernoulli) prevent strong initial bias while allowing rapid learning
- Warm-starting: Historical transaction data can inform initial prior parameters, avoiding the cold-start period
- Batch updating: In high-throughput systems, posterior updates can be batched to reduce computational load without significant regret increase
- Non-stationarity handling: Exponential decay weighting or sliding window approaches allow adaptation to shifting demand curves
- Constraint integration: Business rules like minimum margins or MAP compliance can be enforced as post-processing on sampled actions without breaking the Bayesian framework
Frequently Asked Questions
Clear, technical answers to the most common questions about the probabilistic algorithm that optimally balances exploration and exploitation in dynamic pricing and personalization systems.
Thompson Sampling is a probabilistic algorithm for the multi-armed bandit problem that selects actions based on their probability of being optimal given the observed data. It works by maintaining a posterior probability distribution over the expected reward of each action (e.g., a price point or product recommendation). At each decision step, the algorithm samples a value from each action's posterior distribution and selects the action with the highest sampled value. After observing the actual reward (e.g., a click or purchase), it updates the posterior distribution using Bayes' rule, refining its beliefs. This elegant mechanism naturally balances exploration—trying actions with high uncertainty—and exploitation—choosing actions with high estimated mean reward—without requiring a separate exploration schedule or epsilon parameter. In dynamic pricing, each price point is an 'arm,' and the reward is typically revenue or conversion, with the posterior often modeled as a Beta distribution for binary outcomes or a Gaussian distribution for continuous rewards.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Thompson Sampling vs. Other Bandit Algorithms
Comparative analysis of Thompson Sampling against alternative multi-armed bandit approaches for dynamic pricing and personalization use cases.
| Feature | Thompson Sampling | Epsilon-Greedy | Upper Confidence Bound (UCB) |
|---|---|---|---|
Exploration mechanism | Probabilistic matching via posterior sampling from Beta/Gaussian distributions | Random uniform exploration with fixed probability epsilon | Deterministic optimism bonus based on confidence interval upper bound |
Handles non-stationary rewards | |||
Incorporates prior knowledge | |||
Asymptotic regret bound | O(log T) logarithmic | O(T) linear | O(log T) logarithmic |
Empirical regret on cold start | Low (efficient early exploration) | High (wastes exploration budget) | Medium (over-explores initially) |
Computational complexity per round | O(1) with conjugate priors | O(1) | O(K) where K = number of arms |
Supports contextual bandits | |||
Natural uncertainty quantification |
Related Terms
Thompson Sampling is a cornerstone of modern dynamic pricing. Explore the related algorithms and concepts that form a complete revenue optimization stack.
Contextual Multi-Armed Bandits
An extension of the standard bandit framework that incorporates contextual features (e.g., user demographics, time of day) into the decision. While Thompson Sampling solves the basic explore/exploit dilemma, contextual bandits use a model to predict the reward of an action given the current context, enabling true real-time personalization.
Bayesian Optimization
A sequential design strategy for optimizing black-box objective functions that are expensive to evaluate. It uses a probabilistic surrogate model (often a Gaussian Process) and an acquisition function to decide where to sample next. Unlike Thompson Sampling, which selects discrete arms, Bayesian Optimization is ideal for tuning continuous hyperparameters like the exact discount percentage in a pricing model.
Reinforcement Learning for Pricing
A broader family of algorithms where an agent learns an optimal pricing policy through trial-and-error interaction with a market environment. Techniques include:
- Q-Learning: Learns the value of a price in a specific state.
- Policy Gradients: Directly optimizes the pricing policy. Thompson Sampling is often categorized as a simple, effective form of reinforcement learning for the multi-armed bandit sub-problem.
Price Elasticity Modeling
A foundational econometric technique that quantifies how the quantity demanded of a product changes in response to a price change. While Thompson Sampling learns optimal prices through direct experimentation, elasticity modeling provides the causal understanding of the demand curve. The two are complementary: elasticity estimates can form the prior distribution for a Thompson Sampling algorithm.
Champion-Challenger Framework
A production testing architecture where a new pricing model (the challenger) is deployed alongside the incumbent model (the champion). A small percentage of traffic is routed to the challenger to empirically validate its performance. Thompson Sampling naturally implements this by continuously allocating traffic to the best-performing price points, making it an ideal algorithm for automated champion-challenger testing.
Concept Drift
The phenomenon where the statistical relationship between price and demand changes over time in unforeseen ways. A static Thompson Sampling model with fixed priors can become stale. To combat this, implementations often use a sliding window or discount factor to weight recent observations more heavily, ensuring the algorithm adapts to shifting market conditions and consumer behavior.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us