PARFOR循环:随机样品取决于
2次观看(最近30天)
显示较旧的评论
在一句话中,我的问题是
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循环](http://www.tatmou.com/matlabcentral/answers/uploaded_files/817609/parfor%20loop%20with%20random%20seeds%20generated%20outside%20parfor%20loop.jpeg)
(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](http://www.tatmou.com/matlabcentral/answers/uploaded_files/817614/parfor%20loop%20with%20solution%202.jpeg)
当我使用时
对于循环,
获得以下图
![用于循环](http://www.tatmou.com/matlabcentral/answers/uploaded_files/817619/Using%20for%20loop.jpeg)
显然,该系列通过使用
为了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获得的,蓝线是通过循环获得的。
![](http://www.tatmou.com/matlabcentral/answers/uploaded_files/821625/image.jpeg)