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

class Mean returns incorrect result after processing an Infinity value

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.3
    • Fix Version/s: 3.4
    • Labels:
      None

      Description

      1. Create a Mean object.
      2. call increment() with Double.POSITIVE_INFINITY.
      3. Call getResult(). Result is INFINITY as expected.
      4. call increment() with 0.
      5. Call getResult(). Result is NaN; not INFINITY as expected.

      This is apparently due to the "optimization" for calculating mean described in the javadoc. Rather than accumulating a sum, it maintains a running mean value using the formula "m = m + (new value - m) / (number of observations)", which unlike the "definition way", fails after an infinity.

      I was using Mean within a SummaryStatistics. Other statistics also seem to be affected; for example, the standard deviation also incorrectly gives NaN rather than Infinity. I don't know if that's due to the error in Mean or if the other stats classes have similar bugs.

        Attachments

        1. MATH-1146.patch
          4 kB
          Gilles Sadowski

          Activity

            People

            • Assignee:
              psteitz Phil Steitz
              Reporter:
              cogen david cogen
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: