# 约束采样（统计学）

约束采样是指从一个概率分布中抽取随机样本，同时将样本限制在指定的可行集内，例如由线性不等式定义的多面体。它不同于拒绝采样——后者提出无约束的点并丢弃违反约束者<sup>[1](https://doi.org/10.1287/opre.32.6.1296)</sup>，也不同于塞克特曼（Szechtman）与格林（Glynn）意义上的约束蒙特卡洛——那里的约束作用于相关量的期望而非分布的支撑集。<sup>[2](https://informs-sim.org/wsc01papers/051.PDF)</sup> 主要工具是始终停留在可行集内部的马尔可夫链蒙特卡洛（MCMC）游走，它们被用于仿真、截断模型的贝叶斯推断，以及约束设计空间下的试验设计。<sup>[3](https://par.nsf.gov/servlets/purl/10427648)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义问题 | 从限制在可行集上的目标密度中采样，可行集通常是由 \( A \cdot x \le b \) 给出的凸多面体<sup>[4](https://cran.r-project.org/web/packages/hitandrun/hitandrun.pdf)</sup> |
| 典型算法 | 命中-运行：随机选取一个方向，沿集合内的弦均匀移动<sup>[5](https://faculty.washington.edu/harin/L1.pdf)</sup> |
| 混合保证 | 对于外接半径为 \( R \)、内切半径为 \( r \) 的凸体，命中-运行在 \( O^{*}(n^{2} \cdot R^{2}/r^{2}) \) 步内混合<sup>[5](https://faculty.washington.edu/harin/L1.pdf)</sup> |
| 混合要求 | 维数为 \( n \) 时的 \( O^{*}(n^{3}) \) 界，计的是在其初始化、几何与精度假设下达到近似平稳所需的链转移次数，而非所需输出抽样数——后者取决于目标精度与链的自相关<sup>[4](https://cran.r-project.org/web/packages/hitandrun/hitandrun.pdf)</sup> |
| 快速替代方案 | 反射HMC在 \( O(\kappa \cdot d^{2} \cdot \ell^{2} \log^{2}(\kappa/\varepsilon) \log(d\log(\kappa/\varepsilon)+d\log(\gamma/\varepsilon)) \log(1/\varepsilon)) \) 个热启动步内混合，在基准采样中比命中-运行最快约达 \( 10^{3} \) 倍<sup>[6](https://ar5iv.labs.arxiv.org/html/2102.13068)</sup> |
| 实用软件 | hitandrun R包、COBRA工具箱与HOPS库实现了这些采样器<sup>[4](https://cran.r-project.org/web/packages/hitandrun/hitandrun.pdf)</sup><sup> • </sup><sup>[6](https://ar5iv.labs.arxiv.org/html/2102.13068)</sup><sup> • </sup><sup>[7](https://doi.org/10.1093/bioinformatics/btaa872)</sup> |

## 工作原理

目标是一个在可行集 \( S \) 上有支撑的密度 \( p(x) \)，已知至多差一个归一化常数，\( S \) 最常见的是凸多面体 \( \{x: A \cdot x \le b\} \) 或凸体。约束采样器构造一条马尔可夫链，使其平稳分布为限制在 \( S \) 上的 \( p \)。命中-运行通过全局移动实现这一点：从当前点 \( v \) 出发，在所有方向上均匀地选取一条过 \( v \) 的随机直线，然后对于均匀目标，从该直线落在 \( K \) 内的线段上均匀选取下一点；而对于一般目标 \( p \)，则需要沿弦从其条件密度中采样，或施加适当的Metropolis校正。<sup>[5](https://faculty.washington.edu/harin/L1.pdf)</sup> 由于每一步都能跨越整个支撑集，命中-运行是一种全局可达的采样器，与小步随机游走形成对照。<sup>[8](https://dl.acm.org/doi/10.1145/256562.256619)</sup>

约束HMC方法以三种方式之一处理边界：拒绝型，丢弃违反约束的建议点；反射型，将边界视为弹性能量壁；重构型，变换区域，例如映射到超球面上。<sup>[3](https://par.nsf.gov/servlets/purl/10427648)</sup> 硬约束通过壁、反射或拉格朗日乘子精确执行；基于障碍的方法则在势函数中加入障碍项，并要求反射机制将到达约束边界的样本重新定向。<sup>[9](https://www.mdpi.com/1099-4300/25/8/1234)</sup>

洛瓦兹（Lovász）证明了凸体 \( K \) 上的命中-运行在 \( O^{*}(n^{2} \cdot R^{2}/r^{2}) \) 步内混合，其中 \( R \) 与 \( r \) 分别为外接球与内切球的半径，预处理后得到 \( O^{*}(n^{3}) \)；通过一个圆柱体例子可知，对 \( R \)、\( r \) 与 \( n \) 的依赖是最优可能的。<sup>[5](https://faculty.washington.edu/harin/L1.pdf)</sup> 命中-运行是从凸体近似均匀采样的一种多项式时间马尔可夫链，可从任意起点工作，但如今已有更快的方法，包括以约 \( O(m \cdot d \times m \cdot d^{\omega-1}) \) 次算术运算运行的Dikin型游走，以及带Lewis权重混合障碍的黎曼HMC。<sup>[10](https://www.sciencedirect.com/science/article/abs/pii/S0167637711001271)</sup>

## 实施方法

多面体上均匀或对数凹采样的典型流程如下。首先，将可行集表示为 \( A \cdot x \le b \)，并消去所有等式约束；hitandrun R包使用Moore-Penrose伪逆完成这一步。<sup>[4](https://cran.r-project.org/web/packages/hitandrun/hitandrun.pdf)</sup> 其次，找到一个内点作为起点。第三，运行所选链：命中-运行在单位超球面上采样一个方向，然后在弦上采样一个点<sup>[10](https://www.sciencedirect.com/science/article/abs/pii/S0167637711001271)</sup>；坐标方向命中-运行将方向限制为 \( 2n \) 个坐标向量。<sup>[11](https://websites.umich.edu/~rlsmith/NU6.tex%20typeset.pdf)</sup> 第四，丢弃预热期并对相关输出进行抽稀；对于维数为 \( n \) 的均匀采样，建议使用 \( O^{*}(n^{3}) \) 个样本。<sup>[4](https://cran.r-project.org/web/packages/hitandrun/hitandrun.pdf)</sup> 对于截断高斯上的HMC，当轨迹不撞壁时，行进时间参数 \( T = \pi/2 \) 是安全的选择，而主要运行开销在于计算撞壁时间，其随约束数 \( m \) 线性增长。<sup>[12](https://arxiv.org/pdf/1208.4118)</sup>

## 起源

密歇根大学的罗伯特·L·史密斯（Robert L. Smith）于1984年在《运筹学》上发表了命中-运行算法，用于在任意有界可测区域内生成渐近均匀分布的点，并报告称对于高维区域，此类马尔可夫方法可能优于传统的拒绝技术。<sup>[1](https://doi.org/10.1287/opre.32.6.1296)</sup> 超球方向版本的迭代点独立于起点地趋近均匀极限分布。<sup>[11](https://websites.umich.edu/~rlsmith/NU6.tex%20typeset.pdf)</sup> 特尔根（Telgen）引入了坐标方向变体。<sup>[11](https://websites.umich.edu/~rlsmith/NU6.tex%20typeset.pdf)</sup> 贝利斯尔（Bélisle）、罗梅因（Romeijn）与罗伯特·L·史密斯（Robert L. Smith）于1993年证明了广义命中-运行类的渐近收敛性<sup>[13](https://doi.org/10.1287/moor.18.2.255)</sup>，考夫曼（Kaufman）与罗伯特·L·史密斯（Robert L. Smith）于1998年引入了界最优与自适应方向选择。<sup>[14](https://doi.org/10.1287/opre.46.1.84)</sup> 用于对有界多面体边界采样的摇动-烘焙算法由布恩德（Boender）及其同事于1991年发表在《运筹学》上。<sup>[15](https://doi.org/10.1287/opre.39.6.945)</sup> 在理论方面，戴尔（Dyer）、弗里兹（Frieze）与坎南（Kannan）给出了首个基于格游走的凸体多项式时间采样程序<sup>[5](https://faculty.washington.edu/harin/L1.pdf)</sup>，洛瓦兹（Lovász）与西蒙诺维茨（Simonovits）于1993年分析了凸体内的随机游走。<sup>[16](https://doi.org/10.1002/rsa.3240040402)</sup>

## 变体

除超球方向与坐标方向命中-运行之外，模式命中-运行使用球与盒双游走模式在多面体上高效构造双向游走。<sup>[10](https://www.sciencedirect.com/science/article/abs/pii/S0167637711001271)</sup> 在欧几里得空间中，随机选择坐标的吉布斯采样器与坐标方向命中-运行一致，因为每一步都从所选坐标在给定其余坐标下的条件分布中重新采样该坐标。<sup>[11](https://websites.umich.edu/~rlsmith/NU6.tex%20typeset.pdf)</sup> 洛瓦兹（Lovász）与西蒙诺维茨（Simonovits）的球行走被改进为Dikin行走，后者从利用局部几何的Dikin椭圆中提出建议点。<sup>[17](https://proceedings.neurips.cc/paper_files/paper/2024/file/80364062ec10e7bd976fc2d7a22730c3-Paper-Conference.pdf)</sup> 约束HMC变体包括用于截断高斯的带弹性壁精确HMC<sup>[12](https://arxiv.org/pdf/1208.4118)</sup>、用于等式约束 \( c(\theta)=0 \) 的拉格朗日乘子HMC<sup>[3](https://par.nsf.gov/servlets/purl/10427648)</sup>、球面HMC<sup>[3](https://par.nsf.gov/servlets/purl/10427648)</sup>，以及带蛙跳动力学与边界反射的反射HMC。<sup>[6](https://ar5iv.labs.arxiv.org/html/2102.13068)</sup>

近期工作集中于更快、分析更完善的约束采样器。反射HMC给出了首个利用反射的HMC方法的混合分析，在基准测试中比命中-运行快达 \( 10^{3} \) 倍。<sup>[6](https://ar5iv.labs.arxiv.org/html/2102.13068)</sup> 误差鲁棒Dikin行走允许对障碍的黑塞矩阵进行近似而非精确计算，在多面体上以 \( \widetilde{O}(d^{2} + d \cdot L^{2} \cdot R^{2}) \) 步混合。<sup>[17](https://proceedings.neurips.cc/paper_files/paper/2024/file/80364062ec10e7bd976fc2d7a22730c3-Paper-Conference.pdf)</sup> Metropolis校正镜像Langevin消除了镜像Langevin算法的偏差<sup>[18](https://doi.org/10.48550/arxiv.2312.08823)</sup>，而Metropolis校正预条件Langevin算法在障碍满足自和谐条件时实现了严格更好的维度依赖。<sup>[19](https://proceedings.mlr.press/v272/srinivasan25a.html)</sup>

## 应用

三类标准问题驱动着相关文献：截断多元正态分布、贝叶斯正则化回归（如贝叶斯Lasso）以及非参数密度估计。<sup>[3](https://par.nsf.gov/servlets/purl/10427648)</sup> 精确HMC可直接推广到贝叶斯Lasso模型。<sup>[12](https://arxiv.org/pdf/1208.4118)</sup> 在另一种意义上，带矩约束的约束蒙特卡洛在等式约束下渐近等价于控制变量，已被应用于金融校准问题。<sup>[2](https://informs-sim.org/wsc01papers/051.PDF)</sup> 诸如HOPS之类的多面体采样器是为凸约束模型而构建的。<sup>[7](https://doi.org/10.1093/bioinformatics/btaa872)</sup>

## 局限与替代方案

在可行集上直接进行接受-拒绝的代价随维数指数增长，而将区域包围在超矩形中并在每条弦上做一维拒绝，只会给命中-运行的复杂度增加一个线性缩放因子。<sup>[20](https://websites.umich.edu/~rlsmith/HandRBox.pdf)</sup> 接受-拒绝方法确实产生真正独立同分布的样本且无近似，但设计包络代价高昂，效率随维数下降，而MCMC则从仅已知至多差一个归一化常数的目标中产生相关输出。<sup>[21](https://stats.stackexchange.com/questions/185631/what-is-the-difference-between-metropolis-hastings-gibbs-importance-and-rejec/185643)</sup> 拒绝型约束采样器在复杂约束与高维下可能遭遇过多拒绝和糟糕混合。<sup>[9](https://www.mdpi.com/1099-4300/25/8/1234)</sup> 投影与镜像Langevin方法会累积边界偏差：在限制于 \( [1,3] \) 的截断高斯上，它们在边界附近生成的样本比预期多1.5至3倍，从而低估均值。<sup>[22](https://proceedings.neurips.cc/paper_files/paper/2024/file/33c674cb3ce9dae35021930d8d63308f-Paper-Conference.pdf)</sup> 当约束使坐标间呈现高相关性时，吉布斯采样器探索缓慢<sup>[12](https://arxiv.org/pdf/1208.4118)</sup>，且多数约束MCMC方法缺乏严格的收敛速率分析。<sup>[9](https://www.mdpi.com/1099-4300/25/8/1234)</sup>

在采样内部，选择是一种权衡。拒绝法给出独立同分布样本但随维数恶化；命中-运行稳健且全局可达，但需要 \( O^{*}(n^{3}) \) 个相关抽样<sup>[4](https://cran.r-project.org/web/packages/hitandrun/hitandrun.pdf)</sup>；坐标命中-运行每步成本更低，但最坏情况电导更差<sup>[23](https://link.springer.com/article/10.1007/s00454-023-00497-x)</sup>；基于HMC的方法在目标光滑且对数凹时混合最快，但需要反射、障碍或重构来尊重边界。<sup>[3](https://par.nsf.gov/servlets/purl/10427648)</sup>

## References

1. [Robert L. Smith (1984). Efficient Monte Carlo Procedures for Generating Points Uniformly Distributed over Bounded Regions. Operations Research.](https://doi.org/10.1287/opre.32.6.1296)
2. [Constrained Monte Carlo and the Method of Control Variates (Szechtman & Glynn, 2001 Winter Simulation Conference)](https://informs-sim.org/wsc01papers/051.PDF)
3. [Sampling constrained continuous probability distributions: A review (WIREs Computational Statistics)](https://par.nsf.gov/servlets/purl/10427648)
4. [hitandrun R package: 'Hit and Run' and 'Shake and Bake' for Sampling Uniformly from Convex Shapes](https://cran.r-project.org/web/packages/hitandrun/hitandrun.pdf)
5. [Hit-and-run mixes fast (Lovász, 1999, Mathematical Programming)](https://faculty.washington.edu/harin/L1.pdf)
6. [Truncated Log-concave Sampling with Reflective Hamiltonian Monte Carlo (ReHMC)](https://ar5iv.labs.arxiv.org/html/2102.13068)
7. [Johann F Jadebeck and colleagues (2020). HOPS: high-performance library for (non-)uniform sampling of convex-constrained models. Bioinformatics.](https://doi.org/10.1093/bioinformatics/btaa872)
8. [The hit-and-run sampler: a globally reaching Markov chain sampler for generating arbitrary multivariate distributions (Smith, 1996 WSC)](https://dl.acm.org/doi/10.1145/256562.256619)
9. [Convergence Rates for the Constrained Sampling via Langevin Monte Carlo (Entropy 25(8), 1234, 2023)](https://www.mdpi.com/1099-4300/25/8/1234)
10. [Pattern Hit-and-Run for sampling efficiently on polytopes](https://www.sciencedirect.com/science/article/abs/pii/S0167637711001271)
11. [Direction Choice for Accelerated Convergence in Hit-and-Run Sampling (Kaufman & Smith, Operations Research)](https://websites.umich.edu/~rlsmith/NU6.tex%20typeset.pdf)
12. [Hamiltonian Monte Carlo for Truncated Multivariate Gaussian Distributions (Pakman & Paninski)](https://arxiv.org/pdf/1208.4118)
13. [Claude J. P. Bélisle, H. Edwin Romeijn, Robert L. Smith (1993). Hit-and-Run Algorithms for Generating Multivariate Distributions. Mathematics of Operations Research.](https://doi.org/10.1287/moor.18.2.255)
14. [David E. Kaufman, Robert L. Smith (1998). Direction Choice for Accelerated Convergence in Hit-and-Run Sampling. Operations Research.](https://doi.org/10.1287/opre.46.1.84)
15. [C. G. E. Boender and colleagues (1991). Shake-and-Bake Algorithms for Generating Uniform Points on the Boundary of Bounded Polyhedra. Operations Research.](https://doi.org/10.1287/opre.39.6.945)
16. [L. Lovász, M. Simonovits (1993). Random walks in a convex body and an improved volume algorithm. Random Structures and Algorithms.](https://doi.org/10.1002/rsa.3240040402)
17. [Log-concave Sampling from a Convex Body with a Barrier: a Robust and Unified Dikin Walk (NeurIPS 2024)](https://proceedings.neurips.cc/paper_files/paper/2024/file/80364062ec10e7bd976fc2d7a22730c3-Paper-Conference.pdf)
18. [Srinivasan, Vishwak, Wibisono, Andre, Wilson, Ashia (2023). Fast sampling from constrained spaces using the Metropolis-adjusted Mirror Langevin algorithm. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2312.08823)
19. [High-accuracy sampling from constrained spaces with the Metropolis-adjusted Preconditioned Langevin Algorithm (PMLR v272)](https://proceedings.mlr.press/v272/srinivasan25a.html)
20. [An Analysis of a Variation of Hit-and-Run for Uniform Sampling from a Convex Body (hit-and-run on a box)](https://websites.umich.edu/~rlsmith/HandRBox.pdf)
21. [What is the difference between Metropolis-Hastings, Gibbs, Importance, and Rejection sampling? (Cross Validated)](https://stats.stackexchange.com/questions/185631/what-is-the-difference-between-metropolis-hastings-gibbs-importance-and-rejec/185643)
22. [Constrained Sampling with Primal-Dual Langevin Monte Carlo (NeurIPS 2024)](https://proceedings.neurips.cc/paper_files/paper/2024/file/33c674cb3ce9dae35021930d8d63308f-Paper-Conference.pdf)
23. [Convergence of Gibbs Sampling: Coordinate Hit-and-Run Mixes Fast (Discrete & Computational Geometry, 2023)](https://link.springer.com/article/10.1007/s00454-023-00497-x)

---
*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/constrained-sampling-statistics

English original: https://www.edgepedia.org/constrained-sampling-statistics
