You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2009/12/15 18:39:19 UTC

svn commit: r890899 [2/2] - in /lucene/mahout/trunk/core/src: main/java/org/apache/mahout/cf/taste/impl/model/jdbc/ main/java/org/apache/mahout/classifier/bayes/mapreduce/bayes/ main/java/org/apache/mahout/classifier/bayes/mapreduce/cbayes/ main/java/o...

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FrequentPatternMaxHeap.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FrequentPatternMaxHeap.java?rev=890899&r1=890898&r2=890899&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FrequentPatternMaxHeap.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FrequentPatternMaxHeap.java Tue Dec 15 17:39:18 2009
@@ -21,13 +21,12 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.SortedSet;
 import java.util.TreeSet;
 
-/**
- * {@link FrequentPatternMaxHeap} keeps top K Attributes in a TreeSet
- * 
- */
+/** {@link FrequentPatternMaxHeap} keeps top K Attributes in a TreeSet */
 public class FrequentPatternMaxHeap {
+
   private final Comparator<Pattern> treeSetComparator = new Comparator<Pattern>() {
     @Override
     public int compare(Pattern cr1, Pattern cr2) {
@@ -39,13 +38,15 @@
         if (length1 == length2) {// if they are of same length and support order
           // randomly
           return 1;
-        } else
+        } else {
           return length2 - length1;
+        }
       } else {
-        if (support2 - support1 > 0)
+        if (support2 - support1 > 0) {
           return 1;
-        else
+        } else {
           return -1;
+        }
       }
     }
   };
@@ -66,12 +67,13 @@
   }
 
   public final boolean addable(long support) {
-    if (count < maxSize)
+    if (count < maxSize) {
       return true;
+    }
     return least.support() <= support;
   }
 
-  public final TreeSet<Pattern> getHeap() {
+  public final SortedSet<Pattern> getHeap() {
     return set;
   }
 
@@ -82,8 +84,9 @@
   public final void insert(Pattern frequentPattern, boolean subPatternCheck) {
     if (subPatternCheck)// lazy initialization
     {
-      if (patternIndex == null)
+      if (patternIndex == null) {
         patternIndex = new HashMap<Long, Set<Pattern>>();
+      }
     }
     if (count == maxSize) {
       int cmp = treeSetComparator.compare(frequentPattern, least);
@@ -91,8 +94,9 @@
         if (addPattern(frequentPattern, subPatternCheck)) {
           Pattern evictedItem = set.pollLast();
           least = set.last();
-          if (subPatternCheck)
+          if (subPatternCheck) {
             patternIndex.get(evictedItem.support()).remove(evictedItem);
+          }
         }
       }
     } else {
@@ -100,16 +104,17 @@
         count++;
         if (least != null) {
           int cmp = treeSetComparator.compare(least, frequentPattern);
-          if (cmp < 0)
+          if (cmp < 0) {
             least = frequentPattern;
+          }
         } else {
           least = frequentPattern;
         }
       }
     }
   }
-  
-  public final int count(){
+
+  public final int count() {
     return count;
   }
 
@@ -118,8 +123,9 @@
   }
 
   public final long leastSupport() {
-    if (least == null)
+    if (least == null) {
       return 0;
+    }
     return least.support();
   }
 
@@ -129,7 +135,7 @@
   }
 
   private boolean addPattern(Pattern frequentPattern,
-      boolean subPatternCheck) {
+                             boolean subPatternCheck) {
     if (subPatternCheck == false) {
       set.add(frequentPattern);
       return true;
@@ -141,9 +147,9 @@
         Pattern replacablePattern = null;
         for (Pattern p : indexSet) {
 
-          if (frequentPattern.isSubPatternOf(p))
+          if (frequentPattern.isSubPatternOf(p)) {
             return false;
-          else if (p.isSubPatternOf(frequentPattern)) {
+          } else if (p.isSubPatternOf(frequentPattern)) {
             replace = true;
             replacablePattern = p;
             break;
@@ -151,11 +157,13 @@
         }
         if (replace) {
           indexSet.remove(replacablePattern);
-          if (set.remove(replacablePattern))
+          if (set.remove(replacablePattern)) {
             count--;
+          }
           if (indexSet.contains(frequentPattern) == false) {
-            if (set.add(frequentPattern))
+            if (set.add(frequentPattern)) {
               count++;
+            }
             indexSet.add(frequentPattern);
           }
           return false;

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/Pattern.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/Pattern.java?rev=890899&r1=890898&r2=890899&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/Pattern.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/fpm/pfpgrowth/fpgrowth/Pattern.java Tue Dec 15 17:39:18 2009
@@ -42,16 +42,18 @@
   }
 
   private Pattern(int size) {
-    if (size < DEFAULT_INITIAL_SIZE)
+    if (size < DEFAULT_INITIAL_SIZE) {
       size = DEFAULT_INITIAL_SIZE;
+    }
     this.pattern = new int[size];
     this.supportValues = new long[size];
     dirty = true;
   }
 
   public final void add(int id, long support) {
-    if (length >= pattern.length)
+    if (length >= pattern.length) {
       resize();
+    }
     this.pattern[length] = id;
     this.supportValues[length++] = support;
     this.support = (support > this.support) ? this.support : support;
@@ -60,17 +62,22 @@
 
   @Override
   public boolean equals(Object obj) {
-    if (this == obj)
+    if (this == obj) {
       return true;
-    if (obj == null)
+    }
+    if (obj == null) {
       return false;
-    if (getClass() != obj.getClass())
+    }
+    if (getClass() != obj.getClass()) {
       return false;
+    }
     Pattern other = (Pattern) obj;
-    if (length != other.length)
+    if (length != other.length) {
       return false;
-    if (support != other.support)
+    }
+    if (support != other.support) {
       return false;
+    }
     return Arrays.equals(pattern, other.pattern);
   }
 
@@ -79,13 +86,14 @@
   }
 
   public final Object[] getPatternWithSupport() {
-    return new Object[] { this.pattern, this.supportValues };
+    return new Object[]{this.pattern, this.supportValues};
   }
 
   @Override
   public int hashCode() {
-    if (dirty == false)
+    if (dirty == false) {
       return hashCode;
+    }
     int result = 1;
     int prime = 31;
     result = prime * result + Arrays.hashCode(pattern);
@@ -97,8 +105,9 @@
   public final boolean isSubPatternOf(Pattern frequentPattern) {
     int[] otherPattern = frequentPattern.getPattern();
     int otherLength = frequentPattern.length();
-    if (this.length() > frequentPattern.length())
+    if (this.length() > frequentPattern.length()) {
       return false;
+    }
     int i = 0;
     int otherI = 0;
     while (i < length && otherI < otherLength) {
@@ -107,8 +116,9 @@
         i++;
       } else if (otherPattern[otherI] < pattern[i]) {
         otherI++;
-      } else
+      } else {
         return false;
+      }
     }
     return otherI != otherLength || i == length;
   }
@@ -130,8 +140,9 @@
 
   private void resize() {
     int size = (int) (GROWTH_RATE * length);
-    if (size < DEFAULT_INITIAL_SIZE)
+    if (size < DEFAULT_INITIAL_SIZE) {
       size = DEFAULT_INITIAL_SIZE;
+    }
     int[] oldpattern = pattern;
     long[] oldSupport = supportValues;
     this.pattern = new int[size];

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapred/partial/PartitionBugTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapred/partial/PartitionBugTest.java?rev=890899&r1=890898&r2=890899&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapred/partial/PartitionBugTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapred/partial/PartitionBugTest.java Tue Dec 15 17:39:18 2009
@@ -148,6 +148,11 @@
     }
 
     @Override
+    protected Type getType() {
+      return Type.MOCKLEAF;
+    }
+
+    @Override
     public long nbNodes() {
       return 0;
     }

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/PartitionBugTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/PartitionBugTest.java?rev=890899&r1=890898&r2=890899&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/PartitionBugTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/df/mapreduce/partial/PartitionBugTest.java Tue Dec 15 17:39:18 2009
@@ -146,6 +146,11 @@
     }
 
     @Override
+    protected Type getType() {
+      return Type.MOCKLEAF;
+    }
+
+    @Override
     public long nbNodes() {
       // TODO Auto-generated method stub
       return 0;