You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2004/07/05 00:06:07 UTC
cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment Kurtosis.java
psteitz 2004/07/04 15:06:07
Modified: math/src/java/org/apache/commons/math/stat/univariate/moment
Kurtosis.java
Log:
Changed evaluate method to use embedded moments instead of duplicating code.
Revision Changes Path
1.26 +9 -21 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java
Index: Kurtosis.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Kurtosis.java 4 Jul 2004 09:02:36 -0000 1.25
+++ Kurtosis.java 4 Jul 2004 22:06:07 -0000 1.26
@@ -145,30 +145,19 @@
// Initialize the kurtosis
double kurt = Double.NaN;
- if (test(values, begin, length) && length > 3) {
- Mean mean = new Mean();
- // Get the mean and the standard deviation
- double m = mean.evaluate(values, begin, length);
+ if (test(values, begin, length) && length > 3) {
- // Calc the std, this is implemented here instead
- // of using the standardDeviation method eliminate
- // a duplicate pass to get the mean
- double accum = 0.0;
- double accum2 = 0.0;
- for (int i = begin; i < begin + length; i++) {
- accum += Math.pow((values[i] - m), 2.0);
- accum2 += (values[i] - m);
- }
-
- double stdDev =Math.sqrt(
- (accum - (Math.pow(accum2, 2) / ((double) length))) /
- (double) (length - 1));
+ // Compute the mean and standard deviation
+ Variance variance = new Variance();
+ variance.incrementAll(values, begin, length);
+ double mean = variance.moment.m1;
+ double stdDev = Math.sqrt(variance.getResult());
// Sum the ^4 of the distance from the mean divided by the
// standard deviation
double accum3 = 0.0;
for (int i = begin; i < begin + length; i++) {
- accum3 += Math.pow((values[i] - m), 4.0);
+ accum3 += Math.pow((values[i] - mean), 4.0);
}
accum3 /= Math.pow(stdDev, 4.0d);
@@ -182,8 +171,7 @@
// Calculate kurtosis
kurt = (coefficientOne * accum3) - termTwo;
- }
-
+ }
return kurt;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org