|
| 1 | +randomstate |
| 2 | +=========== |
| 3 | + |
| 4 | +|Travis Build Status| |Appveyor Build Status| |
| 5 | + |
| 6 | +This is a library and generic interface for alternative random |
| 7 | +generators in Python and Numpy. |
| 8 | + |
| 9 | +Features |
| 10 | + |
| 11 | +- Immediate drop in replacement for Numy's RandomState |
| 12 | + |
| 13 | +.. code:: python |
| 14 | +
|
| 15 | + # import numpy.random as rnd |
| 16 | + import randomstate as rnd |
| 17 | + x = rnd.standard_normal(100) |
| 18 | + y = rnd.random_sample(100) |
| 19 | + z = rnd.randn(10,10) |
| 20 | +
|
| 21 | +- Default random generator is identical to NumPy's RandomState (i.e., |
| 22 | + same seed, same random numbers). |
| 23 | +- Support for random number generators that support independent streams |
| 24 | + and jumping ahead so that substreams can be generated |
| 25 | +- Faster ranomd number generations, especially for Normals using the |
| 26 | + Ziggurat method |
| 27 | + |
| 28 | +.. code:: python |
| 29 | +
|
| 30 | + import randomstate as rnd |
| 31 | + w = rnd.standard_normal(10000, method='zig') |
| 32 | +
|
| 33 | +Included Pseudo Random Number Generators |
| 34 | +---------------------------------------- |
| 35 | + |
| 36 | +This modules includes a number of alternative random number generators |
| 37 | +in addition to the MT19937 that is included in NumPy. The RNGs include: |
| 38 | + |
| 39 | +- `MT19937 <https://github.com/numpy/numpy/blob/master/numpy/random/mtrand/>`__, |
| 40 | + the NumPy rng |
| 41 | +- `dSFMT <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/>`__ a |
| 42 | + SSE2-aware version of the MT19937 generator that is especially fast |
| 43 | + at generating doubles |
| 44 | +- `xorshift128+ <http://xorshift.di.unimi.it/>`__ and |
| 45 | + `xorshift1024\* <http://xorshift.di.unimi.it/>`__ |
| 46 | +- `PCG32 <http://www.pcg-random.org/>`__ and |
| 47 | + `PCG64 <http:w//www.pcg-random.org/>`__ |
| 48 | +- `MRG32K3A <http://simul.iro.umontreal.ca/rng>`__ |
| 49 | +- A multiplicative lagged fibonacci generator (LFG(31, 1279, 861, \*)) |
| 50 | + |
| 51 | +Differences from ``numpy.random.RandomState`` |
| 52 | +--------------------------------------------- |
| 53 | + |
| 54 | +New Features |
| 55 | +~~~~~~~~~~~~ |
| 56 | + |
| 57 | +- ``stanard_normal``, ``normal``, ``randn`` and ``multivariate_normal`` |
| 58 | + all support an additional ``method`` keyword argument which can be |
| 59 | + ``inv`` or ``zig`` where ``inv`` corresponds to the current method |
| 60 | + and ``zig`` uses tha much faster (100%+) ziggurat method. |
| 61 | + |
| 62 | +New Functions |
| 63 | +~~~~~~~~~~~~~ |
| 64 | + |
| 65 | +- ``random_entropy`` - Read from the system entropy provider, which is |
| 66 | + commonly used in cryptographic applications |
| 67 | +- ``random_uintegers`` - unsigned integers ``[0, 2**64-1]`` |
| 68 | +- ``jump`` - Jumps RNGs that support it. ``jump`` moves the state a |
| 69 | + great distance. *Only available if supported by the RNG.* |
| 70 | +- ``advance`` - Advanced the core RNG 'as-if' a number of draws were |
| 71 | + made, without actually drawing the numbers. *Only available if |
| 72 | + supported by the RNG.* |
| 73 | + |
| 74 | +Status |
| 75 | +------ |
| 76 | + |
| 77 | +- Complete drop-in replacement for ``numpy.random.RandomState``. The |
| 78 | + ``mt19937`` generator is identical to ``numpy.random.RandomState``, |
| 79 | + and will produce an identical sequence of random numbers for a given |
| 80 | + seed. |
| 81 | +- Builds and passes all tests on: |
| 82 | +- Linux 32/64 bit, Python 2.6, 2.7, 3.3, 3.4, 3.5 |
| 83 | +- PC-BSD (FreeBSD) 64-bit, Python 2.7 |
| 84 | +- OSX 64-bit, Python 2.7 |
| 85 | +- Windows 32/64 bit (only tested on Python 2.7 and 3.5, but should work |
| 86 | + on 3.3/3.4) |
| 87 | + |
| 88 | +Version |
| 89 | +------- |
| 90 | + |
| 91 | +The version matched the latest verion of NumPy where |
| 92 | +``randomstate.prng.mt19937`` passes all NumPy test. |
| 93 | + |
| 94 | +Documentation |
| 95 | +------------- |
| 96 | + |
| 97 | +A occasionally updated build of the documentation is available on `my |
| 98 | +github pages <http://bashtage.github.io/ng-numpy-randomstate/>`__. |
| 99 | + |
| 100 | +Plans |
| 101 | +----- |
| 102 | + |
| 103 | +This module is essentially complete. There are a few rough edges that |
| 104 | +need to be smoothed. |
| 105 | + |
| 106 | +- Stream support for MLFG and MRG32K3A |
| 107 | +- Creation of additional streams from a RandomState where supported |
| 108 | + (i.e. a ``next_stream()`` method) |
| 109 | + |
| 110 | +Requirements |
| 111 | +------------ |
| 112 | + |
| 113 | +Building requires: |
| 114 | + |
| 115 | +- Numpy (1.9, 1.10) |
| 116 | +- Cython (0.22, 0.23) |
| 117 | +- Python (2.6, 2.7, 3.3, 3.4, 3.5) |
| 118 | + |
| 119 | +**Note:** it might work with other versions but only tested with these |
| 120 | +versions. |
| 121 | + |
| 122 | +All development has been on 64-bit Linux, and it is regularly tested on |
| 123 | +Travis-CI. The library is occasionally tested on Linux 32-bit, OSX |
| 124 | +10.10, PC-BSD 10.2 (should also work on Free BSD) and Windows (Python |
| 125 | +2.7/3.5, both 32 and 64-bit). |
| 126 | + |
| 127 | +Basic tests are in place for all RNGs. The MT19937 is tested against |
| 128 | +NumPy's implementation for identical results. It also passes NumPy's |
| 129 | +test suite. |
| 130 | + |
| 131 | +Installing |
| 132 | +---------- |
| 133 | + |
| 134 | +.. code:: bash |
| 135 | +
|
| 136 | + python setup.py install |
| 137 | +
|
| 138 | +Windows |
| 139 | +~~~~~~~ |
| 140 | + |
| 141 | +Either use a binary installer or if building from scratch using Python |
| 142 | +3.5 and the free Visual Studio 2015 Community Edition. It can also be |
| 143 | +build using Microsoft Visual C++ Compiler for Python 2.7 and Python 2.7, |
| 144 | +although some modifications are needed to distutils to find the |
| 145 | +compiler. |
| 146 | + |
| 147 | +Using |
| 148 | +----- |
| 149 | + |
| 150 | +The separate generators are importable from ``randomstate.prng``. |
| 151 | + |
| 152 | +.. code:: python |
| 153 | +
|
| 154 | + import randomstate |
| 155 | + rs = randomstate.prng.xorshift128.RandomState() |
| 156 | + rs.random_sample(100) |
| 157 | +
|
| 158 | + rs = randomstate.prng.pcg64.RandomState() |
| 159 | + rs.random_sample(100) |
| 160 | +
|
| 161 | + # Identical to NumPy |
| 162 | + rs = randomstate.prng.mt19937.RandomState() |
| 163 | + rs.random_sample(100) |
| 164 | +
|
| 165 | +Like NumPy, ``randomstate`` also exposes a single instance of the |
| 166 | +``mt19937`` generator directly at the module level so that commands like |
| 167 | + |
| 168 | +.. code:: python |
| 169 | +
|
| 170 | + import randomstate |
| 171 | + randomstate.standard_normal() |
| 172 | + randomstate.exponential(1.0, 1.0, size=10) |
| 173 | +
|
| 174 | +will work. |
| 175 | + |
| 176 | +License |
| 177 | +------- |
| 178 | + |
| 179 | +Standard NCSA, plus sub licenses for components. |
| 180 | + |
| 181 | +Performance |
| 182 | +----------- |
| 183 | + |
| 184 | +Performance is promising, and even the mt19937 seems to be faster than |
| 185 | +NumPy's mt19937. |
| 186 | + |
| 187 | +:: |
| 188 | + |
| 189 | + Speed-up relative to NumPy (Slow Normals) |
| 190 | + ************************************************************ |
| 191 | + randomstate.prng-dsfmt-standard_normal 107.2% |
| 192 | + randomstate.prng-mlfg_1279_861-standard_normal 51.2% |
| 193 | + randomstate.prng-mrg32k3a-standard_normal -11.8% |
| 194 | + randomstate.prng-mt19937-standard_normal 44.0% |
| 195 | + randomstate.prng-pcg32-standard_normal 51.2% |
| 196 | + randomstate.prng-pcg64-standard_normal 51.1% |
| 197 | + randomstate.prng-xorshift1024-standard_normal 50.5% |
| 198 | + randomstate.prng-xorshift128-standard_normal 52.1% |
| 199 | + |
| 200 | + Speed-up relative to NumPy (Ziggural Normals) |
| 201 | + ************************************************************ |
| 202 | + randomstate.prng-dsfmt-standard_normal 283.7% |
| 203 | + randomstate.prng-mlfg_1279_861-standard_normal 217.4% |
| 204 | + randomstate.prng-mrg32k3a-standard_normal 16.6% |
| 205 | + randomstate.prng-mt19937-standard_normal 201.3% |
| 206 | + randomstate.prng-pcg32-standard_normal 274.9% |
| 207 | + randomstate.prng-pcg64-standard_normal 310.8% |
| 208 | + randomstate.prng-xorshift1024-standard_normal 336.3% |
| 209 | + randomstate.prng-xorshift128-standard_normal 425.1% |
| 210 | + |
| 211 | +.. |Travis Build Status| image:: https://travis-ci.org/bashtage/ng-numpy-randomstate.svg?branch=master |
| 212 | + :target: https://travis-ci.org/bashtage/ng-numpy-randomstate |
| 213 | +.. |Appveyor Build Status| image:: https://ci.appveyor.com/api/projects/status/odc5c4ukhru5xicl/branch/master?svg=true |
| 214 | + :target: https://ci.appveyor.com/project/bashtage/ng-numpy-randomstate/branch/master |
0 commit comments