You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Neidhart (JIRA)" <ji...@apache.org> on 2015/11/24 00:03:11 UTC

[jira] [Commented] (MATH-1253) Skewness could get more precision from slightly reordered code.

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

Thomas Neidhart commented on MATH-1253:
---------------------------------------

just ftr: I did some tests with octave and scipy, and both return NaN or overflow for the input.

> Skewness could get more precision from slightly reordered code.
> ---------------------------------------------------------------
>
>                 Key: MATH-1253
>                 URL: https://issues.apache.org/jira/browse/MATH-1253
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.5
>            Reporter: Bill Murphy
>            Priority: Minor
>
> In Skewness.java, approx line 180, there is code like:
> {noformat}
>             double accum3 = 0.0;
>             for (int i = begin; i < begin + length; i++) {
>                 final double d = values[i] - m;
>                 accum3 += d * d * d;
>             }
>             accum3 /= variance * FastMath.sqrt(variance);
> {noformat}
> If the division was moved into the for loop, accum3 would be less likely to overflow to Infinity (or -Infinity). This might allow computation to return a result in a case such as:
> {noformat}
> double[] numArray = { 1.234E11, 1.234E51, 1.234E101, 1.234E151 };
> Skewness    skew = new Skewness();
> double    sk = skew.evaluate( numArray );
> {noformat}
> Currently, this returns NaN, but I'd prefer it returned approx 1.154700538379252.
> The change I'm proposing would have the code instead read like:
> {noformat}
>             double accum3 = 0.0;
>             double divisor = variance * FastMath.sqrt(variance);
>             for (int i = begin; i < begin + length; i++) {
>                 final double d = values[i] - m;
>                 accum3 += d * d * d / divisor;
>             }
> {noformat}
> Thanks!



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)