# 老虎机算法

老虎机算法是一种序贯决策方法，它从一个固定或变化的动作集合中反复选择一个动作，仅观测所选动作的回报，并更新其选择规则以在不确定性下最大化累积回报。该名称来自老虎机的俗称——“独臂强盗”。每一轮都面临探索—利用权衡：利用已知表现良好的动作可最大化即时回报，而探索了解甚少的动作则收集信息以改善未来决策。老虎机算法介于监督学习与强化学习之间：可将其视为仅有一个状态的强化学习，它与全信息设定的区别在于只能观测到所选臂的收益。<sup>[1](https://ar5iv.labs.arxiv.org/html/1510.00757)</sup>

| 关键事实 | 详情 |
|---|---|
| 每轮输出 | 选择一个臂（动作）；仅观测该臂的回报<sup>[1](https://ar5iv.labs.arxiv.org/html/1510.00757)</sup> |
| 目标 | 最小化遗憾，即始终拉最佳臂与算法期望回报之间的差距<sup>[2](https://jmlr.org/papers/volume3/auer02a/auer02a.pdf)</sup> |
| 最优遗憾增长 | 依Lai–Robbins下界，为时间跨度T的对数级<sup>[3](https://doi.org/10.1016/0196-8858%2885%2990002-8)</sup> |
| 主要算法族 | ε-贪心、UCB、汤普森采样（随机性）；EXP3型指数权重（对抗性） |
| UCB1保证 | 对[0,1]内的回报，在无分布先验知识的情况下，对n一致地实现对数遗憾<sup>[4](https://doi.org/10.1023/a:1013689704352)</sup> |
| 典型部署 | 广告投放、新闻推荐、临床试验、A/B测试、超参数调优<sup>[5](https://web.stanford.edu/%7Ebvr/pubs/TS_Tutorial.pdf)</sup> |

## 工作原理

在随机多臂老虎机问题中，算法在每个时间步拉动K个臂之一，收到从[0,1]支撑的某个固定未知分布独立抽取的回报，仅观测该臂的回报，目标是最小化与最佳臂相比的遗憾。<sup>[6](http://www.columbia.edu/~sa3305/INFORMS2021-tutorial.pdf)</sup> 随机老虎机的遗憾定义为 \( R(T) := T \cdot \mu^{*} - \mathbb{E}\big[\sum_{t} R_t\big] = \sum_{a} (\mu^{*} - \mu_a)\, \mathbb{E}[N_{a,T}] \)，其中 \( \mu^{*} \) 是最佳臂的均值，\( N_{a,t} \) 统计臂a被拉动的次数；因此遗憾分解为每个次优臂的差距与其期望拉动次数之积的总和。<sup>[7](https://chercheurs.lille.inria.fr/munos/papers/files/Thompson_ALT2012.pdf)</sup>

根据回报过程存在三种基本形式化：随机性（由UCB类算法处理）、对抗性（由Exp3处理）和马尔可夫性（由吉廷斯指数处理）。在对抗性设定中，不对回报如何生成做任何统计假设，遗憾是相对于最佳固定策略定义的。<sup>[2](https://jmlr.org/papers/volume3/auer02a/auer02a.pdf)</sup>

主要决策规则很简单。ε-贪心以概率 \( 1 - \varepsilon \) 利用后验均值，以概率 \( \varepsilon \) 均匀随机探索。<sup>[8](https://bayesianbandits.readthedocs.io/en/latest/math/policies.html)</sup> UCB为每个臂的估计构建置信区间，并拉动上置信界最高的臂；UCB(α)指数为经验均值加上 \( \sqrt{\alpha \log t / (2 N_i(t))} \)，因此被频繁拉动的臂获得较窄的区间，探索被内置其中。<sup>[9](https://people.maths.bris.ac.uk/%7Emaajg/teaching/stochopt/ucb.pdf)</sup><sup> • </sup><sup>[10](https://courses.cs.washington.edu/courses/cse312/22su/files/slides/L24_8-17_bandits_annotated.pdf)</sup> [汤普森采样](https://www.edgepedia.org/zh/thompson-sampling)源自该问题的最早论文，它假设每个臂均值的先验，从每个后验中抽取样本 \( \theta_{i,t} \)，并选择样本最大的臂；对于采用 \( \mathrm{Beta}(1,1) \) 先验的伯努利回报，后验在每次观测到成功或失败时更新为 \( \mathrm{Beta}(s+1, f+1) \)。<sup>[10](https://courses.cs.washington.edu/courses/cse312/22su/files/slides/L24_8-17_bandits_annotated.pdf)</sup> 线性老虎机算法基于面对不确定性时的乐观（OFU）原则：维护一个与数据一致的可能环境的置信集，然后在最有利的环境中采取最优行动。<sup>[11](https://proceedings.neurips.cc/paper/2011/file/e1d5be1c7f2f456670de3d53c7b54f4a-Paper.pdf)</sup>

Lai–Robbins下界指出，对于任何强一致策略，次优臂i的期望拉动次数满足 \( \liminf_{T \to \infty} \mathbb{E}[N_i(T)] / \ln T \ge 1/K(\mu_i, \mu^{*}) \)，其中信息项是该臂回报分布与最佳臂回报分布之间的KL散度（对于伯努利回报，即均值之间的伯努利KL散度），因此遗憾至少必须以拉动次数的对数增长；达到该速率的算法被认为解决了该问题。<sup>[3](https://doi.org/10.1016/0196-8858%2885%2990002-8)</sup><sup> • </sup><sup>[9](https://people.maths.bris.ac.uk/%7Emaajg/teaching/stochopt/ucb.pdf)</sup><sup> • </sup><sup>[12](https://www.cs.mcgill.ca/~vkules/bandits.pdf)</sup> UCB1在回报位于[0,1]的所有臂上、在无回报分布先验知识的情况下，对时间跨度一致地实现对数遗憾，而KL-UCB变体达到遗憾的最优渐近增长率。<sup>[4](https://doi.org/10.1023/a:1013689704352)</sup><sup> • </sup><sup>[9](https://people.maths.bris.ac.uk/%7Emaajg/teaching/stochopt/ucb.pdf)</sup> 对于汤普森采样，Agrawal和Goyal证明了两臂情况下期望遗憾的首个对数界 \( O(\ln T/\Delta + 1/\Delta^3) \)，<sup>[13](https://doi.org/10.48550/arxiv.1111.1797)</sup> Kaufmann、Korda和Munos展示了有限时间界，其主导项为 \( (1+\varepsilon) \sum_{a} \Delta_a \ln T / K(\mu_a, \mu^{*}) \) 加上依赖于问题的 \( O(\ln \ln T) \) 项和常数项，与Lai–Robbins下界匹配，因此汤普森采样在常数和速率上都是渐近最优的。<sup>[7](https://chercheurs.lille.inria.fr/munos/papers/files/Thompson_ALT2012.pdf)</sup><sup> • </sup><sup>[14](https://lucasjanson.fas.harvard.edu/courses/10a.pdf)</sup>

## 如何实施

在实践中，规则的选择更多由经验性能而非理论驱动。在跨十二种老虎机设定的比较中，简单启发式ε-贪心和玻尔兹曼（softmax）探索在大多数设定上优于理论上可靠的算法；softmax在几乎所有实例上比具有理论保证的最佳算法UCB1-Tuned产生的遗憾至少少50%，且性能随臂数和回报方差剧烈变化。<sup>[12](https://www.cs.mcgill.ca/~vkules/bandits.pdf)</sup> 部署还必须在多臂方法与上下文方法、同策略与离策略设定、延迟反馈与即时反馈之间做出选择。<sup>[15](https://ar5iv.labs.arxiv.org/html/2302.01223)</sup>

## 起源

首个老虎机算法出现在W. R. 汤普森（W. R. Thompson）1933年发表于《[Biometrika](https://www.edgepedia.org/zh/biometrika)》的论文中，该论文研究一个未知概率超过另一个未知概率的可能性，提出了带伯努利回报的随机老虎机来建模医疗分配问题，并呈现了后来被称为汤普森采样的方法。<sup>[16](https://doi.org/10.1093/biomet/25.3-4.285)</sup> 该算法在很大程度上被忽视，直到20世纪90年代末和2000年被独立重新发现。<sup>[5](https://web.stanford.edu/%7Ebvr/pubs/TS_Tutorial.pdf)</sup> 黎子良（T. L. Lai）和[赫伯特·罗宾斯](https://www.edgepedia.org/zh/herbert-robbins)（Herbert Robbins）1985年发表于《Advances in Applied Mathematics》的论文《Asymptotically efficient adaptive allocation rules》建立了对数下界和用于渐近分析的[上置信界](https://www.edgepedia.org/zh/upper-confidence-bound)技术。<sup>[3](https://doi.org/10.1016/0196-8858%2885%2990002-8)</sup> UCB1、UCB2、\( \varepsilon_n \)-贪心和UCB1-NORMAL由彼得·奥尔（Peter Auer）、尼科洛·切萨-比安奇（Nicolò Cesa-Bianchi）和保罗·菲舍尔（Paul Fischer）在《Finite-time Analysis of the Multiarmed Bandit Problem》（《Machine Learning》，2002年）中分析，该文给出了首个有限时间界。<sup>[4](https://doi.org/10.1023/a:1013689704352)</sup> 现代对汤普森采样的兴趣由奥利维耶·沙佩勒（Olivier Chapelle）和李利宏（Lihong Li）2011年的实证评估激发，该评估展示了其在展示广告和新闻推荐等应用中的强劲表现。<sup>[17](https://www.cs.ubc.ca/~hutter/nips2011workshop/papers_and_posters/Agrawal-Goyal-TS-report.pdf)</sup><sup> • </sup><sup>[5](https://web.stanford.edu/%7Ebvr/pubs/TS_Tutorial.pdf)</sup>

## 变体

**上下文与线性老虎机**为每一轮添加辅助信息。对于有限上下文空间，UCB指数变为 \( \hat{\mu}^{(k)}_t(x_t) + \sqrt{\ln(2 T \cdot K \lvert X\rvert/\delta) / (2 N^{(k)}_t(x_t))} \)；对于大上下文空间，信息通过线性模型 \( \mu^{(k)}(x) = \theta_k^{\top} \cdot x \) 共享。<sup>[14](https://lucasjanson.fas.harvard.edu/courses/10a.pdf)</sup> LinUCB——一种自然的上置信界算法，由李利宏（Lihong Li）、楚威（Wei Chu）、约翰·兰福德（John Langford）和罗伯特·E·沙皮尔（Robert E. Schapire）于2010年提出并实验演示——以及SupLinUCB是标准的线性算法。<sup>[11](https://proceedings.neurips.cc/paper/2011/file/e1d5be1c7f2f456670de3d53c7b54f4a-Paper.pdf)</sup>

**组合老虎机**让学习者在每轮拉动基础臂的一个子集（超级臂），并带有半老虎机反馈；上下文组合老虎机可扩展到数十万个臂，且遗憾界与臂数无关。<sup>[18](https://www.cse.cuhk.edu.hk/~cslui/PUBLICATION/Combinatorial_Logistic_Online_Learning_and_Its_Applications_in_Nonlinear_Networked_Systems.pdf)</sup> **无休老虎机**让每个臂的状态无论是否被拉动都按[马尔可夫链](https://www.edgepedia.org/zh/markov-chain)演化；Restless-UCB实现 \( \tilde{O}((N + M^3)\sqrt{T}) \) 阶的遗憾。<sup>[19](https://proceedings.neurips.cc/paper/2020/file/89ae0fe22c47d374bc9350ef99e01685-Paper.pdf)</sup> **Bayes-UCB**使用后验分位数 \( Q(1-\alpha_t, \lambda_{tj}) \) 作为上置信界，其中 \( \alpha_t \) 为 \( 1/t \) 阶，且对二元老虎机是渐近最优的。<sup>[20](http://proceedings.mlr.press/v22/kaufmann12/kaufmann12.pdf)</sup> **神经老虎机**如EE-Net用网络学习探索，该网络以利用网络的梯度为输入，实现基于实例的 \( \tilde{O}(\sqrt{T}) \) 界。<sup>[21](https://arxiv.org/pdf/2305.03784)</sup> 在非随机设定中，EXP3-IX达到高概率遗憾界。<sup>[22](https://doi.org/10.48550/arxiv.1506.03271)</sup> 近期一个方向将老虎机与大语言模型结合：TS-LLM使用预训练LLM在汤普森采样内部以衰减温度调度采样回报值，RO-LLM将LLM用作SquareCB型算法内部的回归预言机；两者均持续优于基于直接LLM臂选择的基线。<sup>[23](https://arxiv.org/html/2502.01118)</sup> EVOLvE基准（2024年）衡量LLM在老虎机中做出最优决策的能力，涵盖无上下文和上下文任务，并通过遗憾分析探索效率。<sup>[24](https://doi.org/10.48550/arxiv.2410.06238)</sup>

## 应用

汤普森采样及相关老虎机方法已在Adobe、Amazon、Facebook、Google、LinkedIn、Microsoft、Netflix和Twitter应用于收益管理、广告、推荐、超参数调优和[蒙特卡洛树搜索](https://www.edgepedia.org/zh/monte-carlo-tree-search)。<sup>[5](https://web.stanford.edu/%7Ebvr/pubs/TS_Tutorial.pdf)</sup> 微软用于Bing搜索广告点击率预测的adPredictor使用了汤普森采样的思想，沙佩勒和李利宏实证表明汤普森采样在展示广告和新闻文章推荐中与UCB相当或更优，且对延迟或批量反馈更稳健。<sup>[17](https://www.cs.ubc.ca/~hutter/nips2011workshop/papers_and_posters/Agrawal-Goyal-TS-report.pdf)</sup> 上下文线性老虎机已应用于互联网广告选择和门户网站文章推荐。<sup>[11](https://proceedings.neurips.cc/paper/2011/file/e1d5be1c7f2f456670de3d53c7b54f4a-Paper.pdf)</sup> 源自UCB的分层老虎机UCT策略已在MoGo围棋系统中实现。老虎机与[A/B测试](https://www.edgepedia.org/zh/a-b-testing)服务于不同目的：当需要统计置信度或回报延迟时，传统A/B测试更受青睐；而当目标仅仅是最大化回报、机会成本高、或实验中途可添加或移除臂时，老虎机更受青睐。<sup>[10](https://courses.cs.washington.edu/courses/cse312/22su/files/slides/L24_8-17_bandits_annotated.pdf)</sup>

## 局限与替代方案

经典老虎机工作处理的动作空间相对于涵盖数百万条目的推荐目录而言较小，因为遗憾界通常依赖于动作空间的大小，而平台通常产生大动作空间，现有方法在其中往往失效。<sup>[15](https://ar5iv.labs.arxiv.org/html/2302.01223)</sup> 优雅的理论结果依赖于关于平稳性和结果即时观测的限制性假设，这些假设很少能转化为实际应用，且大规模部署实时更新远非易事。<sup>[15](https://ar5iv.labs.arxiv.org/html/2302.01223)</sup> 实践中的回报在延迟下被观测，需要偏差估计和缓解，回报设计必须平衡长期和短期指标。<sup>[15](https://ar5iv.labs.arxiv.org/html/2302.01223)</sup> 非平稳性是一个关键局限：快速的分布变化和切换型模型（昼夜、季节）在许多固定策略上表现极差。<sup>[1](https://ar5iv.labs.arxiv.org/html/1510.00757)</sup> 反馈延迟，尤其是临床试验中治疗响应可能需要数月的极长延迟，在文献中考虑不足。<sup>[1](https://ar5iv.labs.arxiv.org/html/1510.00757)</sup> 离策略方法在实践中比同策略方法更丰富，但离策略评估依赖于记录的动作选择概率，而这些概率并不总是可用或可靠。<sup>[15](https://ar5iv.labs.arxiv.org/html/2302.01223)</sup>

## References

1. [A Survey of Online Experiment Design with the Stochastic Multi-Armed Bandit (arXiv 1510.00757)](https://ar5iv.labs.arxiv.org/html/1510.00757)
2. [The Nonstochastic Multiarmed Bandit Problem (Auer, Cesa-Bianchi, Freund, Schapire; JMLR)](https://jmlr.org/papers/volume3/auer02a/auer02a.pdf)
3. [Asymptotically efficient adaptive allocation rules (Advances in Applied Mathematics, 1985)](https://doi.org/10.1016/0196-8858%2885%2990002-8)
4. [Peter Auer, Nicolò Cesa-Bianchi, Paul Fischer (2002). Finite-time Analysis of the Multiarmed Bandit Problem. Machine Learning.](https://doi.org/10.1023/a:1013689704352)
5. [A Tutorial on Thompson Sampling (Russo, Van Roy et al.; Stanford copy)](https://web.stanford.edu/%7Ebvr/pubs/TS_Tutorial.pdf)
6. [Explore and Exploit (UCB, TS), INFORMS 2021 tutorial (Columbia University)](http://www.columbia.edu/~sa3305/INFORMS2021-tutorial.pdf)
7. [Thompson Sampling: An Asymptotically Optimal Finite Time Analysis (Kaufmann, Korda, Munos; ALT 2012)](https://chercheurs.lille.inria.fr/munos/papers/files/Thompson_ALT2012.pdf)
8. [Exploration Policies (bayesianbandits documentation)](https://bayesianbandits.readthedocs.io/en/latest/math/policies.html)
9. [The UCB algorithm (lecture notes, University of Bristol)](https://people.maths.bris.ac.uk/%7Emaajg/teaching/stochopt/ucb.pdf)
10. [Bandits lecture slides, CSE 312, University of Washington](https://courses.cs.washington.edu/courses/cse312/22su/files/slides/L24_8-17_bandits_annotated.pdf)
11. [Improved Algorithms for Linear Stochastic Bandits (Chu et al.; NeurIPS 2011), with excerpts from the author-site copy 'Contextual Bandits with Linear Payoff Functions'](https://proceedings.neurips.cc/paper/2011/file/e1d5be1c7f2f456670de3d53c7b54f4a-Paper.pdf)
12. [Algorithms for the Multi-Armed Bandit Problem (Kuleshov & Precup)](https://www.cs.mcgill.ca/~vkules/bandits.pdf)
13. [Agrawal, Shipra, Goyal, Navin (2011). Analysis of Thompson Sampling for the multi-armed bandit problem. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1111.1797)
14. [Bandits: Thompson Sampling and Contextual Bandits (Harvard course notes)](https://lucasjanson.fas.harvard.edu/courses/10a.pdf)
15. [Practical Bandits: An Industry Perspective (arXiv 2302.01223)](https://ar5iv.labs.arxiv.org/html/2302.01223)
16. [W. R THOMPSON (1933). ON THE LIKELIHOOD THAT ONE UNKNOWN PROBABILITY EXCEEDS ANOTHER IN VIEW OF THE EVIDENCE OF TWO SAMPLES. Biometrika.](https://doi.org/10.1093/biomet/25.3-4.285)
17. [Analysis of Thompson Sampling for the Multi-armed Bandit Problem (Agrawal, Goyal)](https://www.cs.ubc.ca/~hutter/nips2011workshop/papers_and_posters/Agrawal-Goyal-TS-report.pdf)
18. [Combinatorial Logistic Online Learning and Its Applications in Nonlinear Networked Systems](https://www.cse.cuhk.edu.hk/~cslui/PUBLICATION/Combinatorial_Logistic_Online_Learning_and_Its_Applications_in_Nonlinear_Networked_Systems.pdf)
19. [Restless-UCB, an Efficient and Low-complexity Algorithm for Online Restless Bandits (NeurIPS 2020)](https://proceedings.neurips.cc/paper/2020/file/89ae0fe22c47d374bc9350ef99e01685-Paper.pdf)
20. [On Bayesian Upper Confidence Bounds for Bandit Problems (Kaufmann, Cappé, Garivier; AISTATS 2012)](http://proceedings.mlr.press/v22/kaufmann12/kaufmann12.pdf)
21. [EE-Net: Exploration-Exploitation in Contextual Bandits via Neural Networks (arXiv 2305.03784)](https://arxiv.org/pdf/2305.03784)
22. [Neu, Gergely (2015). Explore no more: Improved high-probability regret bounds for non-stochastic bandits. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1506.03271)
23. [Large Language Model-Enhanced Multi-Armed Bandits (arXiv 2502.01118; ACL 2026)](https://arxiv.org/html/2502.01118)
24. [Nie, Allen and colleagues (2024). EVOLvE: Evaluating and Optimizing LLMs For In-Context Exploration. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2410.06238)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026; Oct 21, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/bandit-algorithm

English original: https://www.edgepedia.org/bandit-algorithm
