private double doItemSimilarity(long itemID1, long itemID2, FastIDSet preferring1) throws TasteException { double intersection = 0.0; double union = 0.0; for (Preference pref : getDataModel().getPreferencesForItem(itemID2)) { long userID = pref.getUserID(); double weight = (double) getDataModel().getNumItems() / mUserPrefNum.get(userID); if (preferring1.contains(userID)) { intersection += weight; union -= weight; } union += weight; } for (LongPrimitiveIterator it_user = preferring1.iterator(); it_user.hasNext(); ) { long userID = (long) it_user.nextLong(); double weight = (double) getDataModel().getNumItems() / mUserPrefNum.get(userID); union += weight; } if (intersection == 0) { return Double.NaN; } return Math.log(intersection) / Math.log(union); }
private FastIDSet toUserFastIDSet(PreferenceArray array) { FastIDSet fastIDSet = new FastIDSet(); for (Preference preference : array) { fastIDSet.add(preference.getUserID()); } return fastIDSet; }