commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles (JIRA)" <>
Subject [jira] [Updated] (MATH-1146) class Mean returns incorrect result after processing an Infinity value
Date Sat, 16 Aug 2014 01:41:18 GMT


Gilles updated MATH-1146:

    Attachment: MATH-1146.patch

Here is a tentative patch which I thought would solve the problem.
However, it makes another unit test fail.

Tests run: 5, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec <<< FAILURE!
- in org.apache.commons.math3.stat.descriptive.AggregateSummaryStatisticsTest            
 Time elapsed: 0.001 sec  <<< FAILURE!                  
java.lang.AssertionError: expected:<Infinity> but was:<NaN>                  
        at org.junit.Assert.failNotEquals(                               
        at org.junit.Assert.assertEquals(                                
        at org.apache.commons.math3.TestUtils.assertEquals(            
        at org.apache.commons.math3.stat.descriptive.AggregateSummaryStatisticsTest.assertEquals(
        at org.apache.commons.math3.stat.descriptive.AggregateSummaryStatisticsTest.testAggregateSpecialValues(

> class Mean returns incorrect result after processing an Infinity value
> ----------------------------------------------------------------------
>                 Key: MATH-1146
>                 URL:
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.3
>            Reporter: david cogen
>         Attachments: MATH-1146.patch
> 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.

This message was sent by Atlassian JIRA

View raw message