commons-issues mailing list archives

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

    [ https://issues.apache.org/jira/browse/MATH-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14099667#comment-14099667
] 

Gilles commented on MATH-1146:
------------------------------

By "policy" here, I don't mean best coding practices (which includes good documentation).
But rather, can we state a general policy on handling special values instead of repeating
all over the place (and forgetting to do so) that results could be garbage if NaN or infinities
are involved?
There are several places in CM where the implementations do not behave as one would expect
from the plain math definition, and it has led to bug reports (recall e.g. "Complex"). I don't
dispute that there may be good reasons, and that the doc may state it clearly enough (although
I don't think it that the doc should contain what could be deemed an implementation detail,
such as the actual computation used to maintain the mean); I find it preferrable to state
once and for all that if users want to manipulate NaN and infinities, they should not expect
that CM will deliver correct results. The rationale being:
bq. \[CM is\] designed for fast, accurate computations \[... and\] we do not add a performance
hit for users with standard (non NaN, non-Inf) data \[... in order to\] return meaningful
results in the presence of INFs.
which is a quite well stated and perfectly acceptable policy IMO.



> class Mean returns incorrect result after processing an Infinity value
> ----------------------------------------------------------------------
>
>                 Key: MATH-1146
>                 URL: https://issues.apache.org/jira/browse/MATH-1146
>             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
(v6.2#6252)

Mime
View raw message