exponential random draws and the seed
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (3)
Walter Roberson
le 16 Fév 2012
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
le 16 Fév 2012
What's your version of MATLAB? setGlobalStream is introduced in R2011a, try
RandStream.setDefaultStream(s)
3 commentaires
Walter Roberson
le 16 Fév 2012
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
le 17 Fév 2012
@Walter, you are right, and thanks for pointing that out. I was not reading the comment correctly. I'm removing my comment.
Peter Perkins
le 17 Fév 2012
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 commentaires
Walter Roberson
le 21 Fév 2012
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
le 21 Fév 2012
I've made a note to have that reference page clarified. Thanks for pointing it out.
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!