Estimate ratio of two gamma functions when individual functions return inf value

主宰稳场 提交于 2019-12-11 03:49:49

问题


I'm estimating the ratio of two gamma functions. Both estimates for gamma(x) and gamma(y) are very large ( > 10^300) but the ratio of the two should be fairly small.

from scipy.special import gamma
gamma(x) / gamma(y)

Unfortunately, there is a point where gamma(x) is too large and the scipy returns an inf value. Is there a way to stop this, increase the threshold, or alternatively calculate this ratio?

Thanks


回答1:


Assuming x and y are real and positive you can use the following identity:

a / b = e^(ln(a) - ln(b))

I can suggest using gmpy2 for the arbitrary precision calculation. It has gmpy2.lgamma, which returns the logarithm of the gamma function, and you can use gmpy2.exp to convert from the logarithm form to your desired ratio.



来源:https://stackoverflow.com/questions/32507510/estimate-ratio-of-two-gamma-functions-when-individual-functions-return-inf-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!