mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r773386 - in /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender: BooleanUserGenericUserBasedRecommender.java GenericUserBasedRecommender.java
Date Sun, 10 May 2009 19:13:38 GMT
Author: srowen
Date: Sun May 10 19:13:37 2009
New Revision: 773386

URL: http://svn.apache.org/viewvc?rev=773386&view=rev
Log:
Removed unneeded check for NaN and further rationalized behavior of 'estimated preference'
in BooleanUserGenericUserBasedRecommender

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BooleanUserGenericUserBasedRecommender.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BooleanUserGenericUserBasedRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BooleanUserGenericUserBasedRecommender.java?rev=773386&r1=773385&r2=773386&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BooleanUserGenericUserBasedRecommender.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BooleanUserGenericUserBasedRecommender.java
Sun May 10 19:13:37 2009
@@ -171,25 +171,30 @@
     return TopItems.getTopUsers(howMany, allUsers, null, estimator);
   }
 
+  /**
+   * This computation is in a technical sense, wrong, since in the domain of "boolean preference
users"
+   * where all preference values are 1, this method should only ever return 1.0 or NaN. This
isn't
+   * terribly useful however since it means results can't be ranked by preference value (all
are 1).
+   * So instead this returns a sum of similarties to any other user in the neighborhood who
has also
+   * rated the item.
+   */
   private double doEstimatePreference(User theUser, Collection<User> theNeighborhood,
Object itemID)
           throws TasteException {
     if (theNeighborhood.isEmpty()) {
       return Double.NaN;
     }
     double totalSimilarity = 0.0;
+    boolean foundAPref = false;
     for (User user : theNeighborhood) {
       if (!user.equals(theUser)) {
         // See GenericItemBasedRecommender.doEstimatePreference() too
-        Preference pref = user.getPreferenceFor(itemID);
-        if (pref != null) {
-          double theSimilarity = similarity.userSimilarity(theUser, user) + 1.0;
-          if (!Double.isNaN(theSimilarity)) {
-            totalSimilarity += theSimilarity;
-          }
+        if (user.getPreferenceFor(itemID) != null) {
+          foundAPref = true;
+          totalSimilarity += similarity.userSimilarity(theUser, user);
         }
       }
     }
-    return totalSimilarity == 0.0 ? Double.NaN : totalSimilarity;
+    return foundAPref ? totalSimilarity : 0.0;
   }
 
   private static Set<Object> getAllOtherItems(Iterable<User> theNeighborhood,
User theUser) {

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java?rev=773386&r1=773385&r2=773386&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java
Sun May 10 19:13:37 2009
@@ -144,10 +144,11 @@
         Preference pref = user.getPreferenceFor(item.getID());
         if (pref != null) {
           double theSimilarity = similarity.userSimilarity(theUser, user) + 1.0;
-          if (!Double.isNaN(theSimilarity)) {
-            preference += theSimilarity * pref.getValue();
-            totalSimilarity += theSimilarity;
-          }
+          // Similarity should not be NaN or else the user should never have showed up
+          // in the neighborhood. Adding 1.0 puts this in the range [0,2] which is
+          // more appropriate for weights
+          preference += theSimilarity * pref.getValue();
+          totalSimilarity += theSimilarity;
         }
       }
     }



Mime
View raw message