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

Bill Murphy commented on MATH-1253:
-----------------------------------

I agree with Otmar's comments entirely.

I do not yet know a better suggestion. Even a slight extension of the range of 
correct results seems to me to be an improvement. I would still prefer going 
forwards with these mods as suggested, but a true fix as outlined by Otmar 
would be hugely better. Does someone else know enough numerical analysis stuff 
to provide a mostly-correct approximation over the range of doubles? It is 
sadly beyond me as of today.


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

Reply via email to