フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

outputs from randg not repeatable with the same random seed

1 回表示 (過去 30 日間)
Etsuko
Etsuko 2016 年 4 月 25 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi, I have a lengthy simulation program composed of many m-files (in total about 1000 lines). It uses several different random number generators (rand, randn, poissrnd, gamrnd, etc) and use these very numerous times. I set a random seed using rng at the very beginning of the main program that calls other m-files. I just noticed that outcomes from the program were not repeatable even though I use the same seed. I examined the code carefully and pinpointed that the matlab function randg is causing this problem. I placed rand(1) just before and after randg and sometimes (not always) rand(1) placed after randg gives a different number. Strangly, the different numbers are not any number; it is from a small set of numbers. Although I ran my code many times to check this issue, so far I have seen only 3-4 different numbers generated from the rand(1) placed after randg. Has anyone encountered this type of problems with randg before? What would be the reason for this? Would it be possible there may be some numerical errors in randg function? Is there anyway this problem can be resolved? Thank you.

回答 (1 件)

Steven Lord
Steven Lord 2016 年 4 月 25 日
I can't reproduce this behavior. Please post the following information:
  • Which release of MATLAB and Statistics and Machine Learning Toolbox (previously just called Statistics Toolbox) are you using?
  • What operating system are you using? Be as specific as you can; for instance, if you're using Windows say whether you're using Windows 7, Windows 8, Windows 10, etc.
  • What is the output of this command:
which -all randg
  • Show a SMALL section of code (no more than 10 lines) that demonstrates the problem.
  1 件のコメント
Etsuko
Etsuko 2016 年 4 月 25 日
編集済み: Walter Roberson 2016 年 4 月 25 日
Hi Steven,
I am using Matlab R2015a student version with the stat toolbox that came with it. The operating system is OS X Yosemite 10.10.5.
The output of the command:
/Applications/MATLAB_R2015a.app/toolbox/stats/stats/randg.mexmaci64 /Applications/MATLAB_R2015a.app/toolbox/stats/stats/randg.m % Shadowed
Small code to demonstrate: I tried it but so far I cannot reproduce it. I can reproduce it with the simulation program. I used this one and has been unsuccessful.
seedi = 984;
s = RandStream('mt19937ar','Seed',seedi);
RandStream.setGlobalStream(s);
for i = 1:2:1000000
test(i)=rand(1);
r = randg(400*WIJ',sizeOut);
test(i+1)=rand(1);
end
s = RandStream('mt19937ar','Seed',seedi);
RandStream.setGlobalStream(s);
for i = 1:2:1000000
test2(i)=rand(1);
r = randg(400*WIJ',sizeOut);
test2(i+1)=rand(1);
end
sum(test-test2)
One clarification: My description was a bit ambiguous. I stated "Although I ran my code many times to check this issue, so far I have seen only 3-4 different numbers generated from the rand(1) placed after randg." This is referring to randg and rand(1) combo placed EXACTLY at the same place in the iterating program (i.e., same time point). I do not mean that rand(1) placed right after randg produces only 3-4 different numbers.
Thank you.
Etsuko

この質問は閉じられています。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by