ground- water, geo- statistics, environmental- engineering, earth- science

Gamma Function in Scipy.Special

with 4 comments

I was playing with the Gamma Distribution Function in python. As typically, I used a combination of bumpy numpy arrays and the scipy.special functions for Gamma and incomplete gamma functions. At one point I realized that the Gamma distribution function (bottom panel on the figure below) was not reaching unity for large x values and for some parameters (k=0.63, theta=0.05). In the given case, the deviation was about 0.3 in probability space, which is significant.

Note: The Gamma Distribution Function (its cdf or pdf) is not the same thing as the Gamma function!

The solution I came up with is to use the module mpmath. When I do, everything looks fine.

I googled only briefly, but did not find any description of this error in scipy.special. Also I am not sure, if using mpmath is the best/fastest/most elegant solution. However, at least it seems to work.

density and distribution of the gamma function

Written by Claus

August 19th, 2013 at 3:05 pm

Posted in