Comments (6)
I hope the explanation above is clear. If not, let me know. I'll add to the documentation.
from ng-numpy-randomstate.
randint
is efficient in that is uses the smallest number of bytes required to produce the values from the PRNG, and so the dtype affects what you get. In the case of int32
it will generate 2 per 64-bit random generated by PCG.
The only generator that is absolutely guaranteed to behave like you see above is random_raw
since it never will transform the underlying output of the PRNG. As you have seen, for some distributions this will always work. For others which use fewer bits (randint
) or which use rejection sampling (many) then this simple relationship cannot be easily enforced.
g = rs.prng.pcg64.RandomState(0,0)
x = g.random_raw(10)
g = rs.prng.pcg64.RandomState(0,0)
g.advance(5)
y = g.random_raw(10)
import numpy as np
assert np.all(x[5:]==y[:-5])
from ng-numpy-randomstate.
Sorry for not replying earlier. The explanation was very helpful. As is more documentation. Given your description, a colleague and myself expected advance
to "work well" with generating 64-bit random integers, but
import randomstate as rs
import numpy as np
g = rs.prng.pcg64.RandomState(0,0)
x = g.randint(256, size=10, dtype=np.uint64)
g = rs.prng.pcg64.RandomState(0,0)
g.advance(5)
y = g.randint(256, size=10, dtype=np.uint64)
assert np.all(x[5:]==y[:-5])
also raised an exception.
PS: Do you happen to know, if all bits of the numbers generated by PCG64 are of equal quality?
from ng-numpy-randomstate.
This works as expected:
g = rs.prng.pcg64.RandomState(0,0)
x = g.randint(2**64-1, size=10, dtype=np.uint64)
g = rs.prng.pcg64.RandomState(0,0)
g.advance(5)
y = g.randint(2**64-1, size=10, dtype=np.uint64)
assert np.all(x[5:]==y[:-5])
You are seeing the behavior you see because of this optimization:
https://github.com/bashtage/ng-numpy-randomstate/blob/master/randomstate/distributions.c#L1415
which uses 32-bit integers when the value required is < 2**32.
from ng-numpy-randomstate.
As for pcg64
, I've never seen any problems when it is run through tests (which test for dependence in high/low bits). This said, If I needed a log of PRNGs I would go with xorshift1024
with jumps.
from ng-numpy-randomstate.
Ah. Thanks again for the clarification.
... and for the library 👍
Mathias
from ng-numpy-randomstate.
Related Issues (20)
- is this normal? HOT 5
- Python 3.6 wheels HOT 8
- help on RandomState functions show numpy examples HOT 3
- Can not be used on Debian 9 HOT 3
- Can you provide a function to generate random number from multiple streams HOT 3
- Jump is too slow for larger jump steps! HOT 10
- optimized uniform small integers? HOT 4
- Add xoroshiro128+ HOT 1
- Lift "No Compatibility Guarantee" HOT 5
- Improve docstring for dtype
- Upload the latests releases to pypi? HOT 1
- faster ziggurat-like methods HOT 9
- did random_uintegers go away? HOT 11
- Segfault when seeding some prng's with float64 HOT 6
- Jump function for the MT19937 HOT 9
- A bug in MultithreadedRNG HOT 8
- Is there a generic randomstate class I can inherit from? HOT 3
- lognormal doc enhancement? HOT 2
- 1.13 fails to build HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-numpy-randomstate.