mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r691302 [2/2] - in /lucene/mahout/trunk/core/src: main/java/org/apache/mahout/cf/taste/correlation/ main/java/org/apache/mahout/cf/taste/impl/correlation/ main/java/org/apache/mahout/cf/taste/impl/neighborhood/ main/java/org/apache/mahout/c...
Date Tue, 02 Sep 2008 16:22:49 GMT
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/LoadTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/LoadTest.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/LoadTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/LoadTest.java Tue Sep  2 09:22:47 2008
@@ -19,10 +19,10 @@
 
 import junit.textui.TestRunner;
 import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.correlation.ItemCorrelation;
-import org.apache.mahout.cf.taste.correlation.UserCorrelation;
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
+import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 import org.apache.mahout.cf.taste.impl.common.RandomUtils;
-import org.apache.mahout.cf.taste.impl.correlation.PearsonCorrelation;
+import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
 import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
 import org.apache.mahout.cf.taste.impl.model.GenericItem;
 import org.apache.mahout.cf.taste.impl.model.GenericPreference;
@@ -78,17 +78,17 @@
 
   public void testItemLoad() throws Exception {
     DataModel model = createModel();
-    ItemCorrelation itemCorrelation = new PearsonCorrelation(model);
-    Recommender recommender = new CachingRecommender(new GenericItemBasedRecommender(model, itemCorrelation));
+    ItemSimilarity itemSimilarity = new PearsonCorrelationSimilarity(model);
+    Recommender recommender = new CachingRecommender(new GenericItemBasedRecommender(model, itemSimilarity));
     doTestLoad(recommender, 240);
   }
 
   public void testUserLoad() throws Exception {
     DataModel model = createModel();
-    UserCorrelation userCorrelation = new PearsonCorrelation(model);
-    UserNeighborhood neighborhood = new NearestNUserNeighborhood(10, userCorrelation, model);
+    UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model);
+    UserNeighborhood neighborhood = new NearestNUserNeighborhood(10, userSimilarity, model);
     Recommender recommender =
-            new CachingRecommender(new GenericUserBasedRecommender(model, neighborhood, userCorrelation));
+            new CachingRecommender(new GenericUserBasedRecommender(model, neighborhood, userSimilarity));
     doTestLoad(recommender, 40);
   }
 

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java Tue Sep  2 09:22:47 2008
@@ -18,9 +18,9 @@
 package org.apache.mahout.cf.taste.impl.model.file;
 
 import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.correlation.UserCorrelation;
+import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
-import org.apache.mahout.cf.taste.impl.correlation.PearsonCorrelation;
+import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
 import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood;
 import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender;
 import org.apache.mahout.cf.taste.model.DataModel;
@@ -50,9 +50,9 @@
   }
 
   public void testFile() throws Exception {
-    UserCorrelation userCorrelation = new PearsonCorrelation(model);
-    UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, userCorrelation, model);
-    Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, userCorrelation);
+    UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model);
+    UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, userSimilarity, model);
+    Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, userSimilarity);
     assertEquals(2, recommender.recommend("A123", 3).size());
     assertEquals(2, recommender.recommend("B234", 3).size());
     assertEquals(1, recommender.recommend("C345", 3).size());

Copied: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummySimilarity.java (from r688739, lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummyCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummySimilarity.java?p2=lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummySimilarity.java&p1=lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummyCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummyCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummySimilarity.java Tue Sep  2 09:22:47 2008
@@ -18,15 +18,15 @@
 package org.apache.mahout.cf.taste.impl.neighborhood;
 
 import org.apache.mahout.cf.taste.common.Refreshable;
-import org.apache.mahout.cf.taste.correlation.ItemCorrelation;
-import org.apache.mahout.cf.taste.correlation.PreferenceInferrer;
-import org.apache.mahout.cf.taste.correlation.UserCorrelation;
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
+import org.apache.mahout.cf.taste.similarity.PreferenceInferrer;
+import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 import org.apache.mahout.cf.taste.model.Item;
 import org.apache.mahout.cf.taste.model.User;
 
 import java.util.Collection;
 
-final class DummyCorrelation implements UserCorrelation, ItemCorrelation {
+final class DummySimilarity implements UserSimilarity, ItemSimilarity {
 
   public double userCorrelation(User user1, User user2) {
     return 1.0 / Math.abs(user1.getPreferencesAsArray()[0].getValue() -

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNNeighborhoodTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNNeighborhoodTest.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNNeighborhoodTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNNeighborhoodTest.java Tue Sep  2 09:22:47 2008
@@ -37,20 +37,20 @@
     DataModel dataModel = new GenericDataModel(users);
 
     Collection<User> neighborhood =
-            new NearestNUserNeighborhood(1, new DummyCorrelation(), dataModel).getUserNeighborhood("test1");
+            new NearestNUserNeighborhood(1, new DummySimilarity(), dataModel).getUserNeighborhood("test1");
     assertNotNull(neighborhood);
     assertEquals(1, neighborhood.size());
     assertTrue(neighborhood.contains(users.get(1)));
 
     Collection<User> neighborhood2 =
-            new NearestNUserNeighborhood(2, new DummyCorrelation(), dataModel).getUserNeighborhood("test2");
+            new NearestNUserNeighborhood(2, new DummySimilarity(), dataModel).getUserNeighborhood("test2");
     assertNotNull(neighborhood2);
     assertEquals(2, neighborhood2.size());
     assertTrue(neighborhood2.contains(users.get(0)));
     assertTrue(neighborhood2.contains(users.get(2)));
 
     Collection<User> neighborhood3 =
-            new NearestNUserNeighborhood(4, new DummyCorrelation(), dataModel).getUserNeighborhood("test4");
+            new NearestNUserNeighborhood(4, new DummySimilarity(), dataModel).getUserNeighborhood("test4");
     assertNotNull(neighborhood3);
     assertEquals(3, neighborhood3.size());
     assertTrue(neighborhood3.contains(users.get(0)));
@@ -62,7 +62,7 @@
   public void testRefresh() throws Exception {
     // Make sure this doesn't throw an exception
     DataModel dataModel = new GenericDataModel(Collections.singletonList(getUser("test1", 0.1)));
-    new NearestNUserNeighborhood(1, new DummyCorrelation(), dataModel).refresh(null);
+    new NearestNUserNeighborhood(1, new DummySimilarity(), dataModel).refresh(null);
   }
 
 }

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdNeighborhoodTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdNeighborhoodTest.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdNeighborhoodTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdNeighborhoodTest.java Tue Sep  2 09:22:47 2008
@@ -37,18 +37,18 @@
     DataModel dataModel = new GenericDataModel(users);
 
     Collection<User> neighborhood =
-            new ThresholdUserNeighborhood(20.0, new DummyCorrelation(), dataModel).getUserNeighborhood("test1");
+            new ThresholdUserNeighborhood(20.0, new DummySimilarity(), dataModel).getUserNeighborhood("test1");
     assertNotNull(neighborhood);
     assertTrue(neighborhood.isEmpty());
 
     Collection<User> neighborhood2 =
-            new ThresholdUserNeighborhood(10.0, new DummyCorrelation(), dataModel).getUserNeighborhood("test1");
+            new ThresholdUserNeighborhood(10.0, new DummySimilarity(), dataModel).getUserNeighborhood("test1");
     assertNotNull(neighborhood2);
     assertEquals(1, neighborhood2.size());
     assertTrue(neighborhood2.contains(users.get(1)));
 
     Collection<User> neighborhood3 =
-            new ThresholdUserNeighborhood(1.0, new DummyCorrelation(), dataModel).getUserNeighborhood("test2");
+            new ThresholdUserNeighborhood(1.0, new DummySimilarity(), dataModel).getUserNeighborhood("test2");
     assertNotNull(neighborhood3);
     assertEquals(3, neighborhood3.size());
     assertTrue(neighborhood3.contains(users.get(0)));
@@ -60,7 +60,7 @@
   public void testRefresh() throws Exception {
     // Make sure this doesn't throw an exception
     DataModel dataModel = new GenericDataModel(Collections.singletonList(getUser("test1", 0.1)));
-    new ThresholdUserNeighborhood(20.0, new DummyCorrelation(), dataModel).refresh(null);
+    new ThresholdUserNeighborhood(20.0, new DummySimilarity(), dataModel).refresh(null);
   }
 
 }

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java Tue Sep  2 09:22:47 2008
@@ -17,9 +17,9 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
-import org.apache.mahout.cf.taste.correlation.ItemCorrelation;
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
-import org.apache.mahout.cf.taste.impl.correlation.GenericItemCorrelation;
+import org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity;
 import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
 import org.apache.mahout.cf.taste.impl.model.GenericItem;
 import org.apache.mahout.cf.taste.model.DataModel;
@@ -59,18 +59,18 @@
     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);
-    Collection<GenericItemCorrelation.ItemItemCorrelation> correlations =
-            new ArrayList<GenericItemCorrelation.ItemItemCorrelation>(6);
+    Collection<GenericItemSimilarity.ItemItemCorrelation> correlations =
+            new ArrayList<GenericItemSimilarity.ItemItemCorrelation>(6);
     for (int i = 0; i < 6; i++) {
       for (int j = i + 1; j < 6; j++) {
         correlations.add(
-                new GenericItemCorrelation.ItemItemCorrelation(new GenericItem<String>(String.valueOf(i)),
+                new GenericItemSimilarity.ItemItemCorrelation(new GenericItem<String>(String.valueOf(i)),
                                                                new GenericItem<String>(String.valueOf(j)),
                                                                1.0 / (1.0 + (double) i + (double) j)));
       }
     }
-    ItemCorrelation correlation = new GenericItemCorrelation(correlations);
-    Recommender recommender = new GenericItemBasedRecommender(dataModel, correlation);
+    ItemSimilarity similarity = new GenericItemSimilarity(correlations);
+    Recommender recommender = new GenericItemBasedRecommender(dataModel, similarity);
     List<RecommendedItem> fewRecommended = recommender.recommend("test1", 2);
     List<RecommendedItem> moreRecommended = recommender.recommend("test1", 4);
     for (int i = 0; i < fewRecommended.size(); i++) {
@@ -92,16 +92,16 @@
     Item item2 = new GenericItem<String>("1");
     Item item3 = new GenericItem<String>("2");
     Item item4 = new GenericItem<String>("3");
-    Collection<GenericItemCorrelation.ItemItemCorrelation> correlations =
-            new ArrayList<GenericItemCorrelation.ItemItemCorrelation>(6);
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item2, 1.0));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item3, 0.5));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item4, 0.2));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item2, item3, 0.7));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item2, item4, 0.5));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item3, item4, 0.9));
-    ItemCorrelation correlation = new GenericItemCorrelation(correlations);
-    Recommender recommender = new GenericItemBasedRecommender(dataModel, correlation);
+    Collection<GenericItemSimilarity.ItemItemCorrelation> correlations =
+            new ArrayList<GenericItemSimilarity.ItemItemCorrelation>(6);
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item2, 1.0));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item3, 0.5));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item4, 0.2));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item2, item3, 0.7));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item2, item4, 0.5));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item3, item4, 0.9));
+    ItemSimilarity similarity = new GenericItemSimilarity(correlations);
+    Recommender recommender = new GenericItemBasedRecommender(dataModel, similarity);
     List<RecommendedItem> originalRecommended = recommender.recommend("test1", 2);
     List<RecommendedItem> rescoredRecommended =
             recommender.recommend("test1", 2, new ReversingRescorer<Item>());
@@ -181,15 +181,15 @@
 
   private static ItemBasedRecommender buildRecommender() {
     DataModel dataModel = new GenericDataModel(getMockUsers());
-    Collection<GenericItemCorrelation.ItemItemCorrelation> correlations =
-            new ArrayList<GenericItemCorrelation.ItemItemCorrelation>(2);
+    Collection<GenericItemSimilarity.ItemItemCorrelation> correlations =
+            new ArrayList<GenericItemSimilarity.ItemItemCorrelation>(2);
     Item item1 = new GenericItem<String>("0");
     Item item2 = new GenericItem<String>("1");
     Item item3 = new GenericItem<String>("2");
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item2, 1.0));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item3, 0.5));
-    ItemCorrelation correlation = new GenericItemCorrelation(correlations);
-    return new GenericItemBasedRecommender(dataModel, correlation);
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item2, 1.0));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item3, 0.5));
+    ItemSimilarity similarity = new GenericItemSimilarity(correlations);
+    return new GenericItemBasedRecommender(dataModel, similarity);
   }
 
   private static ItemBasedRecommender buildRecommender2() {
@@ -199,25 +199,25 @@
     users.add(getUser("test3", 0.4, 0.3, 0.5, 0.1, 0.1));
     users.add(getUser("test4", 0.7, 0.3, 0.8, 0.5, 0.6));
     DataModel dataModel = new GenericDataModel(users);
-    Collection<GenericItemCorrelation.ItemItemCorrelation> correlations =
-            new ArrayList<GenericItemCorrelation.ItemItemCorrelation>(10);
+    Collection<GenericItemSimilarity.ItemItemCorrelation> correlations =
+            new ArrayList<GenericItemSimilarity.ItemItemCorrelation>(10);
     Item item1 = new GenericItem<String>("0");
     Item item2 = new GenericItem<String>("1");
     Item item3 = new GenericItem<String>("2");
     Item item4 = new GenericItem<String>("3");
     Item item5 = new GenericItem<String>("4");
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item2, 1.0));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item3, 0.8));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item4, -0.6));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item5, 1.0));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item2, item3, 0.9));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item2, item4, 0.0));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item2, item2, 1.0));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item3, item4, -0.1));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item3, item5, 0.1));
-    correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item4, item5, -0.5));
-    ItemCorrelation correlation = new GenericItemCorrelation(correlations);
-    return new GenericItemBasedRecommender(dataModel, correlation);
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item2, 1.0));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item3, 0.8));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item4, -0.6));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item5, 1.0));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item2, item3, 0.9));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item2, item4, 0.0));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item2, item2, 1.0));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item3, item4, -0.1));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item3, item5, 0.1));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item4, item5, -0.5));
+    ItemSimilarity similarity = new GenericItemSimilarity(correlations);
+    return new GenericItemBasedRecommender(dataModel, similarity);
   }
 
 }

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java Tue Sep  2 09:22:47 2008
@@ -17,9 +17,9 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
-import org.apache.mahout.cf.taste.correlation.UserCorrelation;
+import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
-import org.apache.mahout.cf.taste.impl.correlation.PearsonCorrelation;
+import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
 import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
 import org.apache.mahout.cf.taste.impl.model.GenericItem;
 import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood;
@@ -61,9 +61,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);
-    UserCorrelation correlation = new PearsonCorrelation(dataModel);
-    UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, correlation, dataModel);
-    Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, correlation);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel);
+    Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
     List<RecommendedItem> fewRecommended = recommender.recommend("test1", 2);
     List<RecommendedItem> moreRecommended = recommender.recommend("test1", 4);
     for (int i = 0; i < fewRecommended.size(); i++) {
@@ -81,9 +81,9 @@
     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);
-    UserCorrelation correlation = new PearsonCorrelation(dataModel);
-    UserNeighborhood neighborhood = new NearestNUserNeighborhood(1, correlation, dataModel);
-    Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, correlation);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    UserNeighborhood neighborhood = new NearestNUserNeighborhood(1, similarity, dataModel);
+    Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
     List<RecommendedItem> originalRecommended = recommender.recommend("test1", 2);
     List<RecommendedItem> rescoredRecommended =
             recommender.recommend("test1", 2, new ReversingRescorer<Item>());
@@ -129,9 +129,9 @@
     users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
     users.add(getUser("test4"));
     DataModel dataModel = new GenericDataModel(users);
-    UserCorrelation correlation = new PearsonCorrelation(dataModel);
-    UserNeighborhood neighborhood = new NearestNUserNeighborhood(3, correlation, dataModel);
-    UserBasedRecommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, correlation);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    UserNeighborhood neighborhood = new NearestNUserNeighborhood(3, similarity, dataModel);
+    UserBasedRecommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
     Collection<User> mostSimilar = recommender.mostSimilarUsers("test4", 3);
     assertNotNull(mostSimilar);
     assertEquals(0, mostSimilar.size());
@@ -139,9 +139,9 @@
 
   private static UserBasedRecommender buildRecommender() throws Exception {
     DataModel dataModel = new GenericDataModel(getMockUsers());
-    UserCorrelation correlation = new PearsonCorrelation(dataModel);
-    UserNeighborhood neighborhood = new NearestNUserNeighborhood(1, correlation, dataModel);
-    return new GenericUserBasedRecommender(dataModel, neighborhood, correlation);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    UserNeighborhood neighborhood = new NearestNUserNeighborhood(1, similarity, dataModel);
+    return new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
   }
 
 }

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=691302&r1=691301&r2=691302&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 Sep  2 09:22:47 2008
@@ -17,9 +17,9 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
-import org.apache.mahout.cf.taste.correlation.UserCorrelation;
+import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
-import org.apache.mahout.cf.taste.impl.correlation.PearsonCorrelation;
+import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
 import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
 import org.apache.mahout.cf.taste.impl.model.GenericItem;
 import org.apache.mahout.cf.taste.model.DataModel;
@@ -42,9 +42,9 @@
     users.add(getUser("test2", 0.2, 0.6));
     users.add(getUser("test3", 0.4, 0.9));
     DataModel dataModel = new GenericDataModel(users);
-    UserCorrelation correlation = new PearsonCorrelation(dataModel);
-    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
-    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
     List<RecommendedItem> recommended = recommender.recommend("test1", 1);
     assertNotNull(recommended);
     assertEquals(0, recommended.size());
@@ -61,9 +61,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);
-    UserCorrelation correlation = new PearsonCorrelation(dataModel);
-    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
-    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
     List<RecommendedItem> fewRecommended = recommender.recommend("test1", 2);
     List<RecommendedItem> moreRecommended = recommender.recommend("test1", 4);
     for (int i = 0; i < fewRecommended.size(); i++) {
@@ -81,9 +81,9 @@
     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);
-    UserCorrelation correlation = new PearsonCorrelation(dataModel);
-    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
-    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
     List<RecommendedItem> originalRecommended = recommender.recommend("test1", 2);
     List<RecommendedItem> rescoredRecommended =
             recommender.recommend("test1", 2, new ReversingRescorer<Item>());
@@ -102,9 +102,9 @@
     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);
-    UserCorrelation correlation = new PearsonCorrelation(dataModel);
-    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
-    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
     assertEquals(0.9, recommender.estimatePreference("test3", "3"));
   }
 
@@ -115,9 +115,9 @@
     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);
-    UserCorrelation correlation = new PearsonCorrelation(dataModel);
-    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
-    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
+    Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
     List<RecommendedItem> recommended = recommender.recommend("test1", 1);
     assertNotNull(recommended);
     assertEquals(1, recommended.size());

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=691302&r1=688739&r2=691302&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 Sep  2 09:22:47 2008
@@ -15,10 +15,10 @@
  * limitations under the License.
  */
 
-package org.apache.mahout.cf.taste.impl.correlation;
+package org.apache.mahout.cf.taste.impl.similarity;
 
 import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.correlation.PreferenceInferrer;
+import org.apache.mahout.cf.taste.similarity.PreferenceInferrer;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
 import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
 import org.apache.mahout.cf.taste.impl.model.GenericItem;

Added: 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=691302&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarityTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarityTest.java Tue Sep  2 09:22:47 2008
@@ -0,0 +1,185 @@
+/**
+ * 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.similarity;
+
+import org.apache.mahout.cf.taste.common.TasteException;
+import org.apache.mahout.cf.taste.common.Weighting;
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
+import org.apache.mahout.cf.taste.impl.model.GenericItem;
+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 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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    assertCorrelationEquals(0.8081551272944483, correlation);
+  }
+
+  public void testNoCorrelation2() throws Exception {
+    Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
+    GenericUser<String> user1 = new GenericUser<String>("test1", Collections.singletonList(pref1));
+    Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
+    GenericUser<String> user2 = new GenericUser<String>("test2", Collections.singletonList(pref2));
+    DataModel dataModel = getDataModel(user1, user2);
+    double correlation = new EuclideanDistanceSimilarity(dataModel).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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);
+    double correlation =
+            new EuclideanDistanceSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("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);
+    double correlation =
+            new EuclideanDistanceSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("1"));
+    // Yeah, undefined in this case
+    assertTrue(Double.isNaN(correlation));
+  }
+
+  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);
+    double correlation =
+            new EuclideanDistanceSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("1"));
+    assertCorrelationEquals(0.424465381883345, correlation);
+  }
+
+  public void testNoItemCorrelation2() throws Exception {
+    Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
+    GenericUser<String> user1 = new GenericUser<String>("test1", Collections.singletonList(pref1));
+    Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
+    GenericUser<String> user2 = new GenericUser<String>("test2", Collections.singletonList(pref2));
+    DataModel dataModel = getDataModel(user1, user2);
+    double correlation =
+            new EuclideanDistanceSimilarity(dataModel).itemCorrelation(dataModel.getItem("1"), dataModel.getItem("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);
+    double correlation =
+            new EuclideanDistanceSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("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);
+    double correlation =
+            new EuclideanDistanceSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("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);
+    ItemSimilarity itemSimilarity = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED);
+    double correlation = itemSimilarity.itemCorrelation(dataModel.getItem("0"), dataModel.getItem("1"));
+    assertCorrelationEquals(0.8974062142054332, correlation);
+  }
+
+  public void testRefresh() throws TasteException {
+    // Make sure this doesn't throw an exception
+    new EuclideanDistanceSimilarity(getDataModel()).refresh(null);
+  }
+
+}
\ No newline at end of file

Added: 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=691302&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarityTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarityTest.java Tue Sep  2 09:22:47 2008
@@ -0,0 +1,65 @@
+/**
+ * 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.similarity;
+
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
+import org.apache.mahout.cf.taste.impl.model.GenericItem;
+import org.apache.mahout.cf.taste.model.DataModel;
+import org.apache.mahout.cf.taste.model.Item;
+import org.apache.mahout.cf.taste.model.User;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>Tests {@link GenericItemSimilarity}.</p>
+ */
+public final class GenericItemSimilarityTest extends SimilarityTestCase {
+
+  public void testSimple() {
+    Item item1 = new GenericItem<String>("1");
+    Item item2 = new GenericItem<String>("2");
+    Item item3 = new GenericItem<String>("3");
+    Item item4 = new GenericItem<String>("4");
+    List<GenericItemSimilarity.ItemItemCorrelation> correlations =
+            new ArrayList<GenericItemSimilarity.ItemItemCorrelation>(4);
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item2, 0.5));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item2, item1, 0.6));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item1, 0.5));
+    correlations.add(new GenericItemSimilarity.ItemItemCorrelation(item1, item3, 0.3));
+    GenericItemSimilarity itemCorrelation = new GenericItemSimilarity(correlations);
+    assertEquals(1.0, itemCorrelation.itemCorrelation(item1, item1));
+    assertEquals(0.6, itemCorrelation.itemCorrelation(item1, item2));
+    assertEquals(0.6, itemCorrelation.itemCorrelation(item2, item1));
+    assertEquals(0.3, itemCorrelation.itemCorrelation(item1, item3));
+    assertTrue(Double.isNaN(itemCorrelation.itemCorrelation(item3, item4)));
+  }
+
+  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);
+    ItemSimilarity otherSimilarity = new PearsonCorrelationSimilarity(dataModel);
+    ItemSimilarity itemSimilarity = new GenericItemSimilarity(otherSimilarity, dataModel);
+    assertCorrelationEquals(1.0,
+                            itemSimilarity.itemCorrelation(dataModel.getItem("0"), dataModel.getItem("0")));
+    assertCorrelationEquals(0.960768922830523,
+                            itemSimilarity.itemCorrelation(dataModel.getItem("0"), dataModel.getItem("1")));
+  }
+
+}

Added: 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=691302&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarityTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarityTest.java Tue Sep  2 09:22:47 2008
@@ -0,0 +1,66 @@
+/**
+ * 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.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);
+
+    double correlation = new LogLikelihoodSimilarity(dataModel).
+        itemCorrelation(dataModel.getItem("1"), dataModel.getItem("0"));
+    assertCorrelationEquals(0.12160727029227925, correlation);
+
+    correlation = new LogLikelihoodSimilarity(dataModel).
+        itemCorrelation(dataModel.getItem("0"), dataModel.getItem("1"));
+    assertCorrelationEquals(0.12160727029227925, correlation);
+
+    correlation = new LogLikelihoodSimilarity(dataModel).
+        itemCorrelation(dataModel.getItem("2"), dataModel.getItem("1"));
+    assertCorrelationEquals(0.5423213660693733, correlation);
+
+    correlation = new LogLikelihoodSimilarity(dataModel).
+        itemCorrelation(dataModel.getItem("2"), dataModel.getItem("3"));
+    assertCorrelationEquals(0.6905400104897509, correlation);
+
+    correlation = new LogLikelihoodSimilarity(dataModel).
+        itemCorrelation(dataModel.getItem("3"), dataModel.getItem("4"));
+    assertCorrelationEquals(0.8706358464330881, correlation);
+
+    correlation = new LogLikelihoodSimilarity(dataModel).
+        itemCorrelation(dataModel.getItem("4"), dataModel.getItem("3"));
+    assertCorrelationEquals(0.8706358464330881, correlation);
+  }
+
+  public void testRefresh() {
+    // Make sure this doesn't throw an exception
+    new LogLikelihoodSimilarity(getDataModel()).refresh(null);
+  }
+
+}
\ No newline at end of file

Added: 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=691302&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarityTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarityTest.java Tue Sep  2 09:22:47 2008
@@ -0,0 +1,185 @@
+/**
+ * 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.similarity;
+
+import org.apache.mahout.cf.taste.common.Weighting;
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
+import org.apache.mahout.cf.taste.impl.model.GenericItem;
+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 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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    // 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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    assertCorrelationEquals(-1.0, correlation);
+  }
+
+  public void testNoCorrelation2() throws Exception {
+    Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
+    GenericUser<String> user1 = new GenericUser<String>("test1", Collections.singletonList(pref1));
+    Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
+    GenericUser<String> user2 = new GenericUser<String>("test2", Collections.singletonList(pref2));
+    DataModel dataModel = getDataModel(user1, user2);
+    double correlation = new PearsonCorrelationSimilarity(dataModel).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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);
+    double correlation =
+            new PearsonCorrelationSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("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);
+    double correlation =
+            new PearsonCorrelationSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("1"));
+    // Yeah, undefined in this case
+    assertTrue(Double.isNaN(correlation));
+  }
+
+  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);
+    double correlation =
+            new PearsonCorrelationSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("1"));
+    assertCorrelationEquals(-1.0, correlation);
+  }
+
+  public void testNoItemCorrelation2() throws Exception {
+    Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
+    GenericUser<String> user1 = new GenericUser<String>("test1", Collections.singletonList(pref1));
+    Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
+    GenericUser<String> user2 = new GenericUser<String>("test2", Collections.singletonList(pref2));
+    DataModel dataModel = getDataModel(user1, user2);
+    double correlation =
+            new PearsonCorrelationSimilarity(dataModel).itemCorrelation(dataModel.getItem("1"), dataModel.getItem("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);
+    double correlation =
+            new PearsonCorrelationSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("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);
+    double correlation =
+            new PearsonCorrelationSimilarity(dataModel).itemCorrelation(dataModel.getItem("0"), dataModel.getItem("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);
+    ItemSimilarity itemSimilarity = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED);
+    double correlation = itemSimilarity.itemCorrelation(dataModel.getItem("0"), dataModel.getItem("1"));
+    assertCorrelationEquals(0.9901922307076306, correlation);
+  }
+
+  public void testRefresh() throws Exception {
+    // Make sure this doesn't throw an exception
+    new PearsonCorrelationSimilarity(getDataModel()).refresh(null);
+  }
+
+}

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SimilarityTestCase.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SimilarityTestCase.java?rev=691302&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SimilarityTestCase.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SimilarityTestCase.java Tue Sep  2 09:22:47 2008
@@ -0,0 +1,31 @@
+/**
+ * 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.similarity;
+
+import org.apache.mahout.cf.taste.impl.TasteTestCase;
+
+abstract class SimilarityTestCase extends TasteTestCase {
+
+  static void assertCorrelationEquals(double expected, double actual) {
+    assertTrue("Correlation is NaN", !Double.isNaN(actual));
+    assertTrue("Correlation > 1.0", actual <= 1.0);
+    assertTrue("Correlation < -1.0", actual >= -1.0);
+    assertEquals(expected, actual, EPSILON);
+  }
+
+}

Added: 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=691302&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarityTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarityTest.java Tue Sep  2 09:22:47 2008
@@ -0,0 +1,66 @@
+/**
+ * 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.similarity;
+
+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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    assertCorrelationEquals(-0.5, correlation);
+  }
+
+  public void testRefresh() throws TasteException {
+    // Make sure this doesn't throw an exception
+    new SpearmanCorrelationSimilarity(getDataModel()).refresh(null);
+  }
+
+}

Added: 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=691302&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarityTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarityTest.java Tue Sep  2 09:22:47 2008
@@ -0,0 +1,89 @@
+/**
+ * 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.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).userCorrelation(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).userCorrelation(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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    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).userCorrelation(user1, user2);
+    assertEquals(0.5, correlation);
+  }
+
+  public void testRefresh() {
+    // Make sure this doesn't throw an exception
+    new TanimotoCoefficientSimilarity(getDataModel()).refresh(null);
+  }
+
+}
\ No newline at end of file



Mime
View raw message