exponential random draws and the seed
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello,
I have a question about setting a seed on random numbers. I have tried
s = RandStream('mt19937ar','Seed','shuffle');
RandStream.setGlobalStream(s);
but it does not work obviously.
Is there embedded seed that I can use in drawing exponential random variables like rand 'twitter' 'seed' type of stuff?
Thanks
댓글 수: 0
답변 (3개)
Walter Roberson
2012년 2월 16일
The 'shuffle' keyword was not added until R2011a
I do not understand about the reference to twitter.
You can use any integer seed up to 2^32-1
Honglei Chen
2012년 2월 16일
What's your version of MATLAB? setGlobalStream is introduced in R2011a, try
RandStream.setDefaultStream(s)
댓글 수: 3
Walter Roberson
2012년 2월 16일
The stream advances as you use it. Setting it as a default stream does not in any way reset it. Default stream is just a matter of which stream is used by default if the code does not specifically ask for a different stream to be used.
If you call your "default pizza delivery store", you always get a current pizza made fresh; re-setting your default pizza delivery store back to the same store does not cause the store to go back and start re-making pizzas exactly like the old ones again.
Compare:
s = RandStream('mt19937ar','Seed',100);
RandStream.setDefaultStream(s);
U1=exprnd(1, [n,g] );
s = RandStream('mt19937ar','Seed',100);
RandStream.setDefaultStream(s);
U2=exprnd(1, [n,g] );
Now U1 and U2 should be the same: you reset back to the same conditions.
Honglei Chen
2012년 2월 17일
@Walter, you are right, and thanks for pointing that out. I was not reading the comment correctly. I'm removing my comment.
Peter Perkins
2012년 2월 17일
etcann, It appears you are using MATLAB 2010a. That release pre-dates the introduction of RandStream.setGlobalStream, which is except for the name is identical to the older RandStream.setDefaultStream. The new name was added because people found the "default" in setDefaultStream to be confusing.
If you were using R2011a, I'd suggest that you use the RNG function, which is a bit more like the even older (and now discouraged) rand('twister',seed).
Walter's suggestion would work, or even simpler,
s = RandStream('mt19937ar','Seed',100);
RandStream.setDefaultStream(s);
U1=exprnd(1, [n,g] );
reset(s);
U2=exprnd(1, [n,g] );
The point is that the random stream that you create in the first line, and make the global default in the second, changes it's state when you call exprnd. So you have to reset it, or create a new one, if you want to go back to where you started.
댓글 수: 8
Walter Roberson
2012년 2월 21일
My concern was about the missing "or to the seed that you most recently reset the stream with <etc>" (as such a seed would, by definition, not be part of the "initial internal state"). The behavior you describe now does make sense.
Peter Perkins
2012년 2월 21일
I've made a note to have that reference page clarified. Thanks for pointing it out.
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!