简体   繁体   中英

High exponent numbers with scipy.stats functions

I have a set of number that can get very small, from 1e-100 , to 1e-700 and lower. The precision doesn't matter as much as the exponent. I can load such numbers just fine using Pandas by simply providing Decimal as a converter for all such numeric columns.

The problem is, even if I use Python's Decimal , I just can't use scipy.stats.chi2.isf and similar functions since their C code explicitly uses double . A possible workaround is that I can use log10 of the numbers. The problem here is that although there is logsf function, for chi2 it's implemented as just log(sf(...)) , and will, therefore, fail when sf returns 0 where it should've returned something like 1e-600 . And for isf there is no such log function at all.

I wanted to know if there is any way to work with such numbers without resolving to writing all these functions myself for Decimal.

You could just write the expression for logsf directly using logs of gamma functions from scipy.special (gammaln, loggamma). And you could send a pull request implementing the logsf for the chi-square distribution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM