Fortran 90的随机数生成器可以用于蒙特卡罗集成吗? [英] Can Random Number Generator of Fortran 90 be trusted for Monte Carlo Integration?

查看:326
本文介绍了Fortran 90的随机数生成器可以用于蒙特卡罗集成吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简短的蒙特卡洛积分算法来计算Fortran 90中的积分。我曾经用一个随机数发生器的方法,用一个内部的随机数发生器, Fortran90第2卷的数值配方。

运行相同的算法两次,一旦调用内在的random_seed(),则总是调用random_number()并调用ran1()方法在数值食谱书中提供,我得到的主要结果是相同的形状,但其内在结果是与ran1结果相反的连续曲线。在这两种情况下,我都使用随机参数10,000次调用函数来获取参数值q,然后添加它,然后继续执行下一个q值并调用函数10000次等。



结果的比较图可以在这里找到:



如果我增加两条曲线收敛的呼叫数量。但我想知道:为什么内在的随机数发生器产生这种光滑?一般还是建议使用它还是还有其他建议的RNG?我认为连续的结果是内在数字生成器的较少随机性的结果。



(我遗漏了源代码,因为我不认为它存在如果有人关心,我可以在以后交给他。)

解决方案

标准Fortran中的伪随机生成器的质量。如果您关心密码学或科学对随机数(蒙特卡罗)敏感的某些特定质量的实施,您应该使用一些您可以控制的库。

您可以研究你的编译器的手册以找出关于随机数生成器的内容,但是每个编译器都可以实现一个完全不同的算法来生成随机数。

数字食谱实际上,在数学数学社区中一些人并未很好地接受它们 http://www.uwyo .edu / buerkle / misc / wnotnr.html



本网站不适用于软件推荐,但本文(由roygvib在评论中给出的链接): https://arxiv.org/abs/1005.4117 是一个很好的评论,其中包含坏的和好的算法的例子,如何测试它们的方法,如何生成任意数量的分布以及C中两个示例库的调用示例(其中一个可以从Fortran中调用)。



我个人使用 https://bitbucket.org/LadaF/elmm/src/e732cb9bee3352877d09ae7f6b6722157a819f2c/src/rng_par_zig .f90?at = master 并行PRNG,但我没有测试质量,我个人只是需要速度。但这不是一个软件推荐网站。


I have written a short monte carlo integration algorithm to calculate an integral in Fortran 90. I once compared the result obtained by solving the integral with respect to some parameter using the intrinsic random number generator with the random number generator method ran1 presented in Numerical Recipes for Fortran90 Volume 2.

Running the same algorithm twice, once calling the intrinsic random_seed(), then always call random_number() and once calling the ran1() method provided in the Numerical Recipe book I obtain as result in principal the same shape but the intrinsic result is a continuous curve in contrast to the ran1 result. In both cases I call the function with random parameters 10,000 times for a parameter value q, add it and then go on to the next q value and call the function 10,000 times etc.

A comparative image of the result can be found here:

If I increase the number of calls both curves converge. But I was wondering: why does the intrinsic random number generator generate this smoothness? Is it still generally advised to use it or are there are other more advised RNG? I suppose the continuous result is a result of the "less" randomness of the intrinsic number generator.

(I left out the source code as I don't think that there is a lot of input from it. If somebody cares I can hand it in later.)

解决方案

There are NO guarantees about the quality of the pseudo random generator in standard Fortran. If you care about some particular quality of implementation for cryptography or science sensitive to random numbers (Monte-Carlo), you should use some library which you have control about.

You can study the manual of your compiler to find out what it says about the random number generator, but every compiler can implement a completely different algorithm to generate random numbers.

Numerical Recipes is actually not well received by some people in the numerical mathematics community http://www.uwyo.edu/buerkle/misc/wnotnr.html

This site is not for software recommendation, but this article (link given by roygvib in a comment): https://arxiv.org/abs/1005.4117 is a good review with examples of bad and good algorithms, methods how to test them, how to generate arbitrary number distributions and examples of calls of two example libraries in C (one of them can be called from Fortran as well).

Personally I use this https://bitbucket.org/LadaF/elmm/src/e732cb9bee3352877d09ae7f6b6722157a819f2c/src/rng_par_zig.f90?at=master parallel PRNG, but I didn't test the quality, I personally just need speed. But this is not a software recommendation site.

这篇关于Fortran 90的随机数生成器可以用于蒙特卡罗集成吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆