Borrar filtros
Borrar filtros

exponential random draws and the seed

11 visualizaciones (últimos 30 días)
etcann
etcann el 16 de Feb. de 2012
Editada: Azzi Abdelmalek el 19 de Oct. de 2013
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

Respuestas (3)

Walter Roberson
Walter Roberson el 16 de Feb. de 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
  1 comentario
etcann
etcann el 16 de Feb. de 2012
Sorry, it is twister not twitter. So it usually goes like rand('twister') or randn('state'). But I wonder if this is only for rand or randn but not for exprnd...
Also,
s = RandStream('mt19937ar','Seed',100);
RandStream.setGlobalStream(s);
gives the msg as
??? No appropriate method, property, or field setGlobalStream
for class RandStream.

Iniciar sesión para comentar.


Honglei Chen
Honglei Chen el 16 de Feb. de 2012
What's your version of MATLAB? setGlobalStream is introduced in R2011a, try
RandStream.setDefaultStream(s)
  3 comentarios
Walter Roberson
Walter Roberson el 16 de Feb. de 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
Honglei Chen el 17 de Feb. de 2012
@Walter, you are right, and thanks for pointing that out. I was not reading the comment correctly. I'm removing my comment.

Iniciar sesión para comentar.


Peter Perkins
Peter Perkins el 17 de Feb. de 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 comentarios
Walter Roberson
Walter Roberson el 21 de Feb. de 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
Peter Perkins el 21 de Feb. de 2012
I've made a note to have that reference page clarified. Thanks for pointing it out.

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by