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

Phil Steitz commented on MATH-1146:
-----------------------------------

I am fine with stating the general policy that NaNs and infinities are not 
specially handled by commons math.  I think documenting algorithms is 
important, though, and I will continue to do it where I can.   Most of what we 
do amounts to providing numerical approximations of mathematically defined 
quantities.  The numerical algorithms used in the approximation are part of the 
API contract, IMO, as it is their results that we are returning.   I see no 
harm in pointing out where possible what happens when infinities or NaNs are 
included in user-supplied data.  I think there are a few cases where we filter 
/ specially handle these values today.  I am OK agreeing to change this 
behavior, but we should talk about it on the dev list and target a major 
release to implement these API changes.

Back to this issue - I think the right resolution is to edit javadoc to make 
clear how NaNs and infinities impact the mean computation.  Same for other 
stats mentioned in this ticket.

> 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)

Reply via email to