You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Roman Werpachowski (JIRA)" <ji...@apache.org> on 2010/06/07 16:55:44 UTC

[jira] Created: (MATH-373) StatUtils.sum returns NaN for zero-length arrays

StatUtils.sum returns NaN for zero-length arrays
------------------------------------------------

                 Key: MATH-373
                 URL: https://issues.apache.org/jira/browse/MATH-373
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 2.1
            Reporter: Roman Werpachowski


StatUtils.sum returns NaN for zero-length arrays, which is:

1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity

sum_{i=0}^{k-1} a_i + sum_{i=k}^{N-1} = sum_{i=0}^{N-1}

is broken for k = 0, since NaN + x = NaN, not x.

2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)

3. enforces "special case" handling when the user expects that the summed array can have a zero length.

The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-373) StatUtils.sum returns NaN for zero-length arrays

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12877784#action_12877784 ] 

Sebb commented on MATH-373:
---------------------------

Possibly crazy idea: 

if Math 3.0 is going to change package names (which may be necessary), one could introduce the fix using a math3 package name?

> StatUtils.sum returns NaN for zero-length arrays
> ------------------------------------------------
>
>                 Key: MATH-373
>                 URL: https://issues.apache.org/jira/browse/MATH-373
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Roman Werpachowski
>             Fix For: 3.0
>
>
> StatUtils.sum returns NaN for zero-length arrays, which is:
> 1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity
> sum_{i=0}^{k-1} a_i + sum_{i=k}^{N-1} = sum_{i=0}^{N-1}
> is broken for k = 0, since NaN + x = NaN, not x.
> 2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)
> 3. enforces "special case" handling when the user expects that the summed array can have a zero length.
> The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-373) StatUtils.sum returns NaN for zero-length arrays

Posted by "Bill Barker (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12878204#action_12878204 ] 

Bill Barker commented on MATH-373:
----------------------------------

As Gilles mentioned, changing the package name for commons-math was discussed and voted on for 2.x.  The result of the vote was to keep the package name, since commons-math won't usually be provided by a third party library.  Since nothing much has changed, I can't see that commons-math would change it's package for version 3.0.

> StatUtils.sum returns NaN for zero-length arrays
> ------------------------------------------------
>
>                 Key: MATH-373
>                 URL: https://issues.apache.org/jira/browse/MATH-373
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Roman Werpachowski
>             Fix For: 3.0
>
>
> StatUtils.sum returns NaN for zero-length arrays, which is:
> 1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity
> sum_{i=0}^{k-1} a_i + sum_{i=k}^{N-1} = sum_{i=0}^{N-1}
> is broken for k = 0, since NaN + x = NaN, not x.
> 2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)
> 3. enforces "special case" handling when the user expects that the summed array can have a zero length.
> The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (MATH-373) StatUtils.sum returns NaN for zero-length arrays

Posted by "Bill Barker (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bill Barker updated MATH-373:
-----------------------------

    Fix Version/s: 3.0

The consensus of the commons-math developers is that, since the current behavior is documented in 2.x, that this will have to wait for 3.0.  Fixing this would introduce a too large incompatibility change to include in 2.x.

I can attach a patch against 2.x that fixes this, as long as anybody using the patch understands that it isn't supported.



> StatUtils.sum returns NaN for zero-length arrays
> ------------------------------------------------
>
>                 Key: MATH-373
>                 URL: https://issues.apache.org/jira/browse/MATH-373
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Roman Werpachowski
>             Fix For: 3.0
>
>
> StatUtils.sum returns NaN for zero-length arrays, which is:
> 1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity
> sum_{i=0}^{k-1} a_i + sum_{i=k}^{N-1} = sum_{i=0}^{N-1}
> is broken for k = 0, since NaN + x = NaN, not x.
> 2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)
> 3. enforces "special case" handling when the user expects that the summed array can have a zero length.
> The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (MATH-373) StatUtils.sum returns NaN for zero-length arrays

Posted by "Bill Barker (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12877689#action_12877689 ] 

Bill Barker edited comment on MATH-373 at 6/10/10 10:58 PM:
------------------------------------------------------------

The consensus of the commons-math developers is that, since the current behavior is documented in 2.x, that this will have to wait for 3.0.  Fixing this in 2.x would introduce a too large incompatibility change to include in 2.x.

I can attach a patch against 2.x that fixes this, as long as anybody using the patch understands that it isn't supported.



      was (Author: billbarker):
    The consensus of the commons-math developers is that, since the current behavior is documented in 2.x, that this will have to wait for 3.0.  Fixing this would introduce a too large incompatibility change to include in 2.x.

I can attach a patch against 2.x that fixes this, as long as anybody using the patch understands that it isn't supported.


  
> StatUtils.sum returns NaN for zero-length arrays
> ------------------------------------------------
>
>                 Key: MATH-373
>                 URL: https://issues.apache.org/jira/browse/MATH-373
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Roman Werpachowski
>             Fix For: 3.0
>
>
> StatUtils.sum returns NaN for zero-length arrays, which is:
> 1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity
> sum_{i=0}^{k-1} a_i + sum_{i=k}^{N-1} = sum_{i=0}^{N-1}
> is broken for k = 0, since NaN + x = NaN, not x.
> 2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)
> 3. enforces "special case" handling when the user expects that the summed array can have a zero length.
> The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-373) StatUtils.sum returns NaN for zero-length arrays

Posted by "Roman Werpachowski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12877807#action_12877807 ] 

Roman Werpachowski commented on MATH-373:
-----------------------------------------

Speaking as a maintainer of client code which uses ACM, I'd rather cope with occasional incompatibilities in the same packages, than have to change ALL my client code to keep up with the package name changes after every release. A reason to change the package name would be if you wanted to use the old and new version side by side, but that would not be a common usage pattern for ACM, I think.

> StatUtils.sum returns NaN for zero-length arrays
> ------------------------------------------------
>
>                 Key: MATH-373
>                 URL: https://issues.apache.org/jira/browse/MATH-373
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Roman Werpachowski
>             Fix For: 3.0
>
>
> StatUtils.sum returns NaN for zero-length arrays, which is:
> 1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity
> sum_{i=0}^{k-1} a_i + sum_{i=k}^{N-1} = sum_{i=0}^{N-1}
> is broken for k = 0, since NaN + x = NaN, not x.
> 2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)
> 3. enforces "special case" handling when the user expects that the summed array can have a zero length.
> The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-373) StatUtils.sum returns NaN for zero-length arrays

Posted by "Bill Barker (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12876512#action_12876512 ] 

Bill Barker commented on MATH-373:
----------------------------------

I agree with the reasoning here, and we should do it this way in 3.0.  However it is an incompatible change to do in a point release, so I'm going to wait for more feed back from other developers before I make any changes to the current code.

I'm thinking that adding a method to AbstractUnivariateStatistic that looks like:
   protected boolean test( final double[] values,  final int begin,   final int length, final boolean allowEmpty)

that would have the test:
   if(length == 0 && !allowEmpty)
        return false;

The current test method can call the new one with allowEmpty=false for backwards compatibility.  Then we can decide on which statistics should have a zero value on the empty set.


> StatUtils.sum returns NaN for zero-length arrays
> ------------------------------------------------
>
>                 Key: MATH-373
>                 URL: https://issues.apache.org/jira/browse/MATH-373
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Roman Werpachowski
>
> StatUtils.sum returns NaN for zero-length arrays, which is:
> 1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity
> sum_{i=0}^{k-1} a_i + sum_{i=k}^{N-1} = sum_{i=0}^{N-1}
> is broken for k = 0, since NaN + x = NaN, not x.
> 2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)
> 3. enforces "special case" handling when the user expects that the summed array can have a zero length.
> The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-373) StatUtils.sum returns NaN for zero-length arrays

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12877803#action_12877803 ] 

Gilles commented on MATH-373:
-----------------------------

IIRC, changing the package name had been suggested and discussed for 2.0.
[One argument is that, to be consistent,  you'd have to change the name at every major release...]


> StatUtils.sum returns NaN for zero-length arrays
> ------------------------------------------------
>
>                 Key: MATH-373
>                 URL: https://issues.apache.org/jira/browse/MATH-373
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Roman Werpachowski
>             Fix For: 3.0
>
>
> StatUtils.sum returns NaN for zero-length arrays, which is:
> 1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity
> sum_{i=0}^{k-1} a_i + sum_{i=k}^{N-1} = sum_{i=0}^{N-1}
> is broken for k = 0, since NaN + x = NaN, not x.
> 2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)
> 3. enforces "special case" handling when the user expects that the summed array can have a zero length.
> The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (MATH-373) StatUtils.sum returns NaN for zero-length arrays

Posted by "Bill Barker (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bill Barker resolved MATH-373.
------------------------------

    Resolution: Fixed

This will be fixed in the 3.0 build.

> StatUtils.sum returns NaN for zero-length arrays
> ------------------------------------------------
>
>                 Key: MATH-373
>                 URL: https://issues.apache.org/jira/browse/MATH-373
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Roman Werpachowski
>             Fix For: 3.0
>
>
> StatUtils.sum returns NaN for zero-length arrays, which is:
> 1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N-1} a_i will be 0 for N=0. In particular, the identity
> sum_{i=0}^{k-1} a_i + sum_{i=k}^{N-1} = sum_{i=0}^{N-1}
> is broken for k = 0, since NaN + x = NaN, not x.
> 2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting an exceptional condition, as NaNs propagate silently and require manual tracing during the debugging)
> 3. enforces "special case" handling when the user expects that the summed array can have a zero length.
> The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.