diff --git a/nonpers-assignment/src/main/java/org/lenskit/mooc/nonpers/assoc/BasicAssociationModelProvider.java b/nonpers-assignment/src/main/java/org/lenskit/mooc/nonpers/assoc/BasicAssociationModelProvider.java index 415941b..190eda7 100644 --- a/nonpers-assignment/src/main/java/org/lenskit/mooc/nonpers/assoc/BasicAssociationModelProvider.java +++ b/nonpers-assignment/src/main/java/org/lenskit/mooc/nonpers/assoc/BasicAssociationModelProvider.java @@ -62,6 +62,7 @@ public class BasicAssociationModelProvider implements Provider for (Long2ObjectMap.Entry xEntry: itemUsers.long2ObjectEntrySet()) { long xId = xEntry.getLongKey(); LongSortedSet xUsers = xEntry.getValue(); + HashSet xSet = new HashSet(xUsers); // set up a map to hold the scores for each 'y' item for this 'x' Long2DoubleMap itemScores = new Long2DoubleOpenHashMap(); @@ -72,9 +73,9 @@ public class BasicAssociationModelProvider implements Provider LongSortedSet yUsers = yEntry.getValue(); // TODO Compute P(Y & X) / P(X) and store in itemScores - HashSet ySet = new HashSet(yUsers), xSet = new HashSet(xUsers); + HashSet ySet = new HashSet(yUsers); ySet.retainAll(xSet); - double p = ySet.size() / xSet.size(); + double p = 1.0 * ySet.size() / xUsers.size(); itemScores.put(yId, p); }