mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r1091320 - in /mahout/trunk/core/src: main/java/org/apache/mahout/common/cache/ main/java/org/apache/mahout/fpm/pfpgrowth/ main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/ test/java/org/apache/mahout/fpm/pfpgrowth/
Date Tue, 12 Apr 2011 08:06:39 GMT
Author: srowen
Date: Tue Apr 12 08:06:39 2011
New Revision: 1091320

URL: http://svn.apache.org/viewvc?rev=1091320&view=rev
Log:
MAHOUT-665 remove unused cache classes, move least-k next to its point of use, remove unused
cache size setter

Added:
    mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/LeastKCache.java
      - copied, changed from r1090861, mahout/trunk/core/src/main/java/org/apache/mahout/common/cache/LeastKCache.java
Removed:
    mahout/trunk/core/src/main/java/org/apache/mahout/common/cache/
Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowth.java
    mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/ParallelFPGrowthReducer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FPTreeDepthCache.java
    mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthRetailDataTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthTest.java

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowth.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowth.java?rev=1091320&r1=1091319&r2=1091320&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowth.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowth.java Tue Apr
12 08:06:39 2011
@@ -74,8 +74,7 @@ public final class PFPGrowth {
   public static final String PARALLEL_COUNTING = "parallelcounting";  
   public static final String SORTED_OUTPUT = "sortedoutput";
   public static final String SPLIT_PATTERN = "splitPattern";
-  public static final String TREE_CACHE_SIZE = "treeCacheSize";
-  
+
   public static final Pattern SPLITTER = Pattern.compile("[ ,\t]*[,|\t][ ,\t]*");
   
   private static final Logger log = LoggerFactory.getLogger(PFPGrowth.class);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/ParallelFPGrowthReducer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/ParallelFPGrowthReducer.java?rev=1091320&r1=1091319&r2=1091320&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/ParallelFPGrowthReducer.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/ParallelFPGrowthReducer.java
Tue Apr 12 08:06:39 2011
@@ -37,7 +37,6 @@ import org.apache.mahout.fpm.pfpgrowth.c
 import org.apache.mahout.fpm.pfpgrowth.convertors.integer.IntegerStringOutputConverter;
 import org.apache.mahout.fpm.pfpgrowth.convertors.string.TopKStringPatterns;
 import org.apache.mahout.fpm.pfpgrowth.fpgrowth.FPGrowth;
-import org.apache.mahout.fpm.pfpgrowth.fpgrowth.FPTreeDepthCache;
 import org.apache.mahout.math.list.IntArrayList;
 import org.apache.mahout.math.map.OpenLongObjectHashMap;
 import org.apache.mahout.math.map.OpenObjectIntHashMap;
@@ -129,7 +128,5 @@ public class ParallelFPGrowthReducer ext
     }
     maxHeapSize = Integer.valueOf(params.get(PFPGrowth.MAX_HEAPSIZE, "50"));
     minSupport = Integer.valueOf(params.get(PFPGrowth.MIN_SUPPORT, "3"));
-    FPTreeDepthCache.setFirstLevelCacheSize(Integer.valueOf(params.get(PFPGrowth.TREE_CACHE_SIZE,
Integer
-        .toString(FPTreeDepthCache.getFirstLevelCacheSize()))));
   }
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FPTreeDepthCache.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FPTreeDepthCache.java?rev=1091320&r1=1091319&r2=1091320&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FPTreeDepthCache.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FPTreeDepthCache.java
Tue Apr 12 08:06:39 2011
@@ -20,51 +20,26 @@ package org.apache.mahout.fpm.pfpgrowth.
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.mahout.common.cache.LeastKCache;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * Caches large FPTree {@link Object} for each level of the recursive
  * {@link FPGrowth} algorithm to reduce allocation overhead.
- * 
  */
 public class FPTreeDepthCache {
 
-  private static final Logger log = LoggerFactory.getLogger(FPTreeDepthCache.class);
-
-  private static int firstLevelCacheSize = 5;
-
-  private final LeastKCache<Integer,FPTree> firstLevelCache = new LeastKCache<Integer,FPTree>(firstLevelCacheSize);
-  
+  private final LeastKCache<Integer,FPTree> firstLevelCache = new LeastKCache<Integer,FPTree>(5);
   private int hits;
-  
   private int misses;
-  
   private final List<FPTree> treeCache = new ArrayList<FPTree>();
   
-  public FPTreeDepthCache() {
-    log.info("Initializing FPTreeCache with firstLevelCacheSize: {}",
-      firstLevelCacheSize);
-  }
-  
-  public static int getFirstLevelCacheSize() {
-    return firstLevelCacheSize;
-  }
-  
-  public static void setFirstLevelCacheSize(int firstLevelCacheSize) {
-    FPTreeDepthCache.firstLevelCacheSize = firstLevelCacheSize;
-  }
-  
-  public final FPTree getFirstLevelTree(int attr) {
-    Integer attribute = attr;
-    if (firstLevelCache.contains(attribute)) {
+  public final FPTree getFirstLevelTree(Integer attr) {
+    FPTree tree = firstLevelCache.get(attr);
+    if (tree != null) {
       hits++;
-      return firstLevelCache.get(attribute);
+      return tree;
     } else {
       misses++;
       FPTree conditionalTree = new FPTree();
-      firstLevelCache.set(attribute, conditionalTree);
+      firstLevelCache.set(attr, conditionalTree);
       return conditionalTree;
     }
   }

Copied: mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/LeastKCache.java
(from r1090861, mahout/trunk/core/src/main/java/org/apache/mahout/common/cache/LeastKCache.java)
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/LeastKCache.java?p2=mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/LeastKCache.java&p1=mahout/trunk/core/src/main/java/org/apache/mahout/common/cache/LeastKCache.java&r1=1090861&r2=1091320&rev=1091320&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/cache/LeastKCache.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/LeastKCache.java
Tue Apr 12 08:06:39 2011
@@ -15,48 +15,29 @@
  * limitations under the License.
  */
 
-package org.apache.mahout.common.cache;
+package org.apache.mahout.fpm.pfpgrowth.fpgrowth;
 
-import java.util.Comparator;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.PriorityQueue;
 
-public class LeastKCache<K extends Comparable<? super K>,V> implements Cache<K,V>
{
+public class LeastKCache<K extends Comparable<? super K>,V> {
   
   private final int capacity;
-  
   private final Map<K,V> cache;
-  
   private final PriorityQueue<K> queue;
   
   public LeastKCache(int capacity) {
-    
     this.capacity = capacity;
-    
     cache = new HashMap<K,V>(capacity);
-    queue = new PriorityQueue<K>(capacity, new Comparator<K>() {
-      
-      @Override
-      public int compare(K o1, K o2) {
-        return o2.compareTo(o1);
-      }
-      
-    });
-    
-  }
-  
-  @Override
-  public final long capacity() {
-    return capacity;
+    queue = new PriorityQueue<K>(capacity + 1, Collections.reverseOrder());
   }
-  
-  @Override
+
   public final V get(K key) {
     return cache.get(key);
   }
   
-  @Override
   public final void set(K key, V value) {
     if (!contains(key)) {
       queue.add(key);
@@ -68,12 +49,10 @@ public class LeastKCache<K extends Compa
     }
   }
   
-  @Override
   public final long size() {
     return cache.size();
   }
   
-  @Override
   public final boolean contains(K key) {
     return cache.containsKey(key);
   }

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthRetailDataTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthRetailDataTest.java?rev=1091320&r1=1091319&r2=1091320&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthRetailDataTest.java
(original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthRetailDataTest.java
Tue Apr 12 08:06:39 2011
@@ -32,6 +32,7 @@ import java.util.Map.Entry;
 import java.util.Set;
 
 import com.google.common.base.Charsets;
+import com.google.common.io.Files;
 import org.apache.mahout.common.MahoutTestCase;
 import org.apache.mahout.common.Pair;
 import org.apache.mahout.common.Parameters;
@@ -56,13 +57,12 @@ public class PFPGrowthRetailDataTest ext
     params.set(PFPGrowth.MAX_HEAPSIZE, "10000");
     params.set(PFPGrowth.NUM_GROUPS, "50");
     params.set(PFPGrowth.ENCODING, "UTF-8");
-    params.set(PFPGrowth.TREE_CACHE_SIZE, "5");
     File inputDir = getTestTempDir("transactions");
     File outputDir = getTestTempDir("frequentpatterns");
     File input = new File(inputDir, "test.txt");
     params.set(PFPGrowth.INPUT, input.getAbsolutePath());
     params.set(PFPGrowth.OUTPUT, outputDir.getAbsolutePath());
-    Writer writer = new OutputStreamWriter(new FileOutputStream(input), Charsets.UTF_8);
+    Writer writer = Files.newWriter(input, Charsets.UTF_8);
     try {
       StringRecordIterator it = new StringRecordIterator(new FileLineIterable(Resources.getResource(
         "retail.dat").openStream()), "\\s+");

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthTest.java?rev=1091320&r1=1091319&r2=1091320&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/fpm/pfpgrowth/PFPGrowthTest.java Tue
Apr 12 08:06:39 2011
@@ -18,10 +18,7 @@
 package org.apache.mahout.fpm.pfpgrowth;
 
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
 import java.io.Writer;
-import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -29,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 
 import com.google.common.base.Charsets;
+import com.google.common.io.Files;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.mahout.common.MahoutTestCase;
 import org.apache.mahout.common.Pair;
@@ -51,13 +49,12 @@ public final class PFPGrowthTest extends
     params.set(PFPGrowth.MAX_HEAPSIZE, "4");
     params.set(PFPGrowth.NUM_GROUPS, "2");
     params.set(PFPGrowth.ENCODING, "UTF-8");
-    params.set(PFPGrowth.TREE_CACHE_SIZE, "5");
     File inputDir = getTestTempDir("transactions");
     File outputDir = getTestTempDir("frequentpatterns");
     File input = new File(inputDir, "test.txt");
     params.set(PFPGrowth.INPUT, input.getAbsolutePath());
     params.set(PFPGrowth.OUTPUT, outputDir.getAbsolutePath());
-    Writer writer = new OutputStreamWriter(new FileOutputStream(input), Charsets.UTF_8);
+    Writer writer = Files.newWriter(input, Charsets.UTF_8);
     try {
       Collection<List<String>> transactions = new ArrayList<List<String>>();
       transactions.add(Arrays.asList("E", "A", "D", "B"));



Mime
View raw message