if (xPrefs.length == 0 || yPrefs.length == 0) {
return Double.NaN;
}
Preference xPref = xPrefs[0];
Preference yPref = yPrefs[0];
Item xIndex = xPref.getItem();
Item yIndex = yPref.getItem();
int xPrefIndex = 1;
int yPrefIndex = 1;
double sumX = 0.0;
double sumX2 = 0.0;
double sumY = 0.0;
double sumY2 = 0.0;
double sumXY = 0.0;
double sumXYdiff2 = 0.0;
int count = 0;
boolean hasInferrer = inferrer != null;
boolean hasPrefTransform = prefTransform != null;
while (true) {
int compare = xIndex.compareTo(yIndex);
if (hasInferrer || compare == 0) {
double x;
double y;
if (compare == 0) {
// Both users expressed a preference for the item
if (hasPrefTransform) {
x = prefTransform.getTransformedValue(xPref);
y = prefTransform.getTransformedValue(yPref);
} else {
x = xPref.getValue();
y = yPref.getValue();
}
} else {
// Only one user expressed a preference, but infer the other one's preference and tally
// as if the other user expressed that preference
if (compare < 0) {
// X has a value; infer Y's
x = hasPrefTransform ? prefTransform.getTransformedValue(xPref) : xPref.getValue();
y = inferrer.inferPreference(user2, xIndex);
} else {
// compare > 0
// Y has a value; infer X's
x = inferrer.inferPreference(user1, yIndex);
y = hasPrefTransform ? prefTransform.getTransformedValue(yPref) : yPref.getValue();
}
}
sumXY += x * y;
sumX += x;
sumX2 += x * x;
sumY += y;
sumY2 += y * y;
double diff = x - y;
sumXYdiff2 += diff * diff;
count++;
}
if (compare <= 0) {
if (xPrefIndex == xPrefs.length) {
break;
}
xPref = xPrefs[xPrefIndex++];
xIndex = xPref.getItem();
}
if (compare >= 0) {
if (yPrefIndex == yPrefs.length) {
break;
}
yPref = yPrefs[yPrefIndex++];
yIndex = yPref.getItem();
}
}
// "Center" the data. If my math is correct, this'll do it.
double n = (double) count;