GithubHelp home page GithubHelp logo

Comments (6)

bashtage avatar bashtage commented on June 18, 2024 1

I hope the explanation above is clear. If not, let me know. I'll add to the documentation.

from ng-numpy-randomstate.

bashtage avatar bashtage commented on June 18, 2024

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.

mkoerner avatar mkoerner commented on June 18, 2024

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.

bashtage avatar bashtage commented on June 18, 2024

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.

bashtage avatar bashtage commented on June 18, 2024

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.

mkoerner avatar mkoerner commented on June 18, 2024

Ah. Thanks again for the clarification.
... and for the library 👍

Mathias

from ng-numpy-randomstate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.