Improved efficiency of evaluate method.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@522305 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
35af6fe1d2
commit
cc6c1f22e9
|
@ -255,17 +255,18 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
||||||
var = 0.0;
|
var = 0.0;
|
||||||
} else if (length > 1) {
|
} else if (length > 1) {
|
||||||
double accum = 0.0;
|
double accum = 0.0;
|
||||||
|
double dev = 0.0;
|
||||||
double accum2 = 0.0;
|
double accum2 = 0.0;
|
||||||
for (int i = begin; i < begin + length; i++) {
|
for (int i = begin; i < begin + length; i++) {
|
||||||
accum += Math.pow((values[i] - mean), 2.0);
|
dev = values[i] - mean;
|
||||||
accum2 += (values[i] - mean);
|
accum += dev * dev;
|
||||||
|
accum2 += dev;
|
||||||
}
|
}
|
||||||
|
double len = (double) length;
|
||||||
if (isBiasCorrected) {
|
if (isBiasCorrected) {
|
||||||
var = (accum - (Math.pow(accum2, 2) / ((double) length))) /
|
var = (accum - (accum2 * accum2 / len)) / (len - 1.0);
|
||||||
(double) (length - 1);
|
|
||||||
} else {
|
} else {
|
||||||
var = (accum - (Math.pow(accum2, 2) / ((double) length))) /
|
var = (accum - (accum2 * accum2 / len)) / len;
|
||||||
(double) length;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue