skypy
skypy copied to clipboard
Improve Schechter function sampling
I am working on a number of fixes for the Schechter function sampling as currently implemented.
-
Improved
gammaincc
that works for all negative indices. The currentupper_incomplete_gamma
quickly breaks, which is a problem when e.g. halo masses need to be sampled from the generalised Schechter function:>>> from skypy.utils.special import upper_incomplete_gamma >>> upper_incomplete_gamma(-0.2, 1.0) # 0.201155 0.20115548418183707 >>> upper_incomplete_gamma(-1.2, 0.5) # 0.138937 nan
The algorithm I originally proposed is also rather wasteful in that it requires special functions in each iteration.
-
Inverse function
gammainccinv
for negative indices. A direct inverse function forgammaincc
that works for negative indices makes numerically integrating the CDF unnecessary. This allows us to get rid of theresolution
argument, and have the option of sampling without upper limit, which is usually what's wanted, since the tail is exponentially suppressed anyway.