# 直接抽样（蒙特卡洛）

直接抽样是一种蒙特卡洛技术：它对均匀随机数施加一个固定的变换，从而精确地从目标概率分布生成独立的随机抽样，既不拒绝候选样本，也不附加重要性权重。直接抽样器是这样一种算法：它产生服从给定密度 f 的独立随机变量，并通过映射 x = G(u₁, …, u_k) 消耗掉事先已知数量的均匀随机数。<sup>[1](https://math.nyu.edu/~goodman/teaching/MonteCarlo12/notes/Week1.pdf)</sup> 已发表的比较研究把逆变换法与拒绝抽样视为从目标分布抽样的两种最基本方法。<sup>[2](https://people.smp.uq.edu.au/DirkKroese/ps/stat03619.pdf)</sup> 由于抽样彼此独立且不加权，直接方法速度很快；只要存在可用的直接方法，它往往就是首选的抽样算法。<sup>[3](http://www.lucamartino.altervista.org/BOOKIndependentRandomSamplingMethods.pdf)</sup> 在贝叶斯统计中，对后验量做直接模拟之所以受重视，是因为它应用直截了当、收敛性得益于独立性，而且易于在多核或多集群上并行化。<sup>[4](https://papers.tinbergen.nl/12098.pdf)</sup>

| 要点 | 说明 |
|---|---|
| 输出 | 通过均匀数的固定映射，从精确的目标密度得到独立、不加权的抽样<sup>[1](https://math.nyu.edu/~goodman/teaching/MonteCarlo12/notes/Week1.pdf)</sup><sup> • </sup><sup>[3](http://www.lucamartino.altervista.org/BOOKIndependentRandomSamplingMethods.pdf)</sup> |
| 一般形式 | 抽取 (0, 1) 上均匀的 U₁, …, U_k；返回 X = g(U₁, …, U_k)<sup>[2](https://people.smp.uq.edu.au/DirkKroese/ps/stat03619.pdf)</sup> |
| 核心机制 | 逆变换：对 [0, 1] 上均匀的 \( U \)，取 \( X = F^{-1}(U) \)<sup>[5](https://pdg.lbl.gov/2026/reviews/rpp2026-rev-monte-carlo-techniques.pdf)</sup> |
| 算例 | 标准指数变量由 \( \log(1/U) \) 生成<sup>[6](https://luc.devroye.org/handbooksimulation1.pdf)</sup> |
| 博克斯–米勒法 | 两个均匀数产生两个独立的标准正态变量<sup>[6](https://luc.devroye.org/handbooksimulation1.pdf)</sup> |
| 拒绝法基准 | 拒绝常数为 c 时，每次接受所需的平均提议数为 \( E[N] = c \)<sup>[7](https://hef.ru.nl/~tbudd/mct/lectures/monte_carlo_integration.html)</sup> |
| 比较方法 | 某一特例生成正态随机变量的平均代价为每个消耗 4.036 个均匀随机变量<sup>[8](http://i.stanford.edu/pub/cstr/reports/cs/tr/72/254/CS-TR-72-254.pdf)</sup> |

## 工作原理

最常见的直接方法，其基础是对累积分布函数作反演。若按密度 f(a) 抽得一个值 a，那么到 a 为止的累积概率 F(a) 本身就是一个在 [0, 1] 上均匀分布的随机变量；令 \( u = F(x) \) 并解出 \( x = F^{-1}(u) \)，就把一个均匀变量转换成了来自 f 的抽样——前提是能找到 F 的逆。<sup>[5](https://pdg.lbl.gov/2026/reviews/rpp2026-rev-monte-carlo-techniques.pdf)</sup> 等价地说，给定分布函数 F 及其逆，取 [0, 1] 上均匀的 \( U \)，生成 \( X = F^{-1}(U) \)；当逆函数易于计算时，这就是首选方法。<sup>[6](https://luc.devroye.org/handbooksimulation1.pdf)</sup> 当 F 并非严格单调时，逆定义为 F⁻¹(u) = inf{x ∈ ℝ | F(x) ≥ u}；当 F 为双射时，它与通常的逆一致。<sup>[2](https://people.smp.uq.edu.au/DirkKroese/ps/stat03619.pdf)</sup>

样本在分布上是精确的：每个抽样都服从 f，既无接受检验，也无权重校正。当累积分布函数 F（定义为 f 从其支撑集下端起的归一化积分）的逆可以手算时，该方法最为便利——此时使用广义逆 \(F^{-1}(u)=\inf\{x:F(x)\ge u\}\)，例如对 f(x) = e⁻ˣ（x > 0）、(1 − x)ⁿ（0 ≤ x ≤ 1）以及 1/(1 + x²)（柯西密度或布莱特–维格纳密度）。<sup>[5](https://pdg.lbl.gov/2026/reviews/rpp2026-rev-monte-carlo-techniques.pdf)</sup> 更一般地，直接抽样器可以对某个固定的 k 使用 k 个均匀数，并返回 X = g(U₁, …, U_k)，其中 g 为适当的函数；其关键的结构性特征是，k 在抽样开始之前就已确定，这与拒绝方法不同——后者消耗的均匀数个数未知。<sup>[1](https://math.nyu.edu/~goodman/teaching/MonteCarlo12/notes/Week1.pdf)</sup>

## 操作步骤

实践者需执行四个步骤。第一，指定目标密度 f 及其累积分布函数 F。第二，用伪随机发生器从 (0, 1) 上抽取一个或多个均匀随机数 U。第三，施加变换：对逆变换法计算 X = F⁻¹(U)；对其他直接方法则施加专门构造的映射。例如，密度为 e⁻ˣ（x > 0）的标准指数随机变量由 log(1/U) 生成。<sup>[6](https://luc.devroye.org/handbooksimulation1.pdf)</sup>

第四，当不存在闭式逆时，标准程序库中含有以数值方式实现反演的软件<sup>[5](https://pdg.lbl.gov/2026/reviews/rpp2026-rev-monte-carlo-techniques.pdf)</sup>，不过这要求对 (0, 1) 中任意 \( p \) 都能高效地计算 \( F^{-1}(p) \)，否则就不得不付出高昂的数值近似代价。<sup>[7](https://hef.ru.nl/~tbudd/mct/lectures/monte_carlo_integration.html)</sup>

## 起源

历史记录集中在洛斯阿拉莫斯。梅特罗波利斯（Metropolis）与乌拉姆（Ulam）1949 年发表于《美国统计学会会刊》、题为《蒙特卡洛方法》的论文，是承载该方法之名的经典文献。<sup>[9](https://doi.org/10.1080/01621459.1949.10483310)</sup> 1949 年夏，在加利福尼亚大学洛杉矶分校校园内的数值分析研究所，约翰·冯·诺伊曼（John von Neumann）就生成伪随机数与随机变量的各个方面作了讲演。<sup>[8](http://i.stanford.edu/pub/cstr/reports/cs/tr/72/254/CS-TR-72-254.pdf)</sup> 抽样重要性重采样由唐纳德·B·鲁宾（Donald B. Rubin）在 1987 年《美国统计学会会刊》的一则评论中作了描述。<sup>[10](https://doi.org/10.2307/2289460)</sup> 基于离散化的直接随机样本生成方法及其 dsample R 包，由王立群（Liqun Wang）与李哲熙（Chel Hee Lee）在 2013 年《计算统计与数据分析》的一篇论文中提出。<sup>[11](https://doi.org/10.1016/j.csda.2013.06.011)</sup>

## 变体

若干有名称的构造可在不同情形下给出直接抽样：

- **逆变换抽样。** 基准方法 \( X = F^{-1}(U) \)，对均匀数 u 返回累积分布函数（cdf）的第 u 分位数。<sup>[12](https://www.informs-sim.org/wsc17papers/includes/files/017.pdf)</sup>
- **复合抽样。** 当密度 f 可写成 r 个其他密度的加权和（即混合分布）时使用；先选出一个分量，再从该分量抽样。<sup>[12](https://www.informs-sim.org/wsc17papers/includes/files/017.pdf)</sup> 在贝叶斯工作中，当联合分布可分解为边缘分布与条件分布之积时，复合抽样法从后验 p(θ | ·) 抽样。<sup>[13](https://web.ics.purdue.edu/~jltobias/BayesClass/lecture_notes/direct_simulation_student.pdf)</sup>
- **博克斯–米勒法。** 把两个独立均匀数变成两个独立标准正态变量（均值为零、方差为 1），尽管它未必是生成大量独立同分布标准正态变量的最佳方式。<sup>[6](https://luc.devroye.org/handbooksimulation1.pdf)</sup>
- **贝叶斯直接方法。** 一种称为直接抽样（DS）的非 MCMC 方法，从目标后验生成独立样本，无须担心链收敛或自相关问题；其推广变体（GDS）是一种重要性抽样形式，适用于高维分层模型。<sup>[14](https://arxiv.org/html/1108.2245v3)</sup> “直接蒙特卡洛”（DMC）这一名称，指的是在不作拒绝、不作重要性加权、不走马尔可夫链步骤的情况下模拟独立抽样。<sup>[4](https://papers.tinbergen.nl/12098.pdf)</sup>
- **SIR。** 抽样重要性重采样从一个重要性抽样函数 g（通俗地说是一个包络）中抽样，再对各点重新加权并重采样；它基于重要性思想，而非直接方法。<sup>[15](https://www.hds.utc.fr/~tdenoeux/dokuwiki/_media/en/simulation.pdf)</sup>

## 应用

在贝叶斯计算中，直接模拟为工具变量模型等模型提供后验抽样：独立抽样有助于提高模拟结果的收敛速度，并给出精确的数值标准误。<sup>[4](https://papers.tinbergen.nl/12098.pdf)</sup> 对分层贝叶斯模型而言，直接抽样及其推广变体所瞄准的后验，正是 MCMC 处理起来要操心收敛与自相关的那些后验，而独立样本可以并行收集。<sup>[14](https://arxiv.org/html/1108.2245v3)</sup> 在物理学中，粒子数据组（Particle Data Group）关于蒙特卡洛技术的综述把逆变换抽样视为标准工具，用来把均匀随机数转换为来自布莱特–维格纳线型等物理分布的抽样。<sup>[5](https://pdg.lbl.gov/2026/reviews/rpp2026-rev-monte-carlo-techniques.pdf)</sup> 基于离散化的直接方法只要求知道目标密度的形式，允许其中有一个未知的乘性常数，既适用于标准分布，也适用于来自真实数据的高维分布。<sup>[16](https://home.cc.umanitoba.ca/~wangl1/papers/walee14.pdf)</sup>

## 局限与替代方法

当所需的变换不可得时，直接抽样便失效。反演需要一种对 (0, 1) 中任意 \( p \) 高效计算 \( F^{-1}(p) \) 的途径；许多情况下 F 没有闭式表达式，更不用说其逆了，于是不得不付出高昂的数值近似代价，而把反演用于多个随机变量的联合分布就更具挑战性。<sup>[7](https://hef.ru.nl/~tbudd/mct/lectures/monte_carlo_integration.html)</sup> 更广泛地说，实践中遇到的大多数概率分布都没有实用的直接抽样器，对它们抽样可能需要依目标与可用提议分布而定，采用拒绝抽样、重要性抽样或 MCMC 等方法，尽管直接抽样器是多数 MCMC 方法的重要组成部分。<sup>[1](https://math.nyu.edu/~goodman/teaching/MonteCarlo12/notes/Week1.pdf)</sup>

最接近的替代方法各有不同的代价。拒绝抽样要求对一切 \( x \) 都有 \( f(x) \le C \cdot g(x) \)，其中 \( C \ge 1 \) 为某常数；它以概率 \( f(y)/(C \cdot g(y)) \) 接受提议 \( y \)，因而总体接受概率为 \( 1/C \)，而其效率往往随维数 d 增大而下降<sup>[2](https://people.smp.uq.edu.au/DirkKroese/ps/stat03619.pdf)</sup>；即便对强对数凹的目标，一次接受之前的期望拒绝次数也约为 \( \kappa^{d/2} \)，其中 \( \kappa \) 是势函数的条件数。<sup>[17](https://papers.nips.cc/paper_files/paper/2024/file/8337b176767d948275d0b6d17cf4221e-Paper-Conference.pdf)</sup> 重要性抽样与 SIR 避免了拒绝，却通过包络密度引入了权重。<sup>[15](https://www.hds.utc.fr/~tdenoeux/dokuwiki/_media/en/simulation.pdf)</sup> MCMC 构造一条遍历马尔可夫链，其极限密度为 \( p(x)/Z \)，其有用之处在于归一化常数 Z 无须显式已知；但它产生的变量彼此相关、需要预热期、可能陷入局部众数，并且所得估计量的方差大于独立样本方法所得估计量的方差。<sup>[2](https://people.smp.uq.edu.au/DirkKroese/ps/stat03619.pdf)</sup><sup> • </sup><sup>[3](http://www.lucamartino.altervista.org/BOOKIndependentRandomSamplingMethods.pdf)</sup> 拟蒙特卡洛用确定性的低偏差节点取代随机样本，可以达到确定性的误差界 \( O(N^{-1} \log(N)^{m-1}) \)。<sup>[3](http://www.lucamartino.altervista.org/BOOKIndependentRandomSamplingMethods.pdf)</sup> 贝叶斯直接抽样方法本身只限于小规模问题，所考虑的最大案例有 10 个参数。<sup>[14](https://arxiv.org/html/1108.2245v3)</sup>

## References

1. [Introduction to Monte Carlo (Goodman, NYU course notes)](https://math.nyu.edu/~goodman/teaching/MonteCarlo12/notes/Week1.pdf)
2. [Monte Carlo Methods (Kroese), Simulation of probability distributions](https://people.smp.uq.edu.au/DirkKroese/ps/stat03619.pdf)
3. [Independent Random Sampling Methods (Martino; excerpts from the repository copy at ndl.ethernet.edu.et merged here)](http://www.lucamartino.altervista.org/BOOKIndependentRandomSamplingMethods.pdf)
4. [Bayesian Analysis of Instrumental Variable Models: Acceptance-Rejection within Direct Monte Carlo](https://papers.tinbergen.nl/12098.pdf)
5. [Monte Carlo Techniques (Particle Data Group review, 2026 revision; content merged with the 2024 edition at pdg.ge.infn.it)](https://pdg.lbl.gov/2026/reviews/rpp2026-rev-monte-carlo-techniques.pdf)
6. [Non-Uniform Random Variate Generation (Devroye), Chapter 1: The inversion method](https://luc.devroye.org/handbooksimulation1.pdf)
7. [Direct-sampling Monte Carlo integration, Monte Carlo Techniques (Radboud University lecture notes)](https://hef.ru.nl/~tbudd/mct/lectures/monte_carlo_integration.html)
8. [Von Neumann's comparison method for random sampling from the normal and other distributions (Forsythe, Stanford CS-TR-72-254)](http://i.stanford.edu/pub/cstr/reports/cs/tr/72/254/CS-TR-72-254.pdf)
9. [Nicholas Metropolis, S. Ulam (1949). The Monte Carlo Method. Journal of the American Statistical Association.](https://doi.org/10.1080/01621459.1949.10483310)
10. [Donald B. Rubin (1987). The Calculation of Posterior Distributions by Data Augmentation: Comment: A Noniterative Sampling/Importance Resampling Alternative to the Data Augmentation Algorithm for Creating a Few Imputations When Fractions of Missing Information Are Modest: The SIR Algorithm. Journal of the American Statistical Association.](https://doi.org/10.2307/2289460)
11. [Liqun Wang, Chel Hee Lee (2013). Discretization-based direct random sample generation. Computational Statistics & Data Analysis.](https://doi.org/10.1016/j.csda.2013.06.011)
12. [History of Random Variate Generation (Winter Simulation Conference 2017)](https://www.informs-sim.org/wsc17papers/includes/files/017.pdf)
13. [Direct Simulation Methods (Bayes class lecture notes, Purdue)](https://web.ics.purdue.edu/~jltobias/BayesClass/lecture_notes/direct_simulation_student.pdf)
14. [Generalized Direct Sampling for Hierarchical Bayesian Models](https://arxiv.org/html/1108.2245v3)
15. [Computational statistics, Simulation of probability distributions: Classical methods (Denoeux course notes)](https://www.hds.utc.fr/~tdenoeux/dokuwiki/_media/en/simulation.pdf)
16. [Discretization-based direct random sample generation (Computational Statistics & Data Analysis, 2014)](https://home.cc.umanitoba.ca/~wangl1/papers/walee14.pdf)
17. [Zeroth-Order Sampling Methods for Non-Log-Concave Distributions: Alleviating Metastability by Denoising Diffusion (NeurIPS 2024)](https://papers.nips.cc/paper_files/paper/2024/file/8337b176767d948275d0b6d17cf4221e-Paper-Conference.pdf)

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

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Statistical inference, estimation, sampling, and testing

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/direct-sampling-monte-carlo

English original: https://www.edgepedia.org/direct-sampling-monte-carlo
