ism3d.maths.stats.custom_rvs

ism3d.maths.stats.custom_rvs(func, size=100000, scale=1.0, interp=0.02, 20, sersic_n=1, seed=None)[source]

https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.random.RandomState.html#numpy.random.RandomState use_nprng==True:

use np built-in random generator rather than the hardcoded uniform+its formula

more ppf rvs can be found here:

https://github.com/scipy/scipy/blob/master/scipy/stats/_continuous_distns.py scipy try to use special.fun as much as possible due to performance gain

performance:

scipy.stats.rvs is generally slowest as the wrapper A Good in-line ITS is usually fast and comparable to rng.dist (which still use C underhood)

rvs=

When size is large, the ppf calculation can slow down the ITS (ur->x); If interp is specificed as a two-element tuple, we will use the pre-calculated ur->x table to performance the transform interp=(a,b) ; (a,b) determined the random variable PDF accuracy, in units of “scale”

a: resolution (so the uncernraiy in x should be smaller than a*scale b: beyond b*scale, the transform is truncated and we lost the PDF accuracy in the random variable.

smaller a or large b will increase the computation time.

if interp is None then, the custom_ppf method is used and the compulation time will incrase with size=1.0 if interp is set as default, the computing time will flatten at some point as size increase.

When using interp for inverse transformation, the better accurate in x within a limit dynamical range setting is determined by which part of sampling table is usable for interpolation. For oneside or twoside function, this is typically x-SF as saving numerican value SF can catpture x change at large x (with close to zero SF) with good enough precsion.

note: np.interp(x,xp,xf) works faster if x is sorted; however, there is cost of sorting random number

the bottleneck is here is still np.interp() https://github.com/numpy/numpy/issues/10937

func: string / built-in function formula
dict / {‘x’:x,’cdf’:cdf} cdf-x is the CDF function

{‘y’:y,’sf’:sf} sf-x is the surveve function

this feature is used for the case where the PPF is not analytical for the distribution