Skip to content

Commit a8ac5f4

Browse files
committed
DOC: Fix PRNG doc strings
Improve PRNG doc strings Add Jump docstring for MT19937
1 parent 8bd5a71 commit a8ac5f4

File tree

5 files changed

+69
-17
lines changed

5 files changed

+69
-17
lines changed

randomstate/interface/dSFMT/dSFMT.pxi

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ hashing function is used as the initial state. Using a single 32-bit value
155155
for the seed can only initialize a small range of the possible initial
156156
state values.
157157
158+
References
159+
----------
158160
.. [1] Mutsuo Saito and Makoto Matsumoto, "SIMD-oriented Fast Mersenne
159161
Twister: a 128-bit Pseudorandom Number Generator." Monte Carlo
160162
and Quasi-Monte Carlo Methods 2006, Springer, pp. 607 -- 622, 2008.

randomstate/interface/random-kit/random-kit.pxi

+50-7
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ was made will be noted in the relevant docstring. Extension of existing
7272
parameter ranges and the addition of new parameters is allowed as long the
7373
previous behavior remains unchanged.
7474
75-
``mt19937.RandomState`` can be used in parallel applications by
76-
calling the method ``jump`` which advances the state as-if :math:`2^{128}`
77-
random numbers have been generated [2]_. This allows the original sequence to
78-
be split so that distinct segments can be used in each worker process. All
79-
generators should be initialized with the same seed to ensure that the
80-
segments come from the same sequence.
81-
8275
Parameters
8376
----------
8477
seed : {None, int, array_like}, optional
@@ -96,4 +89,54 @@ pseudo-random number generator with a number of methods that are similar
9689
to the ones available in ``RandomState``. ``RandomState``, besides being
9790
NumPy-aware, has the advantage that it provides a much larger number
9891
of probability distributions to choose from.
92+
93+
**Parallel Features**
94+
95+
``mt19937.RandomState`` can be used in parallel applications by
96+
calling the method ``jump`` which advances the state as-if :math:`2^{128}`
97+
random numbers have been generated ([1]_, [2]_). This allows the original sequence to
98+
be split so that distinct segments can be used in each worker process. All
99+
generators should be initialized with the same seed to ensure that the
100+
segments come from the same sequence.
101+
102+
>>> from randomstate.entropy import random_entropy
103+
>>> import randomstate.prng.mt19937 as rnd
104+
>>> seed = random_entropy()
105+
>>> rs = [rnd.RandomState(seed) for _ in range(10)]
106+
# Advance rs[i] by i jumps
107+
>>> for i in range(10):
108+
rs[i].jump(i)
109+
110+
References
111+
----------
112+
.. [1] Hiroshi Haramoto, Makoto Matsumoto, and Pierre L\'Ecuyer, "A Fast
113+
Jump Ahead Algorithm for Linear Recurrences in a Polynomial Space",
114+
Sequences and Their Applications - SETA, 290--298, 2008.
115+
.. [2] Hiroshi Haramoto, Makoto Matsumoto, Takuji Nishimura, François
116+
Panneton, Pierre L\'Ecuyer, "Efficient Jump Ahead for F2-Linear
117+
Random Number Generators", INFORMS JOURNAL ON COMPUTING, Vol. 20,
118+
No. 3, Summer 2008, pp. 385-390.
119+
120+
"""
121+
122+
DEF JUMP_DOCSTRING = u"""
123+
jump(iter = 1)
124+
125+
Jumps the state of the random number generator as-if 2**128 random numbers
126+
have been generated.
127+
128+
Parameters
129+
----------
130+
iter : integer, positive
131+
Number of times to jump the state of the prng.
132+
133+
Returns
134+
-------
135+
out : None
136+
Returns 'None' on success.
137+
138+
Notes
139+
-----
140+
Jumping the rng state resets any pre-computed random numbers. This is required
141+
to ensure exact reproducibility.
99142
"""

randomstate/interface/sfmt/sfmt.pxi

+9-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ RandomState(seed=None)
8181
8282
Container for the SIMD-based Mersenne Twister pseudo-random number generator.
8383
84-
``dSFMT.RandomState`` exposes a number of methods for generating random
84+
``sfmt.RandomState`` exposes a number of methods for generating random
8585
numbers drawn from a variety of probability distributions [1]_ . In addition
8686
to the distribution-specific arguments, each method takes a keyword argument
8787
`size` that defaults to ``None``. If `size` is ``None``, then a single
@@ -91,8 +91,8 @@ then an array with that shape is filled and returned.
9191
9292
**No Compatibility Guarantee**
9393
94-
``dSFMT.RandomState`` does not make a guarantee that a fixed seed and a
95-
fixed series of calls to ``dSFMT.RandomState`` methods using the same
94+
``sfmt.RandomState`` does not make a guarantee that a fixed seed and a
95+
fixed series of calls to ``sfmt.RandomState`` methods using the same
9696
parameters will always produce the same results. This is different from
9797
``numpy.random.RandomState`` guarantee. This is done to simplify improving
9898
random number generators. To ensure identical results, you must use the
@@ -104,7 +104,7 @@ seed : {None, int, array_like}, optional
104104
Random seed initializing the pseudo-random number generator.
105105
Can be an integer in [0, 2**32-1], array of integers in
106106
[0, 2**32-1] or ``None`` (the default). If `seed` is ``None``,
107-
then ``dSFMT.RandomState`` will try to read entropy from
107+
then ``sfmt.RandomState`` will try to read entropy from
108108
``/dev/urandom`` (or the Windows analog) if available to
109109
produce a 64-bit seed. If unavailable, the a 64-bit hash of the time
110110
and process ID is used.
@@ -154,9 +154,14 @@ hashing function is used as the initial state. Using a single 32-bit value
154154
for the seed can only initialize a small range of the possible initial
155155
state values.
156156
157+
References
158+
----------
157159
.. [1] Mutsuo Saito and Makoto Matsumoto, "SIMD-oriented Fast Mersenne
158160
Twister: a 128-bit Pseudorandom Number Generator." Monte Carlo
159161
and Quasi-Monte Carlo Methods 2006, Springer, pp. 607 -- 622, 2008.
162+
.. [2] Hiroshi Haramoto, Makoto Matsumoto, and Pierre L\'Ecuyer, "A Fast
163+
Jump Ahead Algorithm for Linear Recurrences in a Polynomial Space",
164+
Sequences and Their Applications - SETA, 290--298, 2008.
160165
"""
161166

162167
DEF JUMP_DOCSTRING = u"""

randomstate/interface/xorshift1024/xorshift1024.pxi

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ RandomState(seed=None)
5353
Container for the xorshift1024* pseudo-random number generator.
5454
5555
xorshift1024* is a 64-bit implementation of Saito and Matsumoto's XSadd
56-
generator [1]_. xorshift1024* has a period of :math:`2^{1024} - 1` and
57-
supports jumping the sequence in increments of :math:`2^{512}`, which allows
58-
multiple non-overlapping sequences to be generated.
56+
generator [1]_ (see also [2]_, [3]_, [4]_). xorshift1024* has a period of
57+
:math:`2^{1024} - 1` and supports jumping the sequence in increments of
58+
:math:`2^{512}`, which allows multiple non-overlapping sequences to be
59+
generated.
5960
6061
``xorshift1024.RandomState`` exposes a number of methods for generating random
6162
numbers drawn from a variety of probability distributions. In addition to the

randomstate/interface/xorshift128/xorshift128.pxi

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ RandomState(seed=None)
4848
Container for the xorshift128+ pseudo-random number generator.
4949
5050
xorshift128+ is a 64-bit implementation of Saito and Matsumoto's XSadd
51-
generator [1]_. xorshift128+ has a period of :math:`2^{128} - 1` and
52-
supports jumping the sequence in increments of :math:`2^{64}`, which allows
53-
multiple non-overlapping sequences to be generated.
51+
generator [1]_ (see also [2]_, [3]_, [4]_). xorshift128+ has a period of
52+
:math:`2^{128} - 1` and supports jumping the sequence in increments of
53+
:math:`2^{64}`, which allows multiple non-overlapping sequences to be
54+
generated.
5455
5556
``xorshift128.RandomState`` exposes a number of methods for generating random
5657
numbers drawn from a variety of probability distributions. In addition to the

0 commit comments

Comments
 (0)