查看“︁蒙地卡羅積分”︁的源代码
←
蒙地卡羅積分
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{noteTA |1=zh-hans:蒙特卡罗; zh-hant:蒙地卡羅; |G1=IT |G2=Math }} [[File:MonteCarloIntegrationCircle.svg|thumb|蒙特卡罗积分示意图。在该示例中,''D''是和正方形内切的圆,域E则是正方形。因为正方形的面积 (值是4) 很容易计算,所以圆的面积 (π*1.0<sup>2</sup>) 可以通过圆内的点 (40个红点) 与总点数 (50个点) 的比率(0.8) 来估计,得出圆面积的近似值 4*0.8 = 3.2 ≈ π。]] 在[[数学]]中,'''蒙特卡罗积分'''(Monte Carlo integration)是一种使用[[伪随机性|随机数]]进行[[數值積分|数值积分]]的技术。它是一种特殊的[[蒙地卡羅方法|蒙特卡罗方法]],可对[[积分|定积分]]进行数值计算。其他算法通常在规则网格上评估被积函数,而<ref>{{Harvnb|Press|Teukolsky|Vetterling|Flannery|2007}}</ref>蒙特卡洛随机选择被积函数评估的点。 <ref>{{Harvnb|Press|Teukolsky|Vetterling|Flannery|2007}}</ref>该方法对于高维积分特别有用。 <ref name="newman1999ch2">{{Harvnb|Newman|Barkema|1999}}</ref> 进行蒙特卡罗积分的方法有多种,例如[[連續型均勻分布|均匀采样]]、[[分层抽样|分层采样]]、[[重要性采样]]、[[粒子濾波器|顺序蒙特卡罗]](也称为粒子滤波器)和平均场粒子方法。 == 概述 == 在数值积分中,[[梯形公式|梯形法则]]等方法使用[[确定性算法|确定性方法]]。另一方面,蒙特卡罗积分采用非确定性方法:每种实现都提供不同的结果。在蒙特卡罗中,最终结果是带有各自误差线的正确值的近似值,并且正确值很可能在这些误差线内。 考虑函数<math display="block">I = \int_{\Omega}f(\overline{\mathbf{x}}) \, d\overline{\mathbf{x}}</math>其中 Ω 是<math>\mathbb{R}^m</math>的一个子集,它的体积是:<math display="block">V = \int_{\Omega}d\overline{\mathbf{x}}</math> 朴素的蒙特卡罗方法是在Ω上均匀采样点: <ref name="newman1999ch1">{{Harvnb|Newman|Barkema|1999}}</ref> 给定''N''个均匀样本,<math display="block">\overline{\mathbf{x}}_1, \cdots, \overline{\mathbf{x}}_N\in \Omega,</math>''I''可以被近似为:<math display="block"> I \approx Q_N \equiv V \frac{1}{N} \sum_{i=1}^N f(\overline{\mathbf{x}}_i) = V \langle f\rangle.</math> 这是因为[[大數法則|大数定律]]确保以下结论成立:<math display="block"> \lim_{N \to \infty} Q_N = I.</math> 我们使用''I''给出''Q<sub>N</sub>''的''I''估计, ''Q<sub>N</sub>''的误差线(error bars)可以使用[[估计量的偏差|方差的无偏估计]]通过[[方差|样本方差]]来估计。<math display="block"> \mathrm{Var}(f)\equiv\sigma_N^2 = \frac{1}{N-1} \sum_{i=1}^N \left (f(\overline{\mathbf{x}}_i) - \langle f \rangle \right )^2. </math>由此可得:<math display="block"> \mathrm{Var}(Q_N) = \frac{V^2}{N^2} \sum_{i=1}^N \mathrm{Var}(f) = V^2\frac{\mathrm{Var}(f)}{N} = V^2\frac{\sigma_N^2}{N}.</math>只要以下序列<math display="block"> \left \{ \sigma_1^2, \sigma_2^2, \sigma_3^2, \ldots \right \} </math>是有界的,该方差就会逐渐减小到零,即 1/''N'' 。 那么,''Q<sub>N</sub>''的误差估计就是:<math display="block">\delta Q_N\approx\sqrt{\mathrm{Var}(Q_N)}=V\frac{\sigma_N}{\sqrt{N}},</math> <!-- 檔案不存在 [[File:Relative_error_of_a_Monte_Carlo_integration_to_calculate_pi.svg|right|thumb|350x350px|相对误差作为样本数量的函数,显示缩放比例<math>\tfrac{1}{\sqrt{N}}</math>]] ,可從英文維基百科取得 --> 我们看到,''Q<sub>N</sub>''的误差是自身的<math>\tfrac{1}{\sqrt{N}}</math>,这是[[标准误差|平均值的标准误差]]乘以<math>V</math>。该结果不依赖于积分的维数,这是蒙特卡洛积分相对于大多数指数依赖维数的确定性方法所具有的优势。 值得注意的是,与确定性方法不同,误差的估计不是严格的误差界限;随机抽样可能无法揭示被积函数的所有重要特征,从而导致误差的低估。 虽然朴素蒙特卡罗适用于简单的示例,但对确定性算法的改进只能通过使用特定于问题的采样分布的算法来实现。通过适当的样本分布,可以利用以下事实:几乎所有高维被积函数都是非常局部化的,并且只有小子空间对积分有显着贡献。 <ref>{{Harvnb|MacKay|2003}}</ref>蒙特卡罗文献的很大一部分致力于开发改进误差估计的策略。特别是,分层采样(将区域划分为子域)和重要性采样(从非均匀分布中采样)是此类技术的两个示例。 === 例子 === 使用蒙特卡洛方法最典型的例子是估计π。 我们考虑以下函数:<math display="block">H\left(x,y\right)=\begin{cases} 1 & \text{if }x^{2}+y^{2}\leq1\\ 0 & \text{else} \end{cases}</math>即正方形集合Ω=[−1,1]×[−1,1]的体积是''V'' = 4。 因此,使用蒙特卡罗积分计算π值的粗略方法是在Ω上选取''N''个随机数并计算:<math display="block">Q_N = 4 \frac{1}{N}\sum_{i=1}^N H(x_{i},y_{i})</math>右图中,相对误差<math>\tfrac{Q_N-\pi}{\pi}</math>被认为是一个关于''N''的函数,由此确认<math>\tfrac{1}{\sqrt{N}}</math> 。 === C 示例 === 请记住,以下的程序需要真正的随机数生成器。<syntaxhighlight lang="c" line="1"> int i, throws = 99999, insideCircle = 0; double randX, randY, pi; srand(time(NULL)); for (i = 0; i < throws; ++i) { randX = rand() / (double) RAND_MAX; randY = rand() / (double) RAND_MAX; if (randX * randX + randY * randY < 1) ++insideCircle; } pi = 4.0 * insideCircle / throws; </syntaxhighlight> === Python示例 === <syntaxhighlight lang="python" line="1"> from numpy import random import numpy as np throws = 2000 inside_circle = 0 i = 0 radius = 1 while i < throws: # Choose random X and Y centered around 0,0 x = random.uniform(-radius, radius) y = random.uniform(-radius, radius) # If the point is inside circle, increase variable if x**2 + y**2 <= radius**2: inside_circle += 1 i += 1 # Calculate area and print; should be closer to Pi with increasing number of throws area = (((2 * radius) ** 2) * inside_circle) / throws print(area) </syntaxhighlight> == 参见 == * [[拟蒙特卡罗方法]] * 蒙特卡洛辅助场 * 统计物理中的蒙特卡罗方法 * [[蒙地卡羅方法|蒙特卡罗方法]] * 减小方差(英语:Variance reduction) == 本章注记 == {{Reflist|30em}} == 参考文献 == {{refbegin}} * {{cite journal |last=Caflisch |first=R. E. |author-link=Russel E. Caflisch |year=1998 |title=Monte Carlo and quasi-Monte Carlo methods |journal=[[Acta Numerica]] |volume=7 |pages=1–49 |bibcode=1998AcNum...7....1C |doi=10.1017/S0962492900002804 |s2cid=5708790}} * {{cite arXiv |eprint=hep-ph/0006269 |first=S. |last=Weinzierl |title=Introduction to Monte Carlo methods |year=2000}} * {{cite journal |last1=Press |first1=W. H. |last2=Farrar |first2=G. R. |year=1990 |title=Recursive Stratified Sampling for Multidimensional Monte Carlo Integration |journal=Computers in Physics |volume=4 |issue=2 |pages=190 |bibcode=1990ComPh...4..190P |doi=10.1063/1.4822899 |doi-access=free}} * {{cite journal |last=Lepage |first=G. P. |year=1978 |title=A New Algorithm for Adaptive Multidimensional Integration |journal=[[Journal of Computational Physics]] |volume=27 |issue=2 |pages=192–203 |bibcode=1978JCoPh..27..192L |doi=10.1016/0021-9991(78)90004-9}} * {{cite journal |last=Lepage |first=G. P. |year=1980 |title=VEGAS: An Adaptive Multi-dimensional Integration Program |journal=Cornell Preprint CLNS 80-447}} * {{cite book|first1=J. M.|last1=Hammersley|first2=D. C.|last2=Handscomb|year=1964|title=Monte Carlo Methods|url=https://archive.org/details/montecarlomethod0000hamm_k1u9|publisher=Methuen|isbn=978-0-416-52340-9}} * {{cite book|last1=Kroese|first1=D. P.|author-link1=Dirk Kroese|last2=Taimre|first2=T.|last3=Botev|first3=Z. I.|title=Handbook of Monte Carlo Methods|year=2011|publisher=John Wiley & Sons}} * {{Cite book|last1=Press|first1=WH|last2=Teukolsky|first2=SA|last3=Vetterling|first3=WT|last4=Flannery|first4=BP|year=2007|title=Numerical Recipes: The Art of Scientific Computing|edition=3rd|publisher=Cambridge University Press|location=New York|isbn=978-0-521-88068-8}} * {{Cite book|url=http://www.inference.phy.cam.ac.uk/mackay/itila/book.html|title=Information Theory, Inference and Learning Algorithms|last=MacKay|first=David|publisher=Cambridge University Press|year=2003|isbn=978-0-521-64298-9|chapter=chapter 4.4 Typicality & chapter 29.1|mr=2012999|author-link=David MacKay (scientist)|chapter-url=http://www.inference.org.uk/itprnn/book.pdf|access-date=2024-03-15|archive-date=2016-02-17|archive-url=https://web.archive.org/web/20160217105359/http://www.inference.phy.cam.ac.uk/mackay/itila/book.html|dead-url=no}} * {{Cite book|last1=Newman|first1=MEJ|last2=Barkema|first2=GT|year=1999|title=Monte Carlo Methods in Statistical Physics|url=https://archive.org/details/montecarlomethod0000newm|publisher=Clarendon Press}} * {{Cite book|last1=Robert|first1=CP|last2=Casella|first2=G|year=2004|title=Monte Carlo Statistical Methods|url=https://archive.org/details/montecarlostatis0000robe|publisher=Springer|edition=2nd|isbn=978-1-4419-1939-7}} {{refend}} == 外部链接 == * [https://web.archive.org/web/20140202110318/http://www.cafemath.fr/mathblog/article.php?page=MonteCarlo.php Café math : Monte Carlo Integration] : A blog article describing Monte Carlo integration (principle, hypothesis, confidence interval) * [http://www.boost.org/doc/libs/release/libs/math/doc/html/math_toolkit/naive_monte_carlo.html Boost.Math : Naive Monte Carlo integration: Documentation for the C++ naive Monte-Carlo routines] * [https://sites.google.com/view/chremos-group/applets/monte-carlo: Monte Carlo applet applied in statistical physics problems]{{Dead link}} [[Category:带有Python代码示例的条目]] [[Category:带有C代码示例的条目]] [[Category:带有代码示例的条目]] [[Category:蒙地卡羅方法]]
该页面使用的模板:
Template:Cite arXiv
(
查看源代码
)
Template:Cite book
(
查看源代码
)
Template:Cite journal
(
查看源代码
)
Template:Dead link
(
查看源代码
)
Template:Harvnb
(
查看源代码
)
Template:NoteTA
(
查看源代码
)
Template:Refbegin
(
查看源代码
)
Template:Refend
(
查看源代码
)
Template:Reflist
(
查看源代码
)
返回
蒙地卡羅積分
。
导航菜单
个人工具
登录
命名空间
页面
讨论
不转换
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
工具
链入页面
相关更改
页面信息