rng seed and cvpartition

2 vues (au cours des 30 derniers jours)
micholeodon
micholeodon le 14 Août 2020
Commenté : micholeodon le 15 Août 2020
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'))

Réponses (1)

Steven Lord
Steven Lord le 14 Août 2020
You're calling rng shuffle on the client, not on the workers. See this documentation page.
  1 commentaire
micholeodon
micholeodon le 15 Août 2020
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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Speed Up Statistical Computations dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by