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

HypergeometricDistribution logProbability() returns NaN for edge cases

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 3.0, 4.0
    • Fix Version/s: 4.0
    • Labels:
      None

      Description

      For certain edge cases, HypergeometricDistribution.logProbability() will return NaN.

      To compute the hypergeometric log probability, three binomial log probabilities are computed and then combined accordingly. The implementation is essentially the same as in BinomialDistribution.logProbability() and uses the SaddlePointExpansion. However, the Binomial implementation includes an extra check for the edge case of 0 trials which the HyperGeometric lacks.

      An example call which fails is:
      new HypergeometricDistribution(null, 11, 0, 1).logProbability(0)
      which returns NaN instead of 0.0.
      Note that
      new HypergeometricDistribution(null, 10, 0, 1).logProbability(0)
      returns 0 as expected.

      Possible fixes:
      1. Check for the edge cases and return appropriate values. This would make the code somewhat more complex.
      2. Instead of duplicating the implementation use BinomialDistribution.logProbability(). This is much simpler/more readable but will reduce performance as each call to BinomialDistribution.logProbability() makes redundant checks of validity of input parameters etc.

      I am happy to submit a PR at the GitHub repo implementing either 1 or 2 with the necessary tests.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                armanbilge Arman Bilge
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: