mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r685329 - in /lucene/mahout/trunk/core/src: main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/ test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/
Date Tue, 12 Aug 2008 21:42:56 GMT
Author: srowen
Date: Tue Aug 12 14:42:55 2008
New Revision: 685329

URL: http://svn.apache.org/viewvc?rev=685329&view=rev
Log:
Use Weighting in MemoryDiffStorage constructor and add a few tests for this class

Added:
    lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorageTest.java
Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorage.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommender.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorage.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorage.java?rev=685329&r1=685328&r2=685329&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorage.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorage.java
Tue Aug 12 14:42:55 2008
@@ -19,6 +19,7 @@
 
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.common.Refreshable;
+import org.apache.mahout.cf.taste.common.Weighting;
 import org.apache.mahout.cf.taste.impl.common.*;
 import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.model.Item;
@@ -83,7 +84,7 @@
    * is null
    */
   public MemoryDiffStorage(DataModel dataModel,
-                           boolean stdDevWeighted,
+                           Weighting stdDevWeighted,
                            boolean compactAverages,
                            long maxEntries) throws TasteException {
     if (dataModel == null) {
@@ -93,7 +94,7 @@
       throw new IllegalArgumentException("maxEntries must be positive");
     }
     this.dataModel = dataModel;
-    this.stdDevWeighted = stdDevWeighted;
+    this.stdDevWeighted = stdDevWeighted == Weighting.WEIGHTED;
     this.compactAverages = compactAverages;
     this.maxEntries = maxEntries;
     this.averageDiffs = new FastMap<Object, Map<Object, RunningAverage>>();

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommender.java?rev=685329&r1=685328&r2=685329&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommender.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommender.java
Tue Aug 12 14:42:55 2008
@@ -65,7 +65,7 @@
     this(dataModel,
          Weighting.WEIGHTED,
          Weighting.WEIGHTED,
-         new MemoryDiffStorage(dataModel, true, false, Long.MAX_VALUE));
+         new MemoryDiffStorage(dataModel, Weighting.WEIGHTED, false, Long.MAX_VALUE));
   }
 
   /**

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorageTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorageTest.java?rev=685329&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorageTest.java
(added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorageTest.java
Tue Aug 12 14:42:55 2008
@@ -0,0 +1,57 @@
+/**
+ * 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.cf.taste.impl.recommender.slopeone;
+
+import org.apache.mahout.cf.taste.impl.TasteTestCase;
+import org.apache.mahout.cf.taste.impl.common.RunningAverage;
+import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
+import org.apache.mahout.cf.taste.model.DataModel;
+import org.apache.mahout.cf.taste.common.Weighting;
+
+/**
+ * Tests {@link MemoryDiffStorage}.
+ */
+public class MemoryDiffStorageTest extends TasteTestCase {
+
+  public void testGetDiff() throws Exception {
+    DataModel model = new GenericDataModel(getMockUsers());
+    MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.UNWEIGHTED, false,
Long.MAX_VALUE);
+    RunningAverage average = storage.getDiff("1", "2");
+    assertEquals(0.23333333333333334, average.getAverage(), EPSILON);
+    assertEquals(3, average.getCount());
+  }
+
+  public void testUpdate() throws Exception {
+    DataModel model = new GenericDataModel(getMockUsers());
+    MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.UNWEIGHTED, false,
Long.MAX_VALUE);
+    storage.updateItemPref("1", 0.5, false);
+    RunningAverage average = storage.getDiff("1", "2");
+    assertEquals(0.06666666666666668, average.getAverage(), EPSILON);
+    assertEquals(3, average.getCount());
+  }
+
+  public void testRemove() throws Exception {
+    DataModel model = new GenericDataModel(getMockUsers());
+    MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.UNWEIGHTED, false,
Long.MAX_VALUE);
+    storage.updateItemPref("1", 0.5, true);
+    RunningAverage average = storage.getDiff("1", "2");
+    assertEquals(0.1, average.getAverage(), EPSILON);
+    assertEquals(2, average.getCount());
+  }
+
+}



Mime
View raw message