Fortran 90 的随机数生成器是否可以用于蒙特卡洛积分? [英] Can Random Number Generator of Fortran 90 be trusted for Monte Carlo Integration?

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

问题描述

我已经编写了一个简短的蒙特卡罗积分算法来计算 Fortran 90 中的积分.我曾经将使用固有随机数生成器对某个参数求解积分获得的结果与随机数生成器方法 ran1 进行了比较Fortran90 第 2 卷的数值配方.

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.

运行相同的算法两次,一次调用内在的 random_seed(),然后总是调用 random_number(),一次调用数值食谱书中提供的 ran1() 方法,我得到的结果原则上相同的形状但内在的结果与 ran1 结果相比,它是一条连续曲线.在这两种情况下,我都会为参数值 q 调用带有随机参数的函数 10,000 次,添加它,然后继续下一个 q 值并调用函数 10,000 次等.

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:

如果我增加调用次数,两条曲线会收敛.但我想知道:为什么内在随机数生成器会产生这种平滑度?还是一般建议使用它还是有其他更建议的 RNG?我想连续的结果是内在数生成器的较少"随机性的结果.

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.)

推荐答案

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

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 实际上并没有被数值数学界的一些人所接受http://www.uwyo.edu/buerkle/misc/wnotnr.html

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

本站不是软件推荐,而是这篇文章(roygvib在评论中给出的链接):https://arxiv.org/abs/1005.4117 是一篇很好的评论,其中包含了坏和好的算法示例、如何测试它们的方法、如何生成任意数字分布以及 C 中两个示例库的调用示例(其中之一它们也可以从 Fortran 中调用).

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).

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

Personally I use this https://bitbucket.org/LadaF/elmm/src/master/src/rng_par_zig.f90 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天全站免登陆