1
- # ng-numpy- randomstate
1
+ # randomstate
2
2
[ ![ Build Status] ( https://travis-ci.org/bashtage/ng-numpy-randomstate.svg?branch=master )] ( https://travis-ci.org/bashtage/ng-numpy-randomstate )
3
3
[ ![ Build status] ( https://ci.appveyor.com/api/projects/status/odc5c4ukhru5xicl/branch/master?svg=true )] ( https://ci.appveyor.com/project/bashtage/ng-numpy-randomstate/branch/master )
4
4
5
5
This is a library and generic interface for alternative random generators
6
- in Python and Numpy. This modules includes a number of alternative random
6
+ in Python and Numpy.
7
+
8
+ Features
9
+
10
+ * Immediate drop in replacement for Numy's RandomState
11
+
12
+ ``` python
13
+ # import numpy.random as rnd
14
+ import randomstate as rnd
15
+ x = rnd.standard_normal(100 )
16
+ y = rnd.random_sample(100 )
17
+ z = rnd.randn(10 ,10 )
18
+ ```
19
+
20
+ * Default random generator is identical to NumPy's RandomState (i.e., same
21
+ seed, same random numbers).
22
+ * Support for random number generators that support independent streams and
23
+ jumping ahead so that substreams can be generated
24
+ * Faster ranomd number generations, especially for Normals using the Ziggurat
25
+ method
26
+
27
+ ``` python
28
+ import randomstate as rnd
29
+ w = rnd.standard_normal(10000 , method = ' zig' )
30
+ ```
31
+
32
+ ## Included Pseudo Random Number Generators
33
+
34
+ This modules includes a number of alternative random
7
35
number generators in addition to the MT19937 that is included in NumPy.
8
36
The RNGs include:
9
37
@@ -17,11 +45,23 @@ version of the MT19937 generator that is especially fast at generating doubles
17
45
* [ MRG32K3A] ( http://simul.iro.umontreal.ca/rng )
18
46
* A multiplicative lagged fibonacci generator (LFG(31, 1279, 861, * ))
19
47
20
- ## Rationale
21
- The main reason for this project is to include other PRNGs that support
22
- important features when working in parallel such as the ability to produce
23
- multiple independent streams, to quickly advance the generator, or to jump
24
- ahead.
48
+ ## Differences from ` numpy.random.RandomState `
49
+
50
+ ### New Features
51
+ * ` stanard_normal ` , ` normal ` , ` randn ` and ` multivariate_normal ` all support
52
+ an additional ` method ` keyword argument which can be ` inv ` or ` zig ` where
53
+ ` inv ` corresponds to the current method and ` zig ` uses tha much faster
54
+ (100%+) ziggurat method.
55
+
56
+ ### New Functions
57
+
58
+ * ` random_entropy ` - Read from the system entropy provider, which is commonly
59
+ used in cryptographic applications
60
+ * ` random_uintegers ` - unsigned integers ` [0, 2**64-1] `
61
+ * ` jump ` - Jumps RNGs that support it. ` jump ` moves the state a great
62
+ distance. _ Only available if supported by the RNG._
63
+ * ` advance ` - Advanced the core RNG 'as-if' a number of draws were made,
64
+ without actually drawing the numbers. _ Only available if supported by the RNG._
25
65
26
66
## Status
27
67
@@ -33,15 +73,14 @@ identical sequence of random numbers for a given seed.
33
73
* PC-BSD (FreeBSD) 64-bit, Python 2.7
34
74
* OSX 64-bit, Python 2.7
35
75
* Windows 32/64 bit (only tested on Python 2.7 and 3.5, but should work on 3.3/3.4)
36
- * There is no documentation for the core RNGs.
37
76
38
77
## Documentation
39
78
40
- A occasionally update build of the documentation is available on
79
+ A occasionally updated build of the documentation is available on
41
80
[ my github pages] ( http://bashtage.github.io/ng-numpy-randomstate/ ) .
42
81
43
82
## Plans
44
- It is essentially complete. There are a few rough edges that need to be smoothed.
83
+ This module is essentially complete. There are a few rough edges that need to be smoothed.
45
84
46
85
* Stream support for MLFG and MRG32K3A
47
86
* Creation of additional streams from a RandomState where supported (i.e.
@@ -71,15 +110,11 @@ implementation for identical results. It also passes NumPy's test suite.
71
110
python setup.py install
72
111
```
73
112
74
- ## Building for Testing Purposes
75
-
76
- This command will build a single module containining xorshift128 called
77
- ` interface ` .
78
-
79
- ``` bash
80
- cd randomstate
81
- python setup-basic.py build_ext --inplace
82
- ```
113
+ ### Windows
114
+ Either use a binary installer or if building from scratch using Python 3.5 and
115
+ the free Visual Studio 2015 Community Edition. It can also be build using
116
+ Microsoft Visual C++ Compiler for Python 2.7 and Python 2.7, although some
117
+ modifications are needed to distutils to find the compiler.
83
118
84
119
## Using
85
120
@@ -99,7 +134,7 @@ rs.random_sample(100)
99
134
```
100
135
101
136
Like NumPy, ` randomstate ` also exposes a single instance of the ` mt19937 `
102
- generator directly at the moduel level so that commands like
137
+ generator directly at the module level so that commands like
103
138
104
139
``` python
105
140
import randomstate
@@ -109,70 +144,32 @@ randomstate.exponential(1.0, 1.0, size=10)
109
144
110
145
will work.
111
146
112
- If you use ` setup-basic.py ` ,
113
-
114
- ``` python
115
- import interface
116
-
117
- rs = interface.RandomState()
118
- rs.random_sample(100 )
119
- ```
120
-
121
147
## License
122
148
Standard NCSA, plus sub licenses for components.
123
149
124
150
## Performance
125
151
Performance is promising, and even the mt19937 seems to be faster than NumPy's mt19937.
126
152
127
153
```
128
- Time to produce 1,000,000 Standard normals
154
+ Speed-up relative to NumPy (Slow Normals)
129
155
************************************************************
130
- numpy-random -standard_normal 58.34 ms
131
- randomstate.prng-mlfg_1279_861-standard_normal 46.20 ms
132
- randomstate.prng-mrg32k3a-standard_normal 75.95 ms
133
- randomstate.prng-mt19937-standard_normal 52.68 ms
134
- randomstate.prng-pcg32-standard_normal 48.38 ms
135
- randomstate.prng-pcg64-standard_normal 46.27 ms
136
- randomstate.prng-xorshift1024-standard_normal 45.53 ms
137
- randomstate.prng-xorshift128-standard_normal 45.57 ms
138
-
139
- Standard normals per second
156
+ randomstate.prng-dsfmt -standard_normal 107.2%
157
+ randomstate.prng-mlfg_1279_861-standard_normal 51.2%
158
+ randomstate.prng-mrg32k3a-standard_normal -11.8%
159
+ randomstate.prng-mt19937-standard_normal 44.0%
160
+ randomstate.prng-pcg32-standard_normal 51.2%
161
+ randomstate.prng-pcg64-standard_normal 51.1%
162
+ randomstate.prng-xorshift1024-standard_normal 50.5%
163
+ randomstate.prng-xorshift128-standard_normal 52.1%
164
+
165
+ Speed-up relative to NumPy (Ziggural Normals)
140
166
************************************************************
141
- numpy-random-standard_normal 17.14 million
142
- randomstate.prng-mlfg_1279_861-standard_normal 21.65 million
143
- randomstate.prng-mrg32k3a-standard_normal 13.17 million
144
- randomstate.prng-mt19937-standard_normal 18.98 million
145
- randomstate.prng-pcg32-standard_normal 20.67 million
146
- randomstate.prng-pcg64-standard_normal 21.61 million
147
- randomstate.prng-xorshift1024-standard_normal 21.96 million
148
- randomstate.prng-xorshift128-standard_normal 21.94 million
149
-
150
- Speed-up relative to NumPy
151
- ************************************************************
152
- randomstate.prng-mlfg_1279_861-standard_normal 26.3%
153
- randomstate.prng-mrg32k3a-standard_normal -23.2%
154
- randomstate.prng-mt19937-standard_normal 10.8%
155
- randomstate.prng-pcg32-standard_normal 20.6%
156
- randomstate.prng-pcg64-standard_normal 26.1%
157
- randomstate.prng-xorshift1024-standard_normal 28.1%
158
- randomstate.prng-xorshift128-standard_normal 28.0%
159
-
160
- --------------------------------------------------------------------------------
167
+ randomstate.prng-dsfmt-standard_normal 283.7%
168
+ randomstate.prng-mlfg_1279_861-standard_normal 217.4%
169
+ randomstate.prng-mrg32k3a-standard_normal 16.6%
170
+ randomstate.prng-mt19937-standard_normal 201.3%
171
+ randomstate.prng-pcg32-standard_normal 274.9%
172
+ randomstate.prng-pcg64-standard_normal 310.8%
173
+ randomstate.prng-xorshift1024-standard_normal 336.3%
174
+ randomstate.prng-xorshift128-standard_normal 425.1%
161
175
```
162
-
163
- ## Differences from ` numpy.random.RandomState `
164
-
165
- ### New Features
166
- * ` stanard_normal ` and ` normal ` support an additional ` method ` keyword
167
- argument which can be ` inv ` or ` zig ` where ` inv ` corresponds to the
168
- current method and ` zig ` uses tha much faster (100%+) ziggurat method.
169
-
170
- ### New Functions
171
-
172
- * ` random_entropy ` - Read from the system entropy provider, which is commonly
173
- used in cryptographic applications
174
- * ` random_uintegers ` - unsigned integers ` [0, 2**64-1] `
175
- * ` jump ` - Jumps RNGs that support it. ` jump ` moves the state a great
176
- distance. _ Only available if supported by the RNG._
177
- * ` advance ` - Advanced the core RNG 'as-if' a number of draws were made,
178
- without actually drawing the numbers. _ Only available if supported by the RNG._
0 commit comments