rng seed and cvpartition

조회 수: 2 (최근 30일)
micholeodon
micholeodon 2020년 8월 14일
댓글: micholeodon 2020년 8월 15일
Dear Matlab Users,
Why cvpartition keeps choosing same test indices in folds from data, despite rng shuffle (thus different seed values assured) ?
When you run code below twice, you got same value of testInd. Why?
Thank you in advance for you help !
clear;
rng shuffle
parpool(parcluster('local'), 24)
tmp = rng;
seed = tmp.Seed;
nData = 89;
nFolds = 10;
selectedFold = 1;
spmd(3)
tmp = cvpartition(nData, 'KFold', nFold)
x = find(tmp.test(selectedFold)); % extract test indices of fold 1
end
for ii = 1:3
testInd(ii,:) = x{ii};
end
% clear context and
clear x tmp
delete(gcp('nocreate'))

답변 (1개)

Steven Lord
Steven Lord 2020년 8월 14일
You're calling rng shuffle on the client, not on the workers. See this documentation page.
  댓글 수: 1
micholeodon
micholeodon 2020년 8월 15일
Thank you. I can read that:
"By default, the random numbers generated on each worker in a parfor loop are different from each other and from the random numbers generated on the client."
and
"each worker produces a unique sequence of random numbers.".
I have checked that and it is endeed true.
So in the context of my problem, it seems that each time I open MATLAB and run the code same set of random streams is produced and distributed to the workers. How to overcome that i.e. make sure that each time I open matlab and run that code I would get different set of random streams and thus different results? The article you pointed is mostly how to make things reproducible, same.
In RandStream documentation there is Example 7 - maybe this approach is recommended to my problem?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Speed Up Statistical Computations에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by