matlab:不同的实例以相同的随机种子开始 [英] matlab: different instances start with the same random seed

查看:94
本文介绍了matlab:不同的实例以相同的随机种子开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MATLAB并尝试使用计算机集群执行具有固有随机性的某些计算的100次重复.这些重复中的每一个都应包含相同的代码,但具有不同的随机种子.看来

  rng('shuffle') 

文档建议如果所有作业在同一时间(在不同的机器上)同时开始运行,则a>可能无法实现这一目标,因为所使用的种子是一个似乎是随时间初始化的整数(它是单调递增的,看起来像是百分之一秒的精度./p>

精度似乎是合理的,但是冲突"是指如果同时运行100-1000个实例,仍然很有可能,从而破坏了结果统计解释的独立性.

任何避免此类冲突的方式都无需手动为每个实例提供实例ID".用作种子吗?

无论您选择哪种种子,它都只能采用32位值,即使它将初始化具有较大状态的生成器(例如Mersenne)Twister("twister",19937位).如" C ++所述,32位种子存在某些问题.播种惊喜"由奥尼尔(M. O'Neill)撰写.据推测,基于时间的种子同样是32​​位长.短种子意味着只能生成有限数量的伪随机序列.

看来 rng 不支持超过32位的种子.另一方面,最新版本的MATLAB支持 mrg32k3a ,然后按以下方式创建随机数流(另请参见):

  [stream1,stream2] = RandStream.create('mrg32k3a','NumStreams',2) 

Using MATLAB and trying to use a computer cluster to perform 100 repetitions of certain calculation with inherent stochastic nature. Each of those repetitions should include the same code, but with different random seed. It seems that

rng('shuffle')

recommended by documentation may not achieve this if all jobs start running at the same time (on different machines) as the seed used is an integer which seems to be initialized from time (it is monotonously increasing, seems like precision of 100th of a second.

The precision seems reasonable, but "collisions" are still very likely if running 100-1000 instances at the same time, thus corrupting the results statistical interpretation as independent.

Any way to avoid such collisions without manually giving each instance an "instance id" used as seed?

解决方案

Whatever you choose for the seed, it can only take on a 32-bit value, even if it will initialize a generator with a bigger state, such as Mersenne Twister ('twister', 19937 bits). There are certain issues with 32-bit seeds, as discussed in "C++ Seeding Surprises" by M. O'Neill. Presumably, the time-based seeds are likewise 32 bits long. A short seed means that only a limited number of pseudorandom sequences can be generated.

It appears that rng doesn't support seeds longer than 32 bits. On the other hand, recent versions of MATLAB support random number streams, which are designed, among other things, if you "want separate sources of randomness in a simulation". For your purposes, choose a generator that supports multiple streams, such as mrg32k3a, and create random number streams as follows (see also "Multiple Streams"):

[stream1, stream2]=RandStream.create('mrg32k3a','NumStreams',2)

这篇关于matlab:不同的实例以相同的随机种子开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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