ism3d.maths.stats.custom_sf

ism3d.maths.stats.custom_sf(func, x, sersic_n=1)[source]

The relation between x and q (i.e. CDF) is used to transfer uniform standard random variables to the desired sampling for a specified PDF. If .ppf can be writtten in analytical forms, we can call funtions to directly calculate. However, if special functions are involved, the computation cost can be high and an pre-calculated transform table can be used.

To Keep numerical precision and meet the sampling gridding error requirementaion (that is the sampling transfer error in X_{i} is smaller than pixel size / bin size. It’s easier to build the table from a regular oversamped grid in x, then calculate the crosspoding p value (within 0~1). Of course the regular oversamped x value can not go to +finity, and an upper limit should be given:

e.g. x_grid=np.linspace(0,100,10000) may be good enought for “expon2d”,

this means the transfered x from interpolated should have error(x)<=0.01Re (as we use linear interp to replace the actual curve), withinin 100Re (more than enought for our modeling accuray)

However, another numerical problem may occare as large x may lead to very close to 1 in this case, and numercial

accurcy may degrade lead to 1: see: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html note on _logsf and the test_custom_ppf_learn(): x=100 will lead to q=1 rather than something cose to zero.

The solution is calculate sf=1-q=1-CDF or logsf=log(1-q)=log(1-CDF); then the small deviation from 1 can still be acturrately represented numerically. And we can use x vs. logsf table to transfer ur to x-domain acurrate enought for gridding purpose

The computer is good at saving small number close to zero rather than a number very close to one.

https://scicomp.stackexchange.com/questions/20629/when-should-log1p-and-expm1-be-used

note: the interplation method is only used for the transform in which the calculatione becomes to expensive

The inverse function x=isf(sf):

if sf is a uniform (0-1) random variable, then x should follow the desired distribution

use sf instead of CDF is for numerical precsion purpose.

We only use this to build interpolation table for expensive case; so only func=’expon2d’ & ‘sersic2d’ are implemented.