mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smar...@apache.org
Subject svn commit: r1542279 - in /mahout/trunk: CHANGELOG core/src/main/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoder.java core/src/test/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoderTest.java
Date Fri, 15 Nov 2013 14:48:18 GMT
Author: smarthi
Date: Fri Nov 15 14:48:18 2013
New Revision: 1542279

URL: http://svn.apache.org/r1542279
Log:
MAHOUT-1357: InteractionValueEncoder produces wrong traceDictionary entries

Modified:
    mahout/trunk/CHANGELOG
    mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoder.java
    mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoderTest.java

Modified: mahout/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/mahout/trunk/CHANGELOG?rev=1542279&r1=1542278&r2=1542279&view=diff
==============================================================================
--- mahout/trunk/CHANGELOG (original)
+++ mahout/trunk/CHANGELOG Fri Nov 15 14:48:18 2013
@@ -2,6 +2,8 @@ Mahout Change Log
 
 Release 0.9 - unreleased
 
+  MAHOUT-1355: InteractionValueEncoder produces wrong traceDictionary entries (Johannes Schulte
via smarthi)
+
   MAHOUT-1343: JSON output format support in cluster dumper (Telvis Calhoun via sslavic)
 
   MAHOUT-1333: Fixed examples bin directory permissions in distribution archives (Mike Percy
via sslavic)

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoder.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoder.java?rev=1542279&r1=1542278&r2=1542279&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoder.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoder.java
Fri Nov 15 14:48:18 2013
@@ -17,10 +17,11 @@
 
 package org.apache.mahout.vectorizer.encoders;
 
+import java.util.Locale;
+
 import org.apache.mahout.math.Vector;
 
-import java.util.Arrays;
-import java.util.Locale;
+import com.google.common.base.Charsets;
 
 public class InteractionValueEncoder extends FeatureVectorEncoder {
   private final FeatureVectorEncoder firstEncoder;
@@ -86,7 +87,8 @@ public class InteractionValueEncoder ext
         for (Integer j : jValues) {
           int n = (k + j) % data.size();
           if (isTraceEnabled()) {
-            trace(String.format("%s:%s", Arrays.toString(originalForm1), Arrays.toString(originalForm2)),
n);
+            trace(String.format("%s:%s", new String(originalForm1, Charsets.UTF_8), new String(originalForm2,
+		Charsets.UTF_8)), n);
           }
           data.set(n, data.get(n) + w);
         }

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoderTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoderTest.java?rev=1542279&r1=1542278&r2=1542279&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoderTest.java
(original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/encoders/InteractionValueEncoderTest.java
Fri Nov 15 14:48:18 2013
@@ -17,6 +17,12 @@
 
 package org.apache.mahout.vectorizer.encoders;
 
+import java.util.Map;
+import java.util.Set;
+
+import static com.google.common.collect.Iterables.getFirst;
+
+import com.google.common.collect.Maps;
 import org.apache.mahout.common.MahoutTestCase;
 import org.apache.mahout.math.DenseVector;
 import org.apache.mahout.math.Vector;
@@ -73,5 +79,25 @@ public class InteractionValueEncoderTest
     // should interact "a" with each of "some","text" and "here"
     assertEquals((float) k*3, v1.norm(1), 0);
   }
+  
+  @Test
+  public void testTraceDictionary() {
+    StaticWordValueEncoder encoder1 = new StaticWordValueEncoder("first");
+    StaticWordValueEncoder encoder2 = new StaticWordValueEncoder("second");
+    
+    Map<String, Set<Integer>> traceDictionary = Maps.newHashMap();
+
+    InteractionValueEncoder interactions = new InteractionValueEncoder("interactions", encoder1,
encoder2);
+    interactions.setProbes(1);
+    interactions.setTraceDictionary(traceDictionary);
+    
+    Vector v = new DenseVector(10);
+    interactions.addInteractionToVector("a", "b", 1, v);
+    
+    assertEquals(1, v.getNumNonZeroElements());
+    assertEquals(1, traceDictionary.size());
+    assertEquals("interactions=a:b", getFirst(traceDictionary.keySet(), null));
+
+  }
 
 }



Mime
View raw message