Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-753

Better implementation for the gamma distribution density function

Rank to TopRank to BottomBulk Copy AttachmentsBulk Move AttachmentsVotersWatch issueWatchersConvert to sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.2, 3.0, 3.1
    • 3.1

    Description

      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.

      Attachments

        1. lanczos.patch
          2 kB
          Sebastien Brisard
        2. MATH-753.tar.gz
          303 kB
          Sebastien Brisard

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            celestin Sebastien Brisard
            fra Francesco Strino
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment