mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r800634 [6/7] - in /lucene/mahout/trunk: core/src/main/java/org/apache/mahout/cf/taste/hadoop/ core/src/main/java/org/apache/mahout/cf/taste/impl/common/ core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/ core/src/main/java/org...
Date Tue, 04 Aug 2009 00:06:50 GMT
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/NullRescorerTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/NullRescorerTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/NullRescorerTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/NullRescorerTest.java Tue Aug  4 00:06:46 2009
@@ -18,13 +18,8 @@
 package org.apache.mahout.cf.taste.impl.recommender;
 
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
-import org.apache.mahout.cf.taste.impl.model.GenericUser;
-import org.apache.mahout.cf.taste.model.Preference;
-import org.apache.mahout.cf.taste.model.User;
 import org.apache.mahout.cf.taste.recommender.Rescorer;
 
-import java.util.Collections;
-
 /** <p>Tests {@link NullRescorer}.</p> */
 public final class NullRescorerTest extends TasteTestCase {
 
@@ -38,13 +33,12 @@
   }
 
   public void testUserRescorer() throws Exception {
-    Rescorer<User> rescorer = NullRescorer.getUserInstance();
+    Rescorer<Comparable<?>> rescorer = NullRescorer.getUserInstance();
     assertNotNull(rescorer);
-    User user = new GenericUser("test", Collections.<Preference>emptyList());
-    assertEquals(1.0, rescorer.rescore(user, 1.0));
+    assertEquals(1.0, rescorer.rescore("test", 1.0));
     assertEquals(1.0, rescorer.rescore(null, 1.0));
-    assertEquals(0.0, rescorer.rescore(user, 0.0));
-    assertTrue(Double.isNaN(rescorer.rescore(user, Double.NaN)));
+    assertEquals(0.0, rescorer.rescore("test", 0.0));
+    assertTrue(Double.isNaN(rescorer.rescore("test", Double.NaN)));
   }
 
 }

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommenderTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommenderTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommenderTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommenderTest.java Tue Aug  4 00:06:46 2009
@@ -18,26 +18,25 @@
 package org.apache.mahout.cf.taste.impl.recommender;
 
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
-import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
 import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
 import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.User;
 import org.apache.mahout.cf.taste.recommender.RecommendedItem;
 import org.apache.mahout.cf.taste.recommender.Recommender;
 import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /** <p>Tests {@link TreeClusteringRecommender}.</p> */
 public final class TreeClusteringRecommenderTest extends TasteTestCase {
 
   public void testNoRecommendations() throws Exception {
-    List<User> users = new ArrayList<User>(3);
-    users.add(getUser("test1", 0.1));
-    users.add(getUser("test2", 0.2, 0.6));
-    users.add(getUser("test3", 0.4, 0.9));
-    DataModel dataModel = new GenericDataModel(users);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {0.1},
+                    {0.2, 0.6},
+                    {0.4, 0.9},
+            });
     UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
     ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
     Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
@@ -50,13 +49,16 @@
   }
 
   public void testHowMany() throws Exception {
-    List<User> users = new ArrayList<User>(3);
-    users.add(getUser("test1", 0.1, 0.2));
-    users.add(getUser("test2", 0.2, 0.3, 0.3, 0.6));
-    users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
-    users.add(getUser("test4", 0.1, 0.4, 0.5, 0.8, 0.9, 1.0));
-    users.add(getUser("test5", 0.2, 0.3, 0.6, 0.7, 0.1, 0.2));
-    DataModel dataModel = new GenericDataModel(users);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3", "test4", "test5"},
+            new Double[][] {
+                    {0.1, 0.2},
+                    {0.2, 0.3, 0.3, 0.6},
+                    {0.4, 0.4, 0.5, 0.9},
+                    {0.1, 0.4, 0.5, 0.8, 0.9, 1.0},
+                    {0.2, 0.3, 0.6, 0.7, 0.1, 0.2},
+            });
+
     UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
     ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
     Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
@@ -72,11 +74,14 @@
   }
 
   public void testRescorer() throws Exception {
-    List<User> users = new ArrayList<User>(3);
-    users.add(getUser("test1", 0.1, 0.2));
-    users.add(getUser("test2", 0.2, 0.3, 0.3, 0.6));
-    users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
-    DataModel dataModel = new GenericDataModel(users);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {0.1, 0.2},
+                    {0.2, 0.3, 0.3, 0.6},
+                    {0.4, 0.4, 0.5, 0.9},
+            });
+
     UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
     ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
     Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
@@ -92,25 +97,32 @@
   }
 
   public void testEstimatePref() throws Exception {
-    List<User> users = new ArrayList<User>(4);
-    users.add(getUser("test1", 0.1, 0.3));
-    users.add(getUser("test2", 0.2, 0.3, 0.3));
-    users.add(getUser("test3", 0.4, 0.3, 0.5));
-    users.add(getUser("test4", 0.7, 0.3, 0.8, 0.9));
-    DataModel dataModel = new GenericDataModel(users);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3", "test4"},
+            new Double[][] {
+                    {0.1, 0.3},
+                    {0.2, 0.3, 0.3},
+                    {0.4, 0.3, 0.5},
+                    {0.7, 0.3, 0.8, 0.9},
+            });
+
     UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
     ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
     Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
-    assertEquals(0.9, recommender.estimatePreference("test3", "3"));
+    assertEquals(0.9f, recommender.estimatePreference("test3", "3"));
   }
 
   public void testBestRating() throws Exception {
-    List<User> users = new ArrayList<User>(4);
-    users.add(getUser("test1", 0.1, 0.3));
-    users.add(getUser("test2", 0.2, 0.3, 0.3));
-    users.add(getUser("test3", 0.4, 0.3, 0.5));
-    users.add(getUser("test4", 0.7, 0.3, 0.8));
-    DataModel dataModel = new GenericDataModel(users);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3", "test4"},
+            new Double[][] {
+                    {0.1, 0.3},
+                    {0.2, 0.3, 0.3},
+                    {0.4, 0.3, 0.5},
+                    {0.7, 0.3, 0.8},
+            });
+
+
     UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
     ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
     Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);

Modified: 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=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorageTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorageTest.java Tue Aug  4 00:06:46 2009
@@ -20,14 +20,13 @@
 import org.apache.mahout.cf.taste.common.Weighting;
 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;
 
 /** Tests {@link MemoryDiffStorage}. */
 public class MemoryDiffStorageTest extends TasteTestCase {
 
   public void testGetDiff() throws Exception {
-    DataModel model = new GenericDataModel(getMockUsers());
+    DataModel model = getDataModel();
     MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.UNWEIGHTED, false, Long.MAX_VALUE);
     RunningAverage average = storage.getDiff("1", "2");
     assertEquals(0.23333333333333334, average.getAverage(), EPSILON);
@@ -35,18 +34,18 @@
   }
 
   public void testUpdate() throws Exception {
-    DataModel model = new GenericDataModel(getMockUsers());
+    DataModel model = getDataModel();
     MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.UNWEIGHTED, false, Long.MAX_VALUE);
-    storage.updateItemPref("1", 0.5, false);
+    storage.updateItemPref("1", 0.5f, 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());
+    DataModel model = getDataModel();
     MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.UNWEIGHTED, false, Long.MAX_VALUE);
-    storage.updateItemPref("1", 0.5, true);
+    storage.updateItemPref("1", 0.5f, true);
     RunningAverage average = storage.getDiff("1", "2");
     assertEquals(0.1, average.getAverage(), EPSILON);
     assertEquals(2, average.getCount());

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommenderTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommenderTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommenderTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommenderTest.java Tue Aug  4 00:06:46 2009
@@ -19,14 +19,11 @@
 
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
-import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
 import org.apache.mahout.cf.taste.impl.recommender.ReversingRescorer;
 import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.User;
 import org.apache.mahout.cf.taste.recommender.RecommendedItem;
 import org.apache.mahout.cf.taste.recommender.Recommender;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /** <p>Tests {@link SlopeOneRecommender}.</p> */
@@ -46,13 +43,16 @@
   }
 
   public void testHowMany() throws Exception {
-    List<User> users = new ArrayList<User>(3);
-    users.add(getUser("test1", 0.1, 0.2));
-    users.add(getUser("test2", 0.2, 0.3, 0.3, 0.6));
-    users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
-    users.add(getUser("test4", 0.1, 0.4, 0.5, 0.8, 0.9, 1.0));
-    users.add(getUser("test5", 0.2, 0.3, 0.6, 0.7, 0.1, 0.2));
-    DataModel dataModel = new GenericDataModel(users);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3", "test4", "test5"},
+            new Double[][] {
+                    {0.1, 0.2},
+                    {0.2, 0.3, 0.3, 0.6},
+                    {0.4, 0.4, 0.5, 0.9},
+                    {0.1, 0.4, 0.5, 0.8, 0.9, 1.0},
+                    {0.2, 0.3, 0.6, 0.7, 0.1, 0.2},
+            });
+
     Recommender recommender = new SlopeOneRecommender(dataModel);
     List<RecommendedItem> fewRecommended = recommender.recommend("test1", 2);
     List<RecommendedItem> moreRecommended = recommender.recommend("test1", 4);
@@ -66,11 +66,14 @@
   }
 
   public void testRescorer() throws Exception {
-    List<User> users = new ArrayList<User>(3);
-    users.add(getUser("test1", 0.1, 0.2));
-    users.add(getUser("test2", 0.2, 0.3, 0.3, 0.6));
-    users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
-    DataModel dataModel = new GenericDataModel(users);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {0.1, 0.2},
+                    {0.2, 0.3, 0.3, 0.6},
+                    {0.4, 0.4, 0.5, 0.9},
+            });
+
     Recommender recommender = new SlopeOneRecommender(dataModel);
     List<RecommendedItem> originalRecommended = recommender.recommend("test1", 2);
     List<RecommendedItem> rescoredRecommended =
@@ -89,11 +92,14 @@
   }
 
   public void testBestRating() throws Exception {
-    List<User> users = new ArrayList<User>(3);
-    users.add(getUser("test1", 0.0, 0.3));
-    users.add(getUser("test2", 0.2, 0.3, 0.3));
-    users.add(getUser("test3", 0.4, 0.3, 0.5));
-    DataModel dataModel = new GenericDataModel(users);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {0.0, 0.3},
+                    {0.2, 0.3, 0.3},
+                    {0.4, 0.3, 0.5},
+            });
+
     Recommender recommender = new SlopeOneRecommender(dataModel);
     List<RecommendedItem> recommended = recommender.recommend("test1", 1);
     assertNotNull(recommended);
@@ -105,16 +111,19 @@
   }
 
   public void testDiffStdevBehavior() throws Exception {
-    List<User> users = new ArrayList<User>(3);
-    users.add(getUser("test1", 0.1, 0.2));
-    users.add(getUser("test2", 0.2, 0.3, 0.6));
-    DataModel dataModel = new GenericDataModel(users);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {0.1, 0.2},
+                    {0.2, 0.3, 0.6},
+            });
+
     Recommender recommender = new SlopeOneRecommender(dataModel);
     assertEquals(0.6, recommender.estimatePreference("test1", "2"), EPSILON);
   }
 
   private static Recommender buildRecommender() throws TasteException {
-    DataModel dataModel = new GenericDataModel(getMockUsers());
+    DataModel dataModel = getDataModel();
     return new SlopeOneRecommender(dataModel);
   }
 

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrerTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrerTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrerTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrerTest.java Tue Aug  4 00:06:46 2009
@@ -19,21 +19,16 @@
 
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
-import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
 import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.User;
 import org.apache.mahout.cf.taste.similarity.PreferenceInferrer;
 
-import java.util.Collections;
-
 /** <p>Tests {@link AveragingPreferenceInferrer}.</p> */
 public final class AveragingPreferenceInferrerTest extends TasteTestCase {
 
   public void testInferrer() throws TasteException {
-    User user1 = getUser("test1", 3.0, -2.0, 5.0);
-    DataModel model = new GenericDataModel(Collections.singletonList(user1));
+    DataModel model = getDataModel(new Comparable<?>[] {"test1"}, new Double[][] {{3.0,-2.0,5.0}});
     PreferenceInferrer inferrer = new AveragingPreferenceInferrer(model);
-    double inferred = inferrer.inferPreference(user1, "3");
+    double inferred = inferrer.inferPreference("test1", "3");
     assertEquals(2.0, inferred);
   }
 

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarityTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarityTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarityTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarityTest.java Tue Aug  4 00:06:46 2009
@@ -19,105 +19,130 @@
 
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.common.Weighting;
-import org.apache.mahout.cf.taste.impl.model.GenericPreference;
-import org.apache.mahout.cf.taste.impl.model.GenericUser;
 import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.Preference;
-import org.apache.mahout.cf.taste.model.User;
 import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
 
-import java.util.Collections;
-
 /** <p>Tests {@link EuclideanDistanceSimilarity}.</p> */
 public final class EuclideanDistanceSimilarityTest extends SimilarityTestCase {
 
   public void testFullCorrelation1() throws Exception {
-    User user1 = getUser("test1", 3.0, -2.0);
-    User user2 = getUser("test2", 3.0, -2.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -2.0},
+                    {3.0, -2.0},
+            });
+    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(1.0, correlation);
   }
 
   public void testFullCorrelation1Weighted() throws Exception {
-    User user1 = getUser("test1", 3.0, -2.0);
-    User user2 = getUser("test2", 3.0, -2.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -2.0},
+                    {3.0, -2.0},
+            });
+    double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity("test1", "test2");
     assertCorrelationEquals(1.0, correlation);
   }
 
   public void testFullCorrelation2() throws Exception {
-    User user1 = getUser("test1", 3.0, 3.0);
-    User user2 = getUser("test2", 3.0, 3.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, 3.0},
+                    {3.0, 3.0},
+            });
+    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity("test1", "test2");
     assertTrue(Double.isNaN(correlation));
   }
 
   public void testNoCorrelation1() throws Exception {
-    User user1 = getUser("test1", 3.0, -2.0);
-    User user2 = getUser("test2", -3.0, 2.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -2.0},
+                    {-3.0, 2.0},
+            });
+    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(0.424465381883345, correlation);
   }
 
   public void testNoCorrelation1Weighted() throws Exception {
-    User user1 = getUser("test1", 3.0, -2.0);
-    User user2 = getUser("test2", -3.0, 2.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -2.0},
+                    {-3.0, 2.0},
+            });
+    double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity("test1", "test2");
     assertCorrelationEquals(0.8081551272944483, correlation);
   }
 
   public void testNoCorrelation2() throws Exception {
-    Preference pref1 = new GenericPreference(null, "1", 1.0);
-    GenericUser user1 = new GenericUser("test1", Collections.singletonList(pref1));
-    Preference pref2 = new GenericPreference(null, "2", 1.0);
-    GenericUser user2 = new GenericUser("test2", Collections.singletonList(pref2));
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {null, 1.0, null},
+                    {null, null, 1.0},
+            });
+    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity("test1", "test2");
     assertTrue(Double.isNaN(correlation));
   }
 
   public void testNoCorrelation3() throws Exception {
-    User user1 = getUser("test1", 90.0, 80.0, 70.0);
-    User user2 = getUser("test2", 70.0, 80.0, 90.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {90.0, 80.0, 70.0},
+                    {70.0, 80.0, 90.0},
+            });
+    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(0.3606507916004517, correlation);
   }
 
   public void testSimple() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0, 3.0);
-    User user2 = getUser("test2", 2.0, 5.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0, 2.0, 3.0},
+                    {2.0, 5.0, 6.0},
+            });
+    double correlation = new EuclideanDistanceSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(0.5896248568217328, correlation);
   }
 
   public void testSimpleWeighted() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0, 3.0);
-    User user2 = getUser("test2", 2.0, 5.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0, 2.0, 3.0},
+                    {2.0, 5.0, 6.0},
+            });
+    double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity("test1", "test2");
     assertCorrelationEquals(0.8974062142054332, correlation);
   }
 
   public void testFullItemCorrelation1() throws Exception {
-    User user1 = getUser("test1", 3.0, 3.0);
-    User user2 = getUser("test2", -2.0, -2.0);
-    DataModel dataModel = getDataModel(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, 3.0},
+                    {-2.0, -2.0},
+            });
     double correlation =
         new EuclideanDistanceSimilarity(dataModel).itemSimilarity("0", "1");
     assertCorrelationEquals(1.0, correlation);
   }
 
   public void testFullItemCorrelation2() throws Exception {
-    User user1 = getUser("test1", 3.0, 3.0);
-    User user2 = getUser("test2", 3.0, 3.0);
-    DataModel dataModel = getDataModel(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, 3.0},
+                    {3.0, 3.0},
+            });
     double correlation =
         new EuclideanDistanceSimilarity(dataModel).itemSimilarity("0", "1");
     // Yeah, undefined in this case
@@ -125,50 +150,63 @@
   }
 
   public void testNoItemCorrelation1() throws Exception {
-    User user1 = getUser("test1", 3.0, -3.0);
-    User user2 = getUser("test2", -2.0, 2.0);
-    DataModel dataModel = getDataModel(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -3.0},
+                    {-2.0, 2.0},
+            });
     double correlation =
         new EuclideanDistanceSimilarity(dataModel).itemSimilarity("0", "1");
     assertCorrelationEquals(0.424465381883345, correlation);
   }
 
   public void testNoItemCorrelation2() throws Exception {
-    Preference pref1 = new GenericPreference(null, "1", 1.0);
-    GenericUser user1 = new GenericUser("test1", Collections.singletonList(pref1));
-    Preference pref2 = new GenericPreference(null, "2", 1.0);
-    GenericUser user2 = new GenericUser("test2", Collections.singletonList(pref2));
-    DataModel dataModel = getDataModel(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {null, 1.0, null},
+                    {null, null, 1.0},
+            });
     double correlation =
         new EuclideanDistanceSimilarity(dataModel).itemSimilarity("1", "2");
     assertTrue(Double.isNaN(correlation));
   }
 
   public void testNoItemCorrelation3() throws Exception {
-    User user1 = getUser("test1", 90.0, 70.0);
-    User user2 = getUser("test2", 80.0, 80.0);
-    User user3 = getUser("test3", 70.0, 90.0);
-    DataModel dataModel = getDataModel(user1, user2, user3);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {90.0, 70.0},
+                    {80.0, 80.0},
+                    {70.0, 90.0},
+            });
     double correlation =
         new EuclideanDistanceSimilarity(dataModel).itemSimilarity("0", "1");
     assertCorrelationEquals(0.3606507916004517, correlation);
   }
 
   public void testSimpleItem() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0);
-    User user2 = getUser("test2", 2.0, 5.0);
-    User user3 = getUser("test3", 3.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2, user3);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {1.0, 2.0},
+                    {2.0, 5.0},
+                    {3.0, 6.0},
+            });
     double correlation =
         new EuclideanDistanceSimilarity(dataModel).itemSimilarity("0", "1");
     assertCorrelationEquals(0.5896248568217328, correlation);
   }
 
   public void testSimpleItemWeighted() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0);
-    User user2 = getUser("test2", 2.0, 5.0);
-    User user3 = getUser("test3", 3.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2, user3);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {1.0, 2.0},
+                    {2.0, 5.0},
+                    {3.0, 6.0},
+            });
     ItemSimilarity itemSimilarity = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED);
     double correlation = itemSimilarity.itemSimilarity("0", "1");
     assertCorrelationEquals(0.8974062142054332, correlation);

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarityTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarityTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarityTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarityTest.java Tue Aug  4 00:06:46 2009
@@ -17,7 +17,6 @@
 package org.apache.mahout.cf.taste.impl.similarity;
 
 import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.User;
 import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
 
 import java.util.ArrayList;
@@ -46,10 +45,13 @@
   }
 
   public void testFromCorrelation() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0);
-    User user2 = getUser("test2", 2.0, 5.0);
-    User user3 = getUser("test3", 3.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2, user3);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {1.0, 2.0},
+                    {2.0, 5.0},
+                    {3.0, 6.0},
+            });
     ItemSimilarity otherSimilarity = new PearsonCorrelationSimilarity(dataModel);
     ItemSimilarity itemSimilarity = new GenericItemSimilarity(otherSimilarity, dataModel);
     assertCorrelationEquals(1.0, itemSimilarity.itemSimilarity("0", "0"));

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarityTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarityTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarityTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarityTest.java Tue Aug  4 00:06:46 2009
@@ -18,18 +18,20 @@
 package org.apache.mahout.cf.taste.impl.similarity;
 
 import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.User;
 
 /** <p>Tests {@link LogLikelihoodSimilarity}.</p> */
 public final class LogLikelihoodSimilarityTest extends SimilarityTestCase {
 
   public void testCorrelation() throws Exception {
-    User user1 = getUser("test1", 1.0, 1.0);
-    User user2 = getUser("test2", 1.0, null, 1.0);
-    User user3 = getUser("test3", null, null, 1.0, 1.0, 1.0);
-    User user4 = getUser("test4", 1.0, 1.0, 1.0, 1.0, 1.0);
-    User user5 = getUser("test5", null, 1.0, 1.0, 1.0, 1.0);
-    DataModel dataModel = getDataModel(user1, user2, user3, user4, user5);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3", "test4", "test5"},
+            new Double[][] {
+                    {1.0, 1.0},
+                    {1.0, null, 1.0},
+                    {null, null, 1.0, 1.0, 1.0},
+                    {1.0, 1.0, 1.0, 1.0, 1.0},
+                    {null, 1.0, 1.0, 1.0, 1.0},
+            });
 
     double correlation = new LogLikelihoodSimilarity(dataModel).itemSimilarity("1", "0");
     assertCorrelationEquals(0.12160727029227925, correlation);

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarityTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarityTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarityTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarityTest.java Tue Aug  4 00:06:46 2009
@@ -18,106 +18,131 @@
 package org.apache.mahout.cf.taste.impl.similarity;
 
 import org.apache.mahout.cf.taste.common.Weighting;
-import org.apache.mahout.cf.taste.impl.model.GenericPreference;
-import org.apache.mahout.cf.taste.impl.model.GenericUser;
 import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.Preference;
-import org.apache.mahout.cf.taste.model.User;
 import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
 
-import java.util.Collections;
-
 /** <p>Tests {@link PearsonCorrelationSimilarity}.</p> */
 public final class PearsonCorrelationSimilarityTest extends SimilarityTestCase {
 
   public void testFullCorrelation1() throws Exception {
-    User user1 = getUser("test1", 3.0, -2.0);
-    User user2 = getUser("test2", 3.0, -2.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -2.0},
+                    {3.0, -2.0},
+            });
+    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(1.0, correlation);
   }
 
   public void testFullCorrelation1Weighted() throws Exception {
-    User user1 = getUser("test1", 3.0, -2.0);
-    User user2 = getUser("test2", 3.0, -2.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -2.0},
+                    {3.0, -2.0},
+            });
+    double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity("test1", "test2");
     assertCorrelationEquals(1.0, correlation);
   }
 
   public void testFullCorrelation2() throws Exception {
-    User user1 = getUser("test1", 3.0, 3.0);
-    User user2 = getUser("test2", 3.0, 3.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, 3.0},
+                    {3.0, 3.0},
+            });
+    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     // Yeah, undefined in this case
     assertTrue(Double.isNaN(correlation));
   }
 
   public void testNoCorrelation1() throws Exception {
-    User user1 = getUser("test1", 3.0, -2.0);
-    User user2 = getUser("test2", -3.0, 2.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -2.0},
+                    {-3.0, 2.0},
+            });
+    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(-1.0, correlation);
   }
 
   public void testNoCorrelation1Weighted() throws Exception {
-    User user1 = getUser("test1", 3.0, -2.0);
-    User user2 = getUser("test2", -3.0, 2.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -2.0},
+                    {-3.0, 2.0},
+            });
+    double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity("test1", "test2");
     assertCorrelationEquals(-1.0, correlation);
   }
 
   public void testNoCorrelation2() throws Exception {
-    Preference pref1 = new GenericPreference(null, "1", 1.0);
-    GenericUser user1 = new GenericUser("test1", Collections.singletonList(pref1));
-    Preference pref2 = new GenericPreference(null, "2", 1.0);
-    GenericUser user2 = new GenericUser("test2", Collections.singletonList(pref2));
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {null, 1.0, null},
+                    {null, null, 1.0},
+            });
+    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     assertTrue(Double.isNaN(correlation));
   }
 
   public void testNoCorrelation3() throws Exception {
-    User user1 = getUser("test1", 90.0, 80.0, 70.0);
-    User user2 = getUser("test2", 70.0, 80.0, 90.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {90.0, 80.0, 70.0},
+                    {70.0, 80.0, 90.0},
+            });
+    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(-1.0, correlation);
   }
 
   public void testSimple() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0, 3.0);
-    User user2 = getUser("test2", 2.0, 5.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0, 2.0, 3.0},
+                    {2.0, 5.0, 6.0},
+            });
+    double correlation = new PearsonCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(0.9607689228305227, correlation);
   }
 
   public void testSimpleWeighted() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0, 3.0);
-    User user2 = getUser("test2", 2.0, 5.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0, 2.0, 3.0},
+                    {2.0, 5.0, 6.0},
+            });
+    double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).userSimilarity("test1", "test2");
     assertCorrelationEquals(0.9901922307076306, correlation);
   }
 
   public void testFullItemCorrelation1() throws Exception {
-    User user1 = getUser("test1", 3.0, 3.0);
-    User user2 = getUser("test2", -2.0, -2.0);
-    DataModel dataModel = getDataModel(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, 3.0},
+                    {-2.0, -2.0},
+            });
     double correlation =
         new PearsonCorrelationSimilarity(dataModel).itemSimilarity("0", "1");
     assertCorrelationEquals(1.0, correlation);
   }
 
   public void testFullItemCorrelation2() throws Exception {
-    User user1 = getUser("test1", 3.0, 3.0);
-    User user2 = getUser("test2", 3.0, 3.0);
-    DataModel dataModel = getDataModel(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, 3.0},
+                    {3.0, 3.0},
+            });
     double correlation =
         new PearsonCorrelationSimilarity(dataModel).itemSimilarity("0", "1");
     // Yeah, undefined in this case
@@ -125,50 +150,63 @@
   }
 
   public void testNoItemCorrelation1() throws Exception {
-    User user1 = getUser("test1", 3.0, -3.0);
-    User user2 = getUser("test2", -2.0, 2.0);
-    DataModel dataModel = getDataModel(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {3.0, -3.0},
+                    {2.0, -2.0},
+            });
     double correlation =
         new PearsonCorrelationSimilarity(dataModel).itemSimilarity("0", "1");
     assertCorrelationEquals(-1.0, correlation);
   }
 
   public void testNoItemCorrelation2() throws Exception {
-    Preference pref1 = new GenericPreference(null, "1", 1.0);
-    GenericUser user1 = new GenericUser("test1", Collections.singletonList(pref1));
-    Preference pref2 = new GenericPreference(null, "2", 1.0);
-    GenericUser user2 = new GenericUser("test2", Collections.singletonList(pref2));
-    DataModel dataModel = getDataModel(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {null, 1.0, null},
+                    {null, null, 1.0},
+            });
     double correlation =
         new PearsonCorrelationSimilarity(dataModel).itemSimilarity("1", "2");
     assertTrue(Double.isNaN(correlation));
   }
 
   public void testNoItemCorrelation3() throws Exception {
-    User user1 = getUser("test1", 90.0, 70.0);
-    User user2 = getUser("test2", 80.0, 80.0);
-    User user3 = getUser("test3", 70.0, 90.0);
-    DataModel dataModel = getDataModel(user1, user2, user3);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {90.0, 70.0},
+                    {80.0, 80.0},
+                    {70.0, 90.0},
+            });
     double correlation =
         new PearsonCorrelationSimilarity(dataModel).itemSimilarity("0", "1");
     assertCorrelationEquals(-1.0, correlation);
   }
 
   public void testSimpleItem() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0);
-    User user2 = getUser("test2", 2.0, 5.0);
-    User user3 = getUser("test3", 3.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2, user3);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {1.0, 2.0},
+                    {2.0, 5.0},
+                    {3.0, 6.0},
+            });
     double correlation =
         new PearsonCorrelationSimilarity(dataModel).itemSimilarity("0", "1");
     assertCorrelationEquals(0.9607689228305227, correlation);
   }
 
   public void testSimpleItemWeighted() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0);
-    User user2 = getUser("test2", 2.0, 5.0);
-    User user3 = getUser("test3", 3.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2, user3);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3"},
+            new Double[][] {
+                    {1.0, 2.0},
+                    {2.0, 5.0},
+                    {3.0, 6.0},
+            });
     ItemSimilarity itemSimilarity = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED);
     double correlation = itemSimilarity.itemSimilarity("0", "1");
     assertCorrelationEquals(0.9901922307076306, correlation);

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarityTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarityTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarityTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarityTest.java Tue Aug  4 00:06:46 2009
@@ -19,40 +19,51 @@
 
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.User;
 
 /** <p>Tests {@link SpearmanCorrelationSimilarity}.</p> */
 public final class SpearmanCorrelationSimilarityTest extends SimilarityTestCase {
 
   public void testFullCorrelation1() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0, 3.0);
-    User user2 = getUser("test2", 1.0, 2.0, 3.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new SpearmanCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0, 2.0, 3.0},
+                    {1.0, 2.0, 3.0},
+            });
+    double correlation = new SpearmanCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(1.0, correlation);
   }
 
   public void testFullCorrelation2() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0, 3.0);
-    User user2 = getUser("test2", 4.0, 5.0, 6.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new SpearmanCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0, 2.0, 3.0},
+                    {4.0, 5.0, 6.0},
+            });
+    double correlation = new SpearmanCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(1.0, correlation);
   }
 
   public void testAnticorrelation() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0, 3.0);
-    User user2 = getUser("test2", 3.0, 2.0, 1.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new SpearmanCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0, 2.0, 3.0},
+                    {3.0, 2.0, 1.0},
+            });
+    double correlation = new SpearmanCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(-1.0, correlation);
   }
 
   public void testSimple() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0, 3.0);
-    User user2 = getUser("test2", 2.0, 3.0, 1.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new SpearmanCorrelationSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0, 2.0, 3.0},
+                    {2.0, 3.0, 1.0},
+            });
+    double correlation = new SpearmanCorrelationSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(-0.5, correlation);
   }
 

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarityTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarityTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarityTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarityTest.java Tue Aug  4 00:06:46 2009
@@ -18,64 +18,62 @@
 package org.apache.mahout.cf.taste.impl.similarity;
 
 import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.User;
 
 /** <p>Tests {@link TanimotoCoefficientSimilarity}.</p> */
 public final class TanimotoCoefficientSimilarityTest extends SimilarityTestCase {
 
-  public void testNoCorrelation1() throws Exception {
-    User user1 = getUser("test1");
-    User user2 = getUser("test2");
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity(user1, user2);
-    assertTrue(Double.isNaN(correlation));
-  }
-
-  public void testNoCorrelation2() throws Exception {
-    User user1 = getUser("test1");
-    User user2 = getUser("test2", 1.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity(user1, user2);
-    assertCorrelationEquals(0.0, correlation);
-  }
-
   public void testNoCorrelation() throws Exception {
-    User user1 = getUser("test1", null, 2.0, 3.0);
-    User user2 = getUser("test2", 1.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {null, 2.0, 3.0},
+                    {1.0},
+            });
+    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(0.0, correlation);
   }
 
   public void testFullCorrelation1() throws Exception {
-    User user1 = getUser("test1", 1.0);
-    User user2 = getUser("test2", 1.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0},
+                    {1.0},
+            });
+    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(1.0, correlation);
   }
 
   public void testFullCorrelation2() throws Exception {
-    User user1 = getUser("test1", 1.0, 2.0, 3.0);
-    User user2 = getUser("test2", 1.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {1.0, 2.0, 3.0},
+                    {1.0},
+            });
+    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity("test1", "test2");
     assertCorrelationEquals(0.3333333333333333, correlation);
   }
 
   public void testCorrelation1() throws Exception {
-    User user1 = getUser("test1", null, 2.0, 3.0);
-    User user2 = getUser("test2", 1.0, 1.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {null, 2.0, 3.0},
+                    {1.0, 1.0},
+            });
+    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity("test1", "test2");
     assertEquals(0.3333333333333333, correlation);
   }
 
   public void testCorrelation2() throws Exception {
-    User user1 = getUser("test1", null, 2.0, 3.0, 1.0);
-    User user2 = getUser("test2", 1.0, 1.0, null, 0.0);
-    DataModel dataModel = getDataModel(user1, user2);
-    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity(user1, user2);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2"},
+            new Double[][] {
+                    {null, 2.0, 3.0, 1.0},
+                    {1.0, 1.0, null, 0.0},
+            });
+    double correlation = new TanimotoCoefficientSimilarity(dataModel).userSimilarity("test1", "test2");
     assertEquals(0.5, correlation);
   }
 

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/InverseUserFrequencyTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/InverseUserFrequencyTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/InverseUserFrequencyTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/InverseUserFrequencyTest.java Tue Aug  4 00:06:46 2009
@@ -17,29 +17,30 @@
 
 package org.apache.mahout.cf.taste.impl.transforms;
 
-import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
+import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.model.Preference;
-import org.apache.mahout.cf.taste.model.User;
-
-import java.util.ArrayList;
-import java.util.List;
+import org.apache.mahout.cf.taste.model.PreferenceArray;
 
 /** <p>Tests {@link InverseUserFrequency}.</p> */
 public final class InverseUserFrequencyTest extends TransformTestCase {
 
   public void testIUF() throws Exception {
-    List<User> users = new ArrayList<User>(5);
-    users.add(getUser("test1", 0.1));
-    users.add(getUser("test2", 0.2, 0.3));
-    users.add(getUser("test3", 0.4, 0.5, 0.6));
-    users.add(getUser("test4", 0.7, 0.8, 0.9, 1.0));
-    users.add(getUser("test5", 1.0, 1.0, 1.0, 1.0, 1.0));
-    GenericDataModel dummy = new GenericDataModel(users);
-    InverseUserFrequency iuf = new InverseUserFrequency(dummy, 10.0);
+    DataModel dataModel = getDataModel(
+            new Comparable<?>[] {"test1", "test2", "test3", "test4", "test5"},
+            new Double[][] {
+                    {0.1},
+                    {0.2, 0.3},
+                    {0.4, 0.5, 0.6},
+                    {0.7, 0.8, 0.9, 1.0},
+                    {1.0, 1.0, 1.0, 1.0, 1.0},
+            });
+
+    InverseUserFrequency iuf = new InverseUserFrequency(dataModel, 10.0);
+
+    PreferenceArray user5Prefs = dataModel.getPreferencesFromUser("test5");
 
-    User user = dummy.getUser("test5");
     for (int i = 0; i < 5; i++) {
-      Preference pref = user.getPreferenceFor(String.valueOf(i));
+      Preference pref = user5Prefs.get(i);
       assertNotNull(pref);
       assertEquals(Math.log(5.0 / (double) (5 - i)) / Math.log(iuf.getLogBase()),
           iuf.getTransformedValue(pref),

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/TransformTestCase.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/TransformTestCase.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/TransformTestCase.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/TransformTestCase.java Tue Aug  4 00:06:46 2009
@@ -17,15 +17,16 @@
 
 package org.apache.mahout.cf.taste.impl.transforms;
 
+import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
+import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.model.Preference;
-import org.apache.mahout.cf.taste.model.User;
 
 abstract class TransformTestCase extends TasteTestCase {
 
-  static void assertPrefsEquals(User user, double... expected) {
+  static void assertPrefsEquals(DataModel dataModel, Comparable<?> userID, double... expected) throws TasteException {
     int i = 0;
-    for (Preference pref : user.getPreferences()) {
+    for (Preference pref : dataModel.getPreferencesFromUser(userID)) {
       assertEquals(expected[i], pref.getValue());
       i++;
     }

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/ZScoreTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/ZScoreTest.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/ZScoreTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/transforms/ZScoreTest.java Tue Aug  4 00:06:46 2009
@@ -17,44 +17,40 @@
 
 package org.apache.mahout.cf.taste.impl.transforms;
 
-import org.apache.mahout.cf.taste.model.User;
+import org.apache.mahout.cf.taste.impl.model.GenericPreference;
+import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.transforms.PreferenceTransform;
 
 /** <p>Tests {@link ZScore}.</p> */
 public final class ZScoreTest extends TransformTestCase {
 
   public void testOnePref() throws Exception {
-    User user = getUser("test", 1.0);
-    PreferenceTransform zScore = new ZScore();
-    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("0")), EPSILON);
+    DataModel dataModel = getDataModel(new Comparable<?>[] {"test1"}, new Double[][] {{1.0}});
+    PreferenceTransform zScore = new ZScore(dataModel);
+    assertEquals(0.0, zScore.getTransformedValue(new GenericPreference("test1", "0", 1.0f)), EPSILON);
   }
 
   public void testAllSame() throws Exception {
-    User user = getUser("test", 1.0, 1.0, 1.0);
-    PreferenceTransform zScore = new ZScore();
-    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("0")), EPSILON);
-    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("1")), EPSILON);
-    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("2")), EPSILON);
+    DataModel dataModel = getDataModel(new Comparable<?>[] {"test1"}, new Double[][] {{1.0,1.0,1.0}});
+    PreferenceTransform zScore = new ZScore(dataModel);
+    assertEquals(0.0, zScore.getTransformedValue(new GenericPreference("test1", "0", 1.0f)), EPSILON);
+    assertEquals(0.0, zScore.getTransformedValue(new GenericPreference("test1", "1", 1.0f)), EPSILON);
+    assertEquals(0.0, zScore.getTransformedValue(new GenericPreference("test1", "2", 1.0f)), EPSILON);
   }
 
   public void testStdev() throws Exception {
-    User user = getUser("test", -1.0, -2.0);
-    PreferenceTransform zScore = new ZScore();
-    assertEquals(0.707107, zScore.getTransformedValue(user.getPreferenceFor("0")), EPSILON);
-    assertEquals(-0.707107, zScore.getTransformedValue(user.getPreferenceFor("1")), EPSILON);
+    DataModel dataModel = getDataModel(new Comparable<?>[] {"test1"}, new Double[][] {{-1.0,-2.0}});
+    PreferenceTransform zScore = new ZScore(dataModel);
+    assertEquals(0.707107, zScore.getTransformedValue(new GenericPreference("test1", "0", -1.0f)), EPSILON);
+    assertEquals(-0.707107, zScore.getTransformedValue(new GenericPreference("test1", "1", -2.0f)), EPSILON);
   }
 
   public void testExample() throws Exception {
-    User user = getUser("test", 5.0, 7.0, 9.0);
-    PreferenceTransform zScore = new ZScore();
-    assertEquals(-1.0, zScore.getTransformedValue(user.getPreferenceFor("0")), EPSILON);
-    assertEquals(0.0, zScore.getTransformedValue(user.getPreferenceFor("1")), EPSILON);
-    assertEquals(1.0, zScore.getTransformedValue(user.getPreferenceFor("2")), EPSILON);
-  }
-
-  public void testRefresh() {
-    // Make sure this doesn't throw an exception
-    new ZScore().refresh(null);
+    DataModel dataModel = getDataModel(new Comparable<?>[] {"test1"}, new Double[][] {{5.0, 7.0, 9.0}});
+    PreferenceTransform zScore = new ZScore(dataModel);
+    assertEquals(-1.0, zScore.getTransformedValue(new GenericPreference("test1", "0", 5.0f)), EPSILON);
+    assertEquals(0.0, zScore.getTransformedValue(new GenericPreference("test1", "1", 7.0f)), EPSILON);
+    assertEquals(1.0, zScore.getTransformedValue(new GenericPreference("test1", "2", 9.0f)), EPSILON);
   }
 
 }

Propchange: lucene/mahout/trunk/examples/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Aug  4 00:06:46 2009
@@ -1,11 +1,10 @@
-target
-build
-dist
+work
+.classpath
+.settings
 input
+build
 output
+target
 temp
-work
-*.iml
-.settings
-.classpath
 .project
+dist

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJB.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJB.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJB.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJB.java Tue Aug  4 00:06:46 2009
@@ -51,9 +51,9 @@
   double estimatePreference(Object userID, Object itemID) throws TasteException, RemoteException;
 
   /**
-   * @see org.apache.mahout.cf.taste.recommender.Recommender#setPreference(Comparable, Comparable, double)
+   * @see org.apache.mahout.cf.taste.recommender.Recommender#setPreference(Comparable, Comparable, float)
    */
-  void setPreference(Object userID, Object itemID, double value)
+  void setPreference(Object userID, Object itemID, float value)
           throws TasteException, RemoteException;
 
   /**

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJBBean.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJBBean.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJBBean.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJBBean.java Tue Aug  4 00:06:46 2009
@@ -57,7 +57,7 @@
     return recommender.estimatePreference(userID, itemID);
   }
 
-  public void setPreference(Comparable<?> userID, Comparable<?> itemID, double value) throws TasteException {
+  public void setPreference(Comparable<?> userID, Comparable<?> itemID, float value) throws TasteException {
     recommender.setPreference(userID, itemID, value);
   }
 

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJBLocal.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJBLocal.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJBLocal.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/ejb/RecommenderEJBLocal.java Tue Aug  4 00:06:46 2009
@@ -49,9 +49,9 @@
   double estimatePreference(Object userID, Object itemID) throws TasteException;
 
   /**
-   * @see org.apache.mahout.cf.taste.recommender.Recommender#setPreference(Comparable, Comparable, double)
+   * @see org.apache.mahout.cf.taste.recommender.Recommender#setPreference(Comparable, Comparable, float)
    */
-  void setPreference(Object userID, Object itemID, double value) throws TasteException;
+  void setPreference(Object userID, Object itemID, float value) throws TasteException;
 
   /**
    * @see org.apache.mahout.cf.taste.recommender.Recommender#removePreference(Comparable, Comparable)

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingDataModel.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingDataModel.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingDataModel.java Tue Aug  4 00:06:46 2009
@@ -17,23 +17,19 @@
 
 package org.apache.mahout.cf.taste.example.bookcrossing;
 
+import org.apache.mahout.cf.taste.example.grouplens.GroupLensDataModel;
 import org.apache.mahout.cf.taste.impl.common.FastMap;
 import org.apache.mahout.cf.taste.impl.common.FileLineIterable;
 import org.apache.mahout.cf.taste.impl.common.IOUtils;
 import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
-import org.apache.mahout.cf.taste.model.User;
-import org.apache.mahout.cf.taste.model.Preference;
-import org.apache.mahout.cf.taste.example.grouplens.GroupLensDataModel;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.io.OutputStreamWriter;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.List;
+import java.io.PrintWriter;
 import java.nio.charset.Charset;
+import java.util.Map;
 
 public final class BookCrossingDataModel extends FileDataModel {
 
@@ -121,29 +117,6 @@
     }
     return result;
   }
-  
-  @Override
-  protected User buildUser(String id, List<Preference> prefs) {
-    String[] userData = userDataMap.get(id);
-    if (userData == null) {
-      throw new NoSuchElementException();
-    }
-    String location = userData[0];
-    String[] locationTokens = location.split(",");
-    for (int i = 0; i < locationTokens.length; i++) {
-      if (locationTokens[i] != null) {
-        locationTokens[i] = locationTokens[i].trim();
-        if (locationTokens[i].length() == 0) {
-          locationTokens[i] = null;
-        }
-      }
-    }
-    String city = locationTokens[0];
-    String state = locationTokens.length > 1 ? locationTokens[1] : null;
-    String country = locationTokens.length > 2 ? locationTokens[2] : null;
-    Integer age = userData[1] == null ? null : Integer.valueOf(userData[1]);
-    return new BookCrossingUser(id, prefs, city, state, country, age);
-  }
 
   private static File convertBCFile(File originalFile) throws IOException {
     File resultFile = new File(new File(System.getProperty("java.io.tmpdir")), "taste.bookcrossing.txt");

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingRecommender.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingRecommender.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingRecommender.java Tue Aug  4 00:06:46 2009
@@ -19,14 +19,15 @@
 
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
+import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood;
 import org.apache.mahout.cf.taste.impl.recommender.CachingRecommender;
 import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender;
-import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood;
+import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
 import org.apache.mahout.cf.taste.model.DataModel;
+import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
 import org.apache.mahout.cf.taste.recommender.RecommendedItem;
 import org.apache.mahout.cf.taste.recommender.Recommender;
 import org.apache.mahout.cf.taste.recommender.Rescorer;
-import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
 import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 
 import java.util.Collection;
@@ -41,7 +42,7 @@
   private final Recommender recommender;
 
   public BookCrossingRecommender(DataModel dataModel, BookCrossingDataModel bcModel) throws TasteException {
-    UserSimilarity similarity = new GeoUserSimilarity(bcModel);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(bcModel);
     UserNeighborhood neighborhood = new NearestNUserNeighborhood(5, similarity, dataModel);
     recommender = new CachingRecommender(new GenericUserBasedRecommender(dataModel, neighborhood, similarity));
   }
@@ -58,12 +59,12 @@
   }
 
   @Override
-  public double estimatePreference(Comparable<?> userID, Comparable<?> itemID) throws TasteException {
+  public float estimatePreference(Comparable<?> userID, Comparable<?> itemID) throws TasteException {
     return recommender.estimatePreference(userID, itemID);
   }
 
   @Override
-  public void setPreference(Comparable<?> userID, Comparable<?> itemID, double value) throws TasteException {
+  public void setPreference(Comparable<?> userID, Comparable<?> itemID, float value) throws TasteException {
     recommender.setPreference(userID, itemID, value);
   }
 

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensDataModel.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensDataModel.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensDataModel.java Tue Aug  4 00:06:46 2009
@@ -26,8 +26,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.PrintWriter;
 import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
 import java.nio.charset.Charset;
 
 public final class GroupLensDataModel extends FileDataModel {

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensRecommender.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensRecommender.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensRecommender.java Tue Aug  4 00:06:46 2009
@@ -68,12 +68,12 @@
   }
 
   @Override
-  public double estimatePreference(Comparable<?> userID, Comparable<?> itemID) throws TasteException {
+  public float estimatePreference(Comparable<?> userID, Comparable<?> itemID) throws TasteException {
     return recommender.estimatePreference(userID, itemID);
   }
 
   @Override
-  public void setPreference(Comparable<?> userID, Comparable<?> itemID, double value) throws TasteException {
+  public void setPreference(Comparable<?> userID, Comparable<?> itemID, float value) throws TasteException {
     recommender.setPreference(userID, itemID, value);
   }
 

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/jester/JesterDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/jester/JesterDataModel.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/jester/JesterDataModel.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/jester/JesterDataModel.java Tue Aug  4 00:06:46 2009
@@ -18,15 +18,16 @@
 package org.apache.mahout.cf.taste.example.jester;
 
 import org.apache.mahout.cf.taste.example.grouplens.GroupLensDataModel;
-import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
 import org.apache.mahout.cf.taste.impl.model.GenericPreference;
+import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
 import org.apache.mahout.cf.taste.model.Preference;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
-import java.util.ArrayList;
 
 public final class JesterDataModel extends FileDataModel {
 
@@ -51,14 +52,14 @@
   }
 
   @Override
-  protected void processLine(String line, Map<String, List<Preference>> data) {
+  protected void processLine(String line, Map<Comparable<?>, Collection<Preference>> data, char delimiter) {
     String userID = String.valueOf(userBeingRead);
     String[] jokePrefs = line.split(",");
     List<Preference> prefs = new ArrayList<Preference>(101);
     for (int itemIDNum = 1; itemIDNum < jokePrefs.length; itemIDNum++) { // yes skip first one, just a count
       String jokePref = jokePrefs[itemIDNum];
       if (!"99".equals(jokePref)) {
-        double jokePrefValue = Double.parseDouble(jokePref);        
+        float jokePrefValue = Float.parseFloat(jokePref);
         String itemID = String.valueOf(itemIDNum);
         prefs.add(new GenericPreference(null, itemID, jokePrefValue));
       }

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/jester/JesterRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/jester/JesterRecommender.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/jester/JesterRecommender.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/jester/JesterRecommender.java Tue Aug  4 00:06:46 2009
@@ -53,12 +53,12 @@
   }
 
   @Override
-  public double estimatePreference(Comparable<?> userID, Comparable<?> itemID) throws TasteException {
+  public float estimatePreference(Comparable<?> userID, Comparable<?> itemID) throws TasteException {
     return recommender.estimatePreference(userID, itemID);
   }
 
   @Override
-  public void setPreference(Comparable<?> userID, Comparable<?> itemID, double value) throws TasteException {
+  public void setPreference(Comparable<?> userID, Comparable<?> itemID, float value) throws TasteException {
     recommender.setPreference(userID, itemID, value);
   }
 

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixDataModel.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixDataModel.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixDataModel.java Tue Aug  4 00:06:46 2009
@@ -17,28 +17,28 @@
 
 package org.apache.mahout.cf.taste.example.netflix;
 
-import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.common.Refreshable;
-import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
-import org.apache.mahout.cf.taste.impl.model.GenericPreference;
-import org.apache.mahout.cf.taste.impl.model.GenericUser;
+import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.FastMap;
+import org.apache.mahout.cf.taste.impl.common.FastSet;
 import org.apache.mahout.cf.taste.impl.common.FileLineIterable;
+import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
+import org.apache.mahout.cf.taste.impl.model.GenericPreference;
 import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.model.Preference;
-import org.apache.mahout.cf.taste.model.User;
-import org.slf4j.LoggerFactory;
+import org.apache.mahout.cf.taste.model.PreferenceArray;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>This is a {@link DataModel} that reads the Netflix data set, as represented in its
@@ -71,7 +71,7 @@
 		log.info("Creating NetflixDataModel for directory: {}", dataDirectory);
 
 		log.info("Reading preference data...");
-		List<User> users = readUsers(dataDirectory);
+		Map<Comparable<?>, PreferenceArray> users = readUsers(dataDirectory);
 
 		log.info("Creating delegate DataModel...");
 		delegate = new GenericDataModel(users);
@@ -90,8 +90,8 @@
 		return movies;
 	}
 
-	private List<User> readUsers(File dataDirectory) throws IOException {
-		Map<Integer, List<Preference>> userIDPrefMap = new FastMap<Integer, List<Preference>>();
+	private Map<Comparable<?>, PreferenceArray> readUsers(File dataDirectory) throws IOException {
+		Map<Comparable<?>, Collection<Preference>> userIDPrefMap = new FastMap<Comparable<?>, Collection<Preference>>();
 
 		int counter = 0;
 		FilenameFilter filenameFilter = new MovieFilenameFilter();
@@ -108,8 +108,8 @@
 				int firstComma = line.indexOf((int) ',');
 				Integer userID = Integer.valueOf(line.substring(0, firstComma));
 				int secondComma = line.indexOf((int) ',', firstComma + 1);
-				double rating = Double.parseDouble(line.substring(firstComma + 1, secondComma));
-				List<Preference> userPrefs = userIDPrefMap.get(userID);
+				float rating = Float.parseFloat(line.substring(firstComma + 1, secondComma));
+				Collection<Preference> userPrefs = userIDPrefMap.get(userID);
 				if (userPrefs == null) {
 					userPrefs = new ArrayList<Preference>();
 					userIDPrefMap.put(userID, userPrefs);
@@ -118,39 +118,40 @@
 			}
 		}
 
-		List<User> users = new ArrayList<User>(userIDPrefMap.size());
-		for (Map.Entry<Integer, List<Preference>> entry : userIDPrefMap.entrySet()) {
-			users.add(new GenericUser(entry.getKey(), entry.getValue()));
-		}
-		return users;
+		return GenericDataModel.toPrefArrayValues(userIDPrefMap, true);
 	}
 
 	@Override
-  public Iterable<? extends User> getUsers() throws TasteException {
-		return delegate.getUsers();
+  public Iterable<Comparable<?>> getUserIDs() throws TasteException {
+		return delegate.getUserIDs();
 	}
 
 	@Override
-  public User getUser(Comparable<?> id) throws TasteException {
-		return delegate.getUser(id);
+  public PreferenceArray getPreferencesFromUser(Comparable<?> id) throws TasteException {
+		return delegate.getPreferencesFromUser(id);
 	}
 
-	@Override
+  @Override
+  public FastSet<Comparable<?>> getItemIDsFromUser(Comparable<?> userID) throws TasteException {
+    return delegate.getItemIDsFromUser(userID);
+  }
+
+  @Override
   public Iterable<Comparable<?>> getItemIDs() throws TasteException {
 		return delegate.getItemIDs();
 	}
 
 	@Override
-  public Iterable<? extends Preference> getPreferencesForItem(Comparable<?> itemID) throws TasteException {
+  public PreferenceArray getPreferencesForItem(Comparable<?> itemID) throws TasteException {
 		return delegate.getPreferencesForItem(itemID);
 	}
 
-	@Override
-  public Preference[] getPreferencesForItemAsArray(Comparable<?> itemID) throws TasteException {
-		return delegate.getPreferencesForItemAsArray(itemID);
-	}
+  @Override
+  public Float getPreferenceValue(Comparable<?> userID, Comparable<?> itemID) throws TasteException {
+    return delegate.getPreferenceValue(userID, itemID);
+  }
 
-	@Override
+  @Override
   public int getNumItems() throws TasteException {
 		return delegate.getNumItems();
 	}
@@ -166,7 +167,7 @@
   }
 
   @Override
-  public void setPreference(Comparable<?> userID, Comparable<?> itemID, double value) {
+  public void setPreference(Comparable<?> userID, Comparable<?> itemID, float value) {
 		throw new UnsupportedOperationException();
 	}
 

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixFileDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixFileDataModel.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixFileDataModel.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixFileDataModel.java Tue Aug  4 00:06:46 2009
@@ -17,20 +17,21 @@
 
 package org.apache.mahout.cf.taste.example.netflix;
 
-import org.apache.mahout.cf.taste.model.DataModel;
-import org.apache.mahout.cf.taste.model.User;
-import org.apache.mahout.cf.taste.model.Preference;
 import org.apache.mahout.cf.taste.common.Refreshable;
+import org.apache.mahout.cf.taste.impl.common.FastSet;
 import org.apache.mahout.cf.taste.impl.common.FileLineIterable;
-import org.apache.mahout.cf.taste.impl.common.ArrayIterator;
+import org.apache.mahout.cf.taste.impl.model.GenericItemPreferenceArray;
 import org.apache.mahout.cf.taste.impl.model.GenericPreference;
+import org.apache.mahout.cf.taste.model.DataModel;
+import org.apache.mahout.cf.taste.model.Preference;
+import org.apache.mahout.cf.taste.model.PreferenceArray;
 
-import java.util.Collection;
-import java.util.List;
-import java.util.ArrayList;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 
 public final class NetflixFileDataModel implements DataModel {
 
@@ -50,12 +51,12 @@
   }
 
   @Override
-  public Iterable<? extends User> getUsers() {
+  public Iterable<Comparable<?>> getUserIDs() {
     throw new UnsupportedOperationException(); // TODO
   }
 
   @Override
-  public User getUser(Comparable<?> id) {
+  public PreferenceArray getPreferencesFromUser(Comparable<?> id) {
     throw new UnsupportedOperationException(); // TODO
   }
 
@@ -65,12 +66,17 @@
   }
 
   @Override
-  public Iterable<? extends Preference> getPreferencesForItem(Comparable<?> itemID) {
-    return new ArrayIterator<Preference>(getPreferencesForItemAsArray(itemID));
+  public FastSet<Comparable<?>> getItemIDsFromUser(Comparable<?> userID) {
+    throw new UnsupportedOperationException(); // TODO
+  }
+
+  @Override
+  public Float getPreferenceValue(Comparable<?> userID, Comparable<?> itemID) {
+    throw new UnsupportedOperationException(); // TODO
   }
 
   @Override
-  public Preference[] getPreferencesForItemAsArray(Comparable<?> itemID) {
+  public PreferenceArray getPreferencesForItem(Comparable<?> itemID) {
     StringBuilder itemIDPadded = new StringBuilder(5);
     itemIDPadded.append(itemID);
     while (itemIDPadded.length() < 5) {
@@ -82,10 +88,10 @@
       int firstComma = line.indexOf((int) ',');
       Integer userID = Integer.valueOf(line.substring(0, firstComma));
       int secondComma = line.indexOf((int) ',', firstComma + 1);
-      double rating = Double.parseDouble(line.substring(firstComma + 1, secondComma));
-      prefs.add(new GenericPreference(getUser(userID), itemID, rating));
+      float rating = Float.parseFloat(line.substring(firstComma + 1, secondComma));
+      prefs.add(new GenericPreference(userID, itemID, rating));
     }
-    return prefs.toArray(new Preference[prefs.size()]);
+    return new GenericItemPreferenceArray(prefs);
   }
 
   @Override
@@ -107,7 +113,7 @@
    * @throws UnsupportedOperationException
    */
   @Override
-  public void setPreference(Comparable<?> userID, Comparable<?> itemID, double value) {
+  public void setPreference(Comparable<?> userID, Comparable<?> itemID, float value) {
     throw new UnsupportedOperationException();
   }
 

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixRecommender.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixRecommender.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixRecommender.java Tue Aug  4 00:06:46 2009
@@ -48,12 +48,12 @@
   }
 
   @Override
-  public double estimatePreference(Comparable<?> userID, Comparable<?> itemID) throws TasteException {
+  public float estimatePreference(Comparable<?> userID, Comparable<?> itemID) throws TasteException {
     return recommender.estimatePreference(userID, itemID);
   }
 
   @Override
-  public void setPreference(Comparable<?> userID, Comparable<?> itemID, double value) throws TasteException {
+  public void setPreference(Comparable<?> userID, Comparable<?> itemID, float value) throws TasteException {
     recommender.setPreference(userID, itemID, value);
   }
 

Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixRecommenderEvaluatorRunner.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixRecommenderEvaluatorRunner.java?rev=800634&r1=800633&r2=800634&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixRecommenderEvaluatorRunner.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/NetflixRecommenderEvaluatorRunner.java Tue Aug  4 00:06:46 2009
@@ -24,8 +24,8 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
 import java.io.File;
+import java.io.IOException;
 
 public final class NetflixRecommenderEvaluatorRunner {
 



Mime
View raw message