mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r741253 - in /lucene/mahout/trunk/core/src: main/java/org/apache/mahout/cf/taste/impl/common/ test/java/org/apache/mahout/cf/taste/impl/eval/
Date Thu, 05 Feb 2009 19:32:08 GMT
Author: srowen
Date: Thu Feb  5 19:32:08 2009
New Revision: 741253

URL: http://svn.apache.org/viewvc?rev=741253&view=rev
Log:
Switch back to Random from MersenneTwisterRNG to avoid bad lock contention; quick enhancement
to FastMap/Set to avoid growing when not necessary

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastMap.java
    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/common/RandomUtils.java
    lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluatorTest.java
    lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluatorTest.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastMap.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastMap.java?rev=741253&r1=741252&r2=741253&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastMap.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastMap.java
Thu Feb  5 19:32:08 2009
@@ -178,8 +178,15 @@
       throw new NullPointerException();
     }
     int hashSize = keys.length;
+    // If less than half the slots are open, let's clear it up
     if (numSlotsUsed >= hashSize >> 1) {
-      growAndRehash();
+      // If over half the slots used are actual entries, let's grow
+      if (numEntries >= numSlotsUsed >> 1) {
+        growAndRehash();
+      } else {
+        // Otherwise just rehash to clear REMOVED entries and don't grow
+        rehash();
+      }
     }
     // Here we may later consider implementing Brent's variation described on page 532
     int index = find(key);

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=741253&r1=741252&r2=741253&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
Thu Feb  5 19:32:08 2009
@@ -123,8 +123,15 @@
       throw new NullPointerException();
     }
     int hashSize = keys.length;
+    // If less than half the slots are open, let's clear it up
     if (numSlotsUsed >= hashSize >> 1) {
-      growAndRehash();
+      // If over half the slots used are actual entries, let's grow
+      if (numEntries >= numSlotsUsed >> 1) {
+        growAndRehash();
+      } else {
+        // Otherwise just rehash to clear REMOVED entries and don't grow
+        rehash();
+      }
     }
     // Here we may later consider implementing Brent's variation described on page 532
     int index = find(key);

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java?rev=741253&r1=741252&r2=741253&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java
Thu Feb  5 19:32:08 2009
@@ -30,12 +30,7 @@
  */
 public final class RandomUtils {
 
-  private static final byte[] STANDARD_SEED = {
-      (byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE,
-      (byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE,
-      (byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE,
-      (byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE,
-  };
+  private static final long STANDARD_SEED = 0xCAFEBABECAFEBABEL;
   private static boolean testSeed;
 
   /**
@@ -51,7 +46,7 @@
   }
 
   public static Random getRandom() {
-    return testSeed ? new MersenneTwisterRNG(STANDARD_SEED) : new MersenneTwisterRNG();
+    return testSeed ? new Random(STANDARD_SEED) : new Random();
   }
 
   /**

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluatorTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluatorTest.java?rev=741253&r1=741252&r2=741253&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluatorTest.java
(original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluatorTest.java
Thu Feb  5 19:32:08 2009
@@ -37,7 +37,7 @@
     RecommenderEvaluator evaluator =
             new AverageAbsoluteDifferenceRecommenderEvaluator();
     double eval = evaluator.evaluate(builder, model, 0.75, 1.0);
-    assertEquals(0.12387145540086855, eval, EPSILON);
+    assertEquals(0.31111111111111106, eval, EPSILON);
   }
 
 }

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluatorTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluatorTest.java?rev=741253&r1=741252&r2=741253&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluatorTest.java
(original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluatorTest.java
Thu Feb  5 19:32:08 2009
@@ -36,7 +36,7 @@
     };
     RecommenderEvaluator evaluator = new RMSRecommenderEvaluator();
     double eval = evaluator.evaluate(builder, model, 0.75, 1.0);
-    assertEquals(0.15553128261991583, eval, EPSILON);
+    assertEquals(0.387776185924781, eval, EPSILON);
   }
 
 }
\ No newline at end of file



Mime
View raw message