[SciPy-dev] random seed in scipy.stats
Sun Apr 20 15:23:51 CDT 2008
Okay, I'm planning to add this to the stats module this afternoon, and
I need to check with people on the best way to include the new random
Allow two additional keyword arguments to the constructor and to the
rvs functions, namely randseed and prng. If neither are given, it
would default to the current behavior and draw straight from
numpy.random. If randseed is given, but not prng, it would create a
random state object with that seed. prng would be a RandomState
object from numpy.random; if given randseed is ignored and that is
used to draw the random numbers. Any concerns?
have a single additional kw arg like rnginfo or randominfo. If it's a
RandomState instance, it is used to draw numbers from. If it's
anything else, it's used to seed the random number generator. If it's
None, it's discarded.
With both options, arguments to the rvs method would override the
arguments to the constructor, but only for that function call.
I would personally go for 1., as it seems the potential for API
confusion is a lot less. Also, 2 wouldn't allow people to pass in
arbitrary random number generating objects that defined the correct
methods, whereas 1 would (though this would probably be pretty rare).
Now if we do 1, is prng the best argument name for the randomstate
object? I could also use rso, rng, randomstateobject, etc.
On Sun, Apr 20, 2008 at 12:44 AM, Hoyt Koepke <firstname.lastname@example.org> wrote:
> > My preference is for a pattern like this:
> > def somefunc(x,y,z, prng=numpy.random):
> > w = prng.standard_normal()
> > ...
> > This allows the default uses to share the same generator state which
> > could avoid some problematic cases.
> This makes sense; I agree. I also like the option of passing a
> straight random seed as an option. I will at least include your
> suggestion, and both if it isn't too hard and no one objects.
> Since scipy.stats works with objects, it seems there are three options:
> 1. pass prng to the constructor; then all of the members use it.
> 2. pass prng individually to each rvs() function.
> 3. both 1 & 2
> I can see arguments for both, so 3 might be the best option.
> > But yes, such a change would be very welcome. It might be a
> > substantial chunk of work, though, which is why I haven't done it.
> Maybe, but unless I'm missing something it looks fairly
> straightforward. It imports numpy.random as mtrand, nice and unique,
> so it looks like it will be a lot of search and replace. Like I said,
> it would be quite useful for me, so I'll see what I can do.
> Hoyt Koepke
> UBC Department of Computer Science
UBC Department of Computer Science
More information about the Scipy-dev