commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r522305 - /jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java
Date Sun, 25 Mar 2007 17:26:35 GMT
Author: psteitz
Date: Sun Mar 25 10:26:35 2007
New Revision: 522305

URL: http://svn.apache.org/viewvc?view=rev&rev=522305
Log:
Improved efficiency of evaluate method.

Modified:
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java?view=diff&rev=522305&r1=522304&r2=522305
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java
(original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java
Sun Mar 25 10:26:35 2007
@@ -255,17 +255,18 @@
                 var = 0.0;
             } else if (length > 1) {
                 double accum = 0.0;
+                double dev = 0.0;
                 double accum2 = 0.0;
                 for (int i = begin; i < begin + length; i++) {
-                    accum += Math.pow((values[i] - mean), 2.0);
-                    accum2 += (values[i] - mean);
+                    dev = values[i] - mean;
+                    accum += dev * dev;
+                    accum2 += dev;
                 }
+                double len = (double) length;            
                 if (isBiasCorrected) {
-                    var = (accum - (Math.pow(accum2, 2) / ((double) length))) /
-                    (double) (length - 1);
+                    var = (accum - (accum2 * accum2 / len)) / (len - 1.0);
                 } else {
-                    var = (accum - (Math.pow(accum2, 2) / ((double) length))) /
-                    (double) length;
+                    var = (accum - (accum2 * accum2 / len)) / len;
                 }
             }
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message