You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Bill Murphy (JIRA)" <ji...@apache.org> on 2015/08/04 00:33:05 UTC

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

Bill Murphy created MATH-1253:
---------------------------------

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