Preference[] prefs = theUser.getPreferencesAsArray();
RunningAverage[] averages = diffStorage.getDiffs(theUser.getID(), itemID, prefs);
for (int i = 0; i < prefs.length; i++) {
RunningAverage averageDiff = averages[i];
if (averageDiff != null) {
Preference pref = prefs[i];
double averageDiffValue = averageDiff.getAverage();
if (weighted) {
double weight = (double) averageDiff.getCount();
if (stdDevWeighted) {
double stdev = ((RunningAverageAndStdDev) averageDiff).getStandardDeviation();
if (!Double.isNaN(stdev)) {
weight /= 1.0 + stdev;
}
// If stdev is NaN, then it is because count is 1. Because we're weighting by count,
// the weight is already relatively low. We effectively assume stdev is 0.0 here and
// that is reasonable enough. Otherwise, dividing by NaN would yield a weight of NaN
// and disqualify this pref entirely
// (Thanks Daemmon)
}
totalPreference += weight * (pref.getValue() + averageDiffValue);
count += weight;
} else {
totalPreference += pref.getValue() + averageDiffValue;
count += 1.0;
}
}
}
if (count <= 0.0) {