mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r773799 - in /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl: common/FastSet.java model/file/FileDataModel.java similarity/BooleanTanimotoCoefficientSimilarity.java
Date Tue, 12 May 2009 06:25:02 GMT
Author: srowen
Date: Tue May 12 06:25:02 2009
New Revision: 773799

URL: http://svn.apache.org/viewvc?rev=773799&view=rev
Log:
Tiny attempts to squeeze out more performance in critical blocks

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastSet.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/BooleanTanimotoCoefficientSimilarity.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastSet.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastSet.java?rev=773799&r1=773798&r2=773799&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastSet.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastSet.java
Tue May 12 06:25:02 2009
@@ -272,8 +272,7 @@
   @SuppressWarnings("unchecked")  
   public int intersectionSize(FastSet<?> other) {
     int count = 0;
-    K[] otherKeys = (K[]) other.keys;
-    for (K key : otherKeys) {
+    for (K key : (K[]) other.keys) {
       if (key != null && key != REMOVED && keys[find(key)] != null) {
         count++;
       }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java?rev=773799&r1=773798&r2=773799&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
Tue May 12 06:25:02 2009
@@ -211,10 +211,10 @@
    */
   protected void processLine(String line, Map<String, List<Preference>> data,
Map<String, Item> itemCache) {
     int delimiterOne = line.indexOf((int) delimiter);
-    int delimiterTwo = line.indexOf((int) delimiter, delimiterOne + 1);
     if (delimiterOne < 0) {
       throw new IllegalArgumentException("Bad line: " + line);
     }
+    int delimiterTwo = line.indexOf((int) delimiter, delimiterOne + 1);
 
     String userID = line.substring(0, delimiterOne);
     String itemID;
@@ -249,9 +249,6 @@
         item = buildItem(itemID);
         itemCache.put(itemID, item);
       }
-      if (log.isDebugEnabled()) {
-        log.debug("Read item '{}' for user ID '{}'", item, userID);
-      }
       if (preferenceValueString == null) {
         prefs.add(new BooleanPreference(null, item));
       } else {
@@ -373,6 +370,7 @@
       for (Preference pref : prefs) {
         itemIDs.add(pref.getItem().getID());
       }
+      itemIDs.rehash();
       return new BooleanPrefUser<String>(id, itemIDs);
     }
     return new GenericUser<String>(id, prefs);

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/BooleanTanimotoCoefficientSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/BooleanTanimotoCoefficientSimilarity.java?rev=773799&r1=773798&r2=773799&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/BooleanTanimotoCoefficientSimilarity.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/BooleanTanimotoCoefficientSimilarity.java
Tue May 12 06:25:02 2009
@@ -54,23 +54,17 @@
 
   @Override
   public double userSimilarity(User user1, User user2) {
-    if (!(user1 instanceof BooleanPrefUser && user2 instanceof BooleanPrefUser))
{
-      throw new IllegalArgumentException();
-    }
-    BooleanPrefUser<?> bpUser1 = (BooleanPrefUser<?>) user1;
-    BooleanPrefUser<?> bpUser2 = (BooleanPrefUser<?>) user2;
-
-    FastSet<Object> prefs1 = bpUser1.getItemIDs();
-    FastSet<Object> prefs2 = bpUser2.getItemIDs();
-    int intersectionSize =
-        prefs1.size() < prefs2.size() ? prefs2.intersectionSize(prefs1) : prefs1.intersectionSize(prefs2);
-
-    int unionSize = prefs1.size() + prefs2.size() - intersectionSize;
-
+    FastSet<Object> prefs1 = ((BooleanPrefUser<?>) user1).getItemIDs();
+    FastSet<Object> prefs2 = ((BooleanPrefUser<?>) user2).getItemIDs();
+    int prefs1Size = prefs1.size();
+    int prefs2Size = prefs2.size();
+    int intersectionSize = prefs1Size < prefs2Size ?
+                           prefs2.intersectionSize(prefs1) :
+                           prefs1.intersectionSize(prefs2);
+    int unionSize = prefs1Size + prefs2Size - intersectionSize;
     return (double) intersectionSize / (double) unionSize;
   }
 
-
   @Override
   public void refresh(Collection<Refreshable> alreadyRefreshed) {
     alreadyRefreshed = RefreshHelper.buildRefreshed(alreadyRefreshed);
@@ -82,4 +76,4 @@
     return "BooleanTanimotoCoefficientSimilarity[dataModel:" + dataModel + ']';
   }
 
-}
+}
\ No newline at end of file



Mime
View raw message