numpy
lets you generate random samples from a beta distribution (or any other arbitrary distribution) with this API:
samples = np.random.beta(a,b, size=1000)
What is this doing beneath the hood? Inverse Transform Sampling?
distributionsnumpyrandom-generation
numpy
lets you generate random samples from a beta distribution (or any other arbitrary distribution) with this API:
samples = np.random.beta(a,b, size=1000)
What is this doing beneath the hood? Inverse Transform Sampling?
Best Answer
The code for
numpy.random.beta
is found at legacy-distributions.c at the time of this writing.Notice that
numpy.random.*
functions (includingnumpy.random.beta
) became legacy functions since NumPy 1.17 introduced a new system for pseudorandom number generation (see the NumPy RNG Policy). Thus, the implementation ofnumpy.random.beta
is not expected to change for as long asnumpy.random.*
functions are still present in NumPy, and the beta generator used in the new RNG system may differ from the one presented here.In fact, at the time of this writing, the new generator is slightly different from the legacy generator (see distributions.c at the time of this writing), and one of the reasons for introducing the new RNG system is to allow the non-uniform random generators to be improved without having to maintain backward compatibility.
REFERENCES: