PARFOR循环:随机样品取决于

2次观看(最近30天)
Abhinav Gupta
Abhinav Gupta 2021年11月29日
Edited: Abhinav Guptaon 2 Dec 2021
在一句话中,我的问题是 how do I carry out MC simulations in parallel using parfor loop without introducing statistical dependecies?
这是细节。我正在使用parfor循环进行蒙特卡洛模拟。基本上,我从多元正常随机变量中绘制一些样品,并使用这些样品做某事
parfori = 1:n
% samps = draw n samples using mvnrnd
%x(i)= samp的复杂功能
结尾
The thing is that I want my N samples to be independent of each other. Samples seems to be statistically independent when I use ' 为了loop ' instead of ' parfor循环', 但是当我使用PARFOR循环时,样品似乎在统计上取决于。
I have tried to address this problem by two methods
(1)在PARFOR循环之前生成随机种子,然后在每个环中更改随机数发生器的状态,如下所示:
rng('default');
rng_seeds = randi(100000,n,1);
parfori = 1:n
rng(rng_seeds(i),'twister'
% samps = draw n samples using mvnrnd
%x(i)= samp的复杂功能
结尾
这在某种程度上解决了问题,但并非完全解决问题,因为在 X 系列。我附上了 X below for n = 100.
PARFOR循环,随机种子在外部生成parfor循环
(2)从PAFOR循环和计算中生成n个随机样品 X 为了 样本中的循环 如下
为了i = 1:n
% samps{i} = draw n samples using mvnrnd
结尾
parfori = 1:n
%x(i)= samps {i}的复杂功能
结尾
如下所示,这也具有统计依赖性。
parforloop with solution 2
当我使用时 对于循环, 获得以下图
用于循环
显然,该系列通过使用 为了loop 与使用的系列相同 parfor循环。
So, my question is how do I carry out MC simulations in parallel using parfor loop without introducing statistical dependecies?
编辑:
I have also tried the 'substream' solution now it again does not help. For and parfor loop are still giving different results. I tried the following code with for and parfor loop and the results are very different:
stream = randstream('MRG32K3A');
parfori = 1:n
set(流,“子流”,i);
% samps = draw n samples using mvnrnd
%x(i)= samp的复杂功能
结尾
以下是 n = 1000.红线是通过parfor获得的,蓝线是通过循环获得的。

答案(1)

雷蒙德·诺里斯(Raymond Norris)
2条评论
Abhinav Gupta
Abhinav Gupta 2021年11月30日
我从MATLAB文档中收集了关注
(1)使用RandStream创建一个随机数流
(2)使用PARFOR循环索引为子流分配一个值。
代码应如下:
myStream = randStream('Threefry');
parfori = 1:n
mystream.substream = i;
%samps =从mvnrnd绘制样品
%x(i)= samps {i}的复杂功能
结尾
您能确认这是否有意义吗?另外,我并不真正理解这背后的逻辑。如果您可以解释一下,那将是有帮助的。此外,为什么解决方案1在我的问题中发布1不起作用?

登录发表评论。

下载188bet金宝搏


Release

R2021A

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!