mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r1142566 [2/2] - in /mahout/trunk/core/src: main/java/org/apache/mahout/classifier/naivebayes/ main/java/org/apache/mahout/classifier/naivebayes/trainer/ main/java/org/apache/mahout/classifier/naivebayes/training/ main/java/org/apache/mahou...
Date Mon, 04 Jul 2011 06:49:19 GMT
Added: mahout/trunk/core/src/test/java/org/apache/mahout/classifier/naivebayes/training/WeightsMapperTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/naivebayes/training/WeightsMapperTest.java?rev=1142566&view=auto
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/classifier/naivebayes/training/WeightsMapperTest.java
(added)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/classifier/naivebayes/training/WeightsMapperTest.java
Mon Jul  4 06:49:17 2011
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.classifier.naivebayes.training;
+
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.mahout.common.MahoutTestCase;
+import org.apache.mahout.math.DenseVector;
+import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.VectorWritable;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class WeightsMapperTest extends MahoutTestCase {
+
+  @Test
+  public void scores() throws Exception {
+
+    Mapper.Context ctx = EasyMock.createMock(Mapper.Context.class);
+    Vector instance1 = new DenseVector(new double[] { 1, 0,   0.5, 0.5, 0 });
+    Vector instance2 = new DenseVector(new double[] { 0, 0.5, 0,   0,   0 });
+    Vector instance3 = new DenseVector(new double[] { 1, 0.5, 1,   1.5, 1 });
+
+    Vector weightsPerLabel = new DenseVector(new double[] { 0, 0 });
+
+    ctx.write(new Text(TrainNaiveBayesJob.WEIGHTS_PER_FEATURE),
+        new VectorWritable(new DenseVector(new double[] { 2, 1, 1.5, 2, 1 })));
+    ctx.write(new Text(TrainNaiveBayesJob.WEIGHTS_PER_LABEL),
+        new VectorWritable(new DenseVector(new double[] { 2.5, 5 })));
+
+    EasyMock.replay(ctx);
+
+    WeightsMapper weights = new WeightsMapper();
+    setField(weights, "weightsPerLabel", weightsPerLabel);
+
+    weights.map(new IntWritable(0), new VectorWritable(instance1), ctx);
+    weights.map(new IntWritable(0), new VectorWritable(instance2), ctx);
+    weights.map(new IntWritable(1), new VectorWritable(instance3), ctx);
+
+    weights.cleanup(ctx);
+
+    EasyMock.verify(ctx);
+  }
+}



Mime
View raw message