skypy icon indicating copy to clipboard operation
skypy copied to clipboard

Improve Schechter function sampling

Open ntessore opened this issue 4 years ago • 0 comments

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 current upper_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 for gammaincc that works for negative indices makes numerically integrating the CDF unnecessary. This allows us to get rid of the resolution argument, and have the option of sampling without upper limit, which is usually what's wanted, since the tail is exponentially suppressed anyway.

ntessore avatar Apr 19 '20 23:04 ntessore