Fixed incorrect type spec, simplified references.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@764211 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2009-04-11 15:57:03 +00:00
parent d271b3132c
commit 53b912cb49

View File

@ -187,11 +187,11 @@ public class Covariance {
throws IllegalArgumentException { throws IllegalArgumentException {
Mean mean = new Mean(); Mean mean = new Mean();
double result = 0d; double result = 0d;
long length = xArray.length; int length = xArray.length;
if(length == yArray.length && length > 1) { if(length == yArray.length && length > 1) {
double xMean = mean.evaluate(xArray); double xMean = mean.evaluate(xArray);
double yMean = mean.evaluate(yArray); double yMean = mean.evaluate(yArray);
for (int i = 0; i < xArray.length; i++) { for (int i = 0; i < length; i++) {
double xDev = xArray[i] - xMean; double xDev = xArray[i] - xMean;
double yDev = yArray[i] - yMean; double yDev = yArray[i] - yMean;
result += (xDev * yDev - result) / (i + 1); result += (xDev * yDev - result) / (i + 1);
@ -201,7 +201,7 @@ public class Covariance {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"arrays must have the same length and both must have at " + "arrays must have the same length and both must have at " +
"least two elements. xArray has size {0}, yArray has {1} elements", "least two elements. xArray has size {0}, yArray has {1} elements",
xArray.length, yArray.length); length, yArray.length);
} }
return biasCorrected ? result * ((double) length / (double)(length - 1)) : result; return biasCorrected ? result * ((double) length / (double)(length - 1)) : result;
} }