commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From S├ębastien Brisard (Commented) (JIRA) <>
Subject [jira] [Commented] (MATH-753) Better implementation for the gamma distribution density function
Date Sat, 25 Feb 2012 07:50:48 GMT


S├ębastien Brisard commented on MATH-753:

Thanks Francesco for reporting this issue. The fix you propose is indeed very simple. However,
we should make sure that there is no loss of accuracy for smaller values of alpha and beta.
I'd like to know what others think. Also, we are trying to stabilize version 3.0, so we do
not have much time to investigate this right now.

Two options would be possible
# wait until 3.1 to include this fix,
# include this fix right now, but keep the ticket open, in order to thoroughly investigate
accurracy issues in 3.1.
> Better implementation for the gamma distribution density function
> -----------------------------------------------------------------
>                 Key: MATH-753
>                 URL:
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.2
>            Reporter: Francesco Strino
>            Priority: Minor
>              Labels: improvement, stability
>             Fix For: 2.2
> The way the density of the gamma distribution function is estimated can be improved.
> It's much more stable to calculate first the log of the density and then exponentiate,
otherwise the function returns NaN for high values of the parameters alpha and beta. 
> It would be sufficient to change the public double density(double x) function at line
204 in the file org.apache.commons.math.distribution.GammaDistributionImpl as follows:
> return Math.exp(Math.log( x )*(alpha-1) - Math.log(beta)*alpha - x/beta - Gamma.logGamma(alpha));

> In order to improve performance, log(beta) and Gamma.logGamma(alpha) could also be precomputed
and stored during initialization.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message