You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2008/09/02 18:22:49 UTC
svn commit: r691302 [1/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...
Author: srowen
Date: Tue Sep 2 09:22:47 2008
New Revision: 691302
URL: http://svn.apache.org/viewvc?rev=691302&view=rev
Log:
Finally rename improperly named "correlations" to "similarities" since while some similarity metrics are implemented via correlations, not all are. Might as well before 0.1.
Added:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/
- copied from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AbstractSimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/AbstractCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingItemSimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/CachingItemCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingUserSimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/CachingUserCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/EuclideanDistanceCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/GenericItemCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/LogLikelihoodCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/PearsonCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/SpearmanCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/TanimotoCoefficientCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/
- copied from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/correlation/
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/ItemSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/UserSimilarity.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummySimilarity.java
- copied, changed from r688739, lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummyCorrelation.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/
- copied from r688739, lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/correlation/
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarityTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarityTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarityTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarityTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SimilarityTestCase.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarityTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarityTest.java
Removed:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/correlation/
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AbstractCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingItemCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingUserCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/ItemCorrelation.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/UserCorrelation.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/correlation/
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/DummyCorrelation.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/CorrelationTestCase.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceCorrelationTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemCorrelationTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodCorrelationTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientCorrelationTest.java
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/NearestNeighborClusterSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/TopItems.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/PreferenceInferrer.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/LoadTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNNeighborhoodTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdNeighborhoodTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommenderTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrerTest.java
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java Tue Sep 2 09:22:47 2008
@@ -18,7 +18,7 @@
package org.apache.mahout.cf.taste.impl.neighborhood;
import org.apache.mahout.cf.taste.common.Refreshable;
-import org.apache.mahout.cf.taste.correlation.UserCorrelation;
+import org.apache.mahout.cf.taste.similarity.UserSimilarity;
import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
import org.apache.mahout.cf.taste.impl.common.RandomUtils;
import org.apache.mahout.cf.taste.model.DataModel;
@@ -34,30 +34,30 @@
private static final Random random = RandomUtils.getRandom();
- private final UserCorrelation userCorrelation;
+ private final UserSimilarity userSimilarity;
private final DataModel dataModel;
private final double samplingRate;
private final RefreshHelper refreshHelper;
- AbstractUserNeighborhood(UserCorrelation userCorrelation,
+ AbstractUserNeighborhood(UserSimilarity userSimilarity,
DataModel dataModel,
double samplingRate) {
- if (userCorrelation == null || dataModel == null) {
- throw new IllegalArgumentException("userCorrelation or dataModel is null");
+ if (userSimilarity == null || dataModel == null) {
+ throw new IllegalArgumentException("userSimilarity or dataModel is null");
}
if (Double.isNaN(samplingRate) || samplingRate <= 0.0 || samplingRate > 1.0) {
throw new IllegalArgumentException("samplingRate must be in (0,1]");
}
- this.userCorrelation = userCorrelation;
+ this.userSimilarity = userSimilarity;
this.dataModel = dataModel;
this.samplingRate = samplingRate;
this.refreshHelper = new RefreshHelper(null);
this.refreshHelper.addDependency(this.dataModel);
- this.refreshHelper.addDependency(this.userCorrelation);
+ this.refreshHelper.addDependency(this.userSimilarity);
}
- final UserCorrelation getUserCorrelation() {
- return userCorrelation;
+ final UserSimilarity getUserCorrelation() {
+ return userSimilarity;
}
final DataModel getDataModel() {
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java Tue Sep 2 09:22:47 2008
@@ -18,7 +18,7 @@
package org.apache.mahout.cf.taste.impl.neighborhood;
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.model.DataModel;
import org.apache.mahout.cf.taste.model.User;
import org.slf4j.Logger;
@@ -33,7 +33,7 @@
/**
* <p>Computes a neigbhorhood consisting of the nearest n {@link User}s to a given {@link User}.
- * "Nearest" is defined by the given {@link UserCorrelation}.</p>
+ * "Nearest" is defined by the given {@link org.apache.mahout.cf.taste.similarity.UserSimilarity}.</p>
*/
public final class NearestNUserNeighborhood extends AbstractUserNeighborhood {
@@ -43,19 +43,19 @@
/**
* @param n neighborhood size
- * @param userCorrelation nearness metric
+ * @param userSimilarity nearness metric
* @param dataModel data model
* @throws IllegalArgumentException if n < 1, or userCorrelation or dataModel are <code>null</code>
*/
public NearestNUserNeighborhood(int n,
- UserCorrelation userCorrelation,
+ UserSimilarity userSimilarity,
DataModel dataModel) {
- this(n, userCorrelation, dataModel, 1.0);
+ this(n, userSimilarity, dataModel, 1.0);
}
/**
* @param n neighborhood size
- * @param userCorrelation nearness metric
+ * @param userSimilarity nearness metric
* @param dataModel data model
* @param samplingRate percentage of users to consider when building neighborhood -- decrease to
* trade quality for performance
@@ -63,10 +63,10 @@
* or userCorrelation or dataModel are <code>null</code>
*/
public NearestNUserNeighborhood(int n,
- UserCorrelation userCorrelation,
+ UserSimilarity userSimilarity,
DataModel dataModel,
double samplingRate) {
- super(userCorrelation, dataModel, samplingRate);
+ super(userSimilarity, dataModel, samplingRate);
if (n < 1) {
throw new IllegalArgumentException("n must be at least 1");
}
@@ -78,13 +78,13 @@
DataModel dataModel = getDataModel();
User theUser = dataModel.getUser(userID);
- UserCorrelation userCorrelationImpl = getUserCorrelation();
+ UserSimilarity userSimilarityImpl = getUserCorrelation();
LinkedList<UserCorrelationPair> queue = new LinkedList<UserCorrelationPair>();
boolean full = false;
for (User user : dataModel.getUsers()) {
if (sampleForUser() && !userID.equals(user.getID())) {
- double theCorrelation = userCorrelationImpl.userCorrelation(theUser, user);
+ double theCorrelation = userSimilarityImpl.userCorrelation(theUser, user);
if (!Double.isNaN(theCorrelation) && (!full || theCorrelation > queue.getLast().theCorrelation)) {
ListIterator<UserCorrelationPair> iterator = queue.listIterator(queue.size());
while (iterator.hasPrevious()) {
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java Tue Sep 2 09:22:47 2008
@@ -18,7 +18,7 @@
package org.apache.mahout.cf.taste.impl.neighborhood;
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.model.DataModel;
import org.apache.mahout.cf.taste.model.User;
import org.slf4j.Logger;
@@ -33,7 +33,7 @@
/**
* <p>Computes a neigbhorhood consisting of all {@link User}s whose similarity to the
* given {@link User} meets or exceeds a certain threshold. Similartiy is defined by the given
- * {@link UserCorrelation}.</p>
+ * {@link org.apache.mahout.cf.taste.similarity.UserSimilarity}.</p>
*/
public final class ThresholdUserNeighborhood extends AbstractUserNeighborhood {
@@ -43,21 +43,21 @@
/**
* @param threshold similarity threshold
- * @param userCorrelation similarity metric
+ * @param userSimilarity similarity metric
* @param dataModel data model
* @throws IllegalArgumentException if threshold is {@link Double#NaN},
* or if samplingRate is not positive and less than or equal to 1.0, or if userCorrelation
* or dataModel are <code>null</code>
*/
public ThresholdUserNeighborhood(double threshold,
- UserCorrelation userCorrelation,
+ UserSimilarity userSimilarity,
DataModel dataModel) {
- this(threshold, userCorrelation, dataModel, 1.0);
+ this(threshold, userSimilarity, dataModel, 1.0);
}
/**
* @param threshold similarity threshold
- * @param userCorrelation similarity metric
+ * @param userSimilarity similarity metric
* @param dataModel data model
* @param samplingRate percentage of users to consider when building neighborhood -- decrease to
* trade quality for performance
@@ -66,10 +66,10 @@
* or dataModel are <code>null</code>
*/
public ThresholdUserNeighborhood(double threshold,
- UserCorrelation userCorrelation,
+ UserSimilarity userSimilarity,
DataModel dataModel,
double samplingRate) {
- super(userCorrelation, dataModel, samplingRate);
+ super(userSimilarity, dataModel, samplingRate);
if (Double.isNaN(threshold)) {
throw new IllegalArgumentException("threshold must not be NaN");
}
@@ -83,12 +83,12 @@
User theUser = dataModel.getUser(userID);
List<User> neighborhood = new ArrayList<User>();
Iterator<? extends User> users = dataModel.getUsers().iterator();
- UserCorrelation userCorrelationImpl = getUserCorrelation();
+ UserSimilarity userSimilarityImpl = getUserCorrelation();
while (users.hasNext()) {
User user = users.next();
if (sampleForUser() && !userID.equals(user.getID())) {
- double theCorrelation = userCorrelationImpl.userCorrelation(theUser, user);
+ double theCorrelation = userSimilarityImpl.userCorrelation(theUser, user);
if (!Double.isNaN(theCorrelation) && theCorrelation >= threshold) {
neighborhood.add(user);
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java Tue Sep 2 09:22:47 2008
@@ -19,7 +19,7 @@
import org.apache.mahout.cf.taste.common.Refreshable;
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.common.RefreshHelper;
import org.apache.mahout.cf.taste.impl.common.RandomUtils;
import org.apache.mahout.cf.taste.model.User;
@@ -36,31 +36,31 @@
private static final Random random = RandomUtils.getRandom();
- private final UserCorrelation correlation;
+ private final UserSimilarity similarity;
private final double samplingPercentage;
/**
- * <p>Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link UserCorrelation}.
+ * <p>Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link org.apache.mahout.cf.taste.similarity.UserSimilarity}.
* All user-user correlations are examined.</p>
*/
- public FarthestNeighborClusterSimilarity(UserCorrelation correlation) {
- this(correlation, 1.0);
+ public FarthestNeighborClusterSimilarity(UserSimilarity similarity) {
+ this(similarity, 1.0);
}
/**
- * <p>Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link UserCorrelation}.
+ * <p>Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link org.apache.mahout.cf.taste.similarity.UserSimilarity}.
* By setting <code>samplingPercentage</code> to a value less than 1.0, this implementation will only examine
* that fraction of all user-user correlations between two clusters, increasing performance at the expense
* of accuracy.</p>
*/
- public FarthestNeighborClusterSimilarity(UserCorrelation correlation, double samplingPercentage) {
- if (correlation == null) {
- throw new IllegalArgumentException("correlation is null");
+ public FarthestNeighborClusterSimilarity(UserSimilarity similarity, double samplingPercentage) {
+ if (similarity == null) {
+ throw new IllegalArgumentException("similarity is null");
}
if (Double.isNaN(samplingPercentage) || samplingPercentage <= 0.0 || samplingPercentage > 1.0) {
throw new IllegalArgumentException("samplingPercentage is invalid: " + samplingPercentage);
}
- this.correlation = correlation;
+ this.similarity = similarity;
this.samplingPercentage = samplingPercentage;
}
@@ -73,7 +73,7 @@
for (User user1 : cluster1) {
if (samplingPercentage >= 1.0 || random.nextDouble() < samplingPercentage) {
for (User user2 : cluster2) {
- double theCorrelation = correlation.userCorrelation(user1, user2);
+ double theCorrelation = similarity.userCorrelation(user1, user2);
if (theCorrelation < leastCorrelation) {
leastCorrelation = theCorrelation;
}
@@ -82,19 +82,19 @@
}
// We skipped everything? well, at least try comparing the first Users to get some value
if (leastCorrelation == Double.POSITIVE_INFINITY) {
- return correlation.userCorrelation(cluster1.iterator().next(), cluster2.iterator().next());
+ return similarity.userCorrelation(cluster1.iterator().next(), cluster2.iterator().next());
}
return leastCorrelation;
}
public void refresh(Collection<Refreshable> alreadyRefreshed) {
alreadyRefreshed = RefreshHelper.buildRefreshed(alreadyRefreshed);
- RefreshHelper.maybeRefresh(alreadyRefreshed, correlation);
+ RefreshHelper.maybeRefresh(alreadyRefreshed, similarity);
}
@Override
public String toString() {
- return "FarthestNeighborClusterSimilarity[correlation:" + correlation + ']';
+ return "FarthestNeighborClusterSimilarity[similarity:" + similarity + ']';
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java Tue Sep 2 09:22:47 2008
@@ -19,7 +19,7 @@
import org.apache.mahout.cf.taste.common.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.correlation.ItemCorrelation;
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
import org.apache.mahout.cf.taste.impl.common.FullRunningAverage;
import org.apache.mahout.cf.taste.impl.common.Pair;
import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
@@ -43,35 +43,35 @@
/**
* <p>A simple {@link org.apache.mahout.cf.taste.recommender.Recommender} which uses a given
- * {@link org.apache.mahout.cf.taste.model.DataModel} and {@link org.apache.mahout.cf.taste.correlation.ItemCorrelation}
+ * {@link org.apache.mahout.cf.taste.model.DataModel} and {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity}
* to produce recommendations. This class represents Taste's support for item-based recommenders.</p>
*
- * <p>The {@link ItemCorrelation} is the most important point to discuss here. Item-based recommenders
+ * <p>The {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} is the most important point to discuss here. Item-based recommenders
* are useful because they can take advantage of something to be very fast: they base their computations
* on item correlation, not user correlation, and item correlation is relatively static. It can be
* precomputed, instead of re-computed in real time.</p>
*
- * <p>Thus it's strongly recommended that you use {@link org.apache.mahout.cf.taste.impl.correlation.GenericItemCorrelation}
+ * <p>Thus it's strongly recommended that you use {@link org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity}
* with pre-computed correlations if you're going to use this class. You can use
- * {@link org.apache.mahout.cf.taste.impl.correlation.PearsonCorrelation} too, which computes correlations in real-time,
+ * {@link org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity} too, which computes correlations in real-time,
* but will probably find this painfully slow for large amounts of data.</p>
*/
public final class GenericItemBasedRecommender extends AbstractRecommender implements ItemBasedRecommender {
private static final Logger log = LoggerFactory.getLogger(GenericItemBasedRecommender.class);
- private final ItemCorrelation correlation;
+ private final ItemSimilarity similarity;
private final RefreshHelper refreshHelper;
- public GenericItemBasedRecommender(DataModel dataModel, ItemCorrelation correlation) {
+ public GenericItemBasedRecommender(DataModel dataModel, ItemSimilarity similarity) {
super(dataModel);
- if (correlation == null) {
- throw new IllegalArgumentException("correlation is null");
+ if (similarity == null) {
+ throw new IllegalArgumentException("similarity is null");
}
- this.correlation = correlation;
+ this.similarity = similarity;
this.refreshHelper = new RefreshHelper(null);
refreshHelper.addDependency(dataModel);
- refreshHelper.addDependency(correlation);
+ refreshHelper.addDependency(similarity);
}
public List<RecommendedItem> recommend(Object userID, int howMany, Rescorer<Item> rescorer)
@@ -126,7 +126,7 @@
throw new IllegalArgumentException("rescorer is null");
}
Item toItem = getDataModel().getItem(itemID);
- TopItems.Estimator<Item> estimator = new MostSimilarEstimator(toItem, correlation, rescorer);
+ TopItems.Estimator<Item> estimator = new MostSimilarEstimator(toItem, similarity, rescorer);
return doMostSimilarItems(itemID, howMany, estimator);
}
@@ -145,7 +145,7 @@
for (Object itemID : itemIDs) {
toItems.add(model.getItem(itemID));
}
- TopItems.Estimator<Item> estimator = new MultiMostSimilarEstimator(toItems, correlation, rescorer);
+ TopItems.Estimator<Item> estimator = new MultiMostSimilarEstimator(toItems, similarity, rescorer);
Collection<Item> allItems = new HashSet<Item>(model.getNumItems());
for (Item item : model.getItems()) {
allItems.add(item);
@@ -172,7 +172,7 @@
DataModel model = getDataModel();
User user = model.getUser(userID);
Item recommendedItem = model.getItem(itemID);
- TopItems.Estimator<Item> estimator = new RecommendedBecauseEstimator(user, recommendedItem, correlation);
+ TopItems.Estimator<Item> estimator = new RecommendedBecauseEstimator(user, recommendedItem, similarity);
Collection<Item> allUserItems = new HashSet<Item>();
Preference[] prefs = user.getPreferencesAsArray();
@@ -203,9 +203,9 @@
Preference[] prefs = theUser.getPreferencesAsArray();
for (int i = 0; i < prefs.length; i++) {
Preference pref = prefs[i];
- double theCorrelation = correlation.itemCorrelation(item, pref.getItem());
+ double theCorrelation = similarity.itemCorrelation(item, pref.getItem());
if (!Double.isNaN(theCorrelation)) {
- // Why + 1.0? correlation ranges from -1.0 to 1.0, and we want to use it as a simple
+ // Why + 1.0? similarity ranges from -1.0 to 1.0, and we want to use it as a simple
// weight. To avoid negative values, we add 1.0 to put it in
// the [0.0,2.0] range which is reasonable for weights
theCorrelation += 1.0;
@@ -226,20 +226,20 @@
@Override
public String toString() {
- return "GenericItemBasedRecommender[correlation:" + correlation + ']';
+ return "GenericItemBasedRecommender[similarity:" + similarity + ']';
}
private static class MostSimilarEstimator implements TopItems.Estimator<Item> {
private final Item toItem;
- private final ItemCorrelation correlation;
+ private final ItemSimilarity similarity;
private final Rescorer<Pair<Item, Item>> rescorer;
private MostSimilarEstimator(Item toItem,
- ItemCorrelation correlation,
+ ItemSimilarity similarity,
Rescorer<Pair<Item, Item>> rescorer) {
this.toItem = toItem;
- this.correlation = correlation;
+ this.similarity = similarity;
this.rescorer = rescorer;
}
@@ -248,7 +248,7 @@
if (rescorer.isFiltered(pair)) {
return Double.NaN;
}
- double originalEstimate = correlation.itemCorrelation(toItem, item);
+ double originalEstimate = similarity.itemCorrelation(toItem, item);
return rescorer.rescore(pair, originalEstimate);
}
}
@@ -269,14 +269,14 @@
private static class MultiMostSimilarEstimator implements TopItems.Estimator<Item> {
private final List<Item> toItems;
- private final ItemCorrelation correlation;
+ private final ItemSimilarity similarity;
private final Rescorer<Pair<Item, Item>> rescorer;
private MultiMostSimilarEstimator(List<Item> toItems,
- ItemCorrelation correlation,
+ ItemSimilarity similarity,
Rescorer<Pair<Item, Item>> rescorer) {
this.toItems = toItems;
- this.correlation = correlation;
+ this.similarity = similarity;
this.rescorer = rescorer;
}
@@ -287,7 +287,7 @@
if (rescorer.isFiltered(pair)) {
continue;
}
- double estimate = correlation.itemCorrelation(toItem, item);
+ double estimate = similarity.itemCorrelation(toItem, item);
estimate = rescorer.rescore(pair, estimate);
average.addDatum(estimate);
}
@@ -299,14 +299,14 @@
private final User user;
private final Item recommendedItem;
- private final ItemCorrelation correlation;
+ private final ItemSimilarity similarity;
private RecommendedBecauseEstimator(User user,
Item recommendedItem,
- ItemCorrelation correlation) {
+ ItemSimilarity similarity) {
this.user = user;
this.recommendedItem = recommendedItem;
- this.correlation = correlation;
+ this.similarity = similarity;
}
public double estimate(Item item) throws TasteException {
@@ -314,7 +314,7 @@
if (pref == null) {
return Double.NaN;
}
- double correlationValue = correlation.itemCorrelation(recommendedItem, item);
+ double correlationValue = similarity.itemCorrelation(recommendedItem, item);
return (1.0 + correlationValue) * pref.getValue();
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java Tue Sep 2 09:22:47 2008
@@ -19,7 +19,7 @@
import org.apache.mahout.cf.taste.common.Refreshable;
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.common.Pair;
import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
import org.apache.mahout.cf.taste.model.DataModel;
@@ -49,21 +49,21 @@
private static final Logger log = LoggerFactory.getLogger(GenericUserBasedRecommender.class);
private final UserNeighborhood neighborhood;
- private final UserCorrelation correlation;
+ private final UserSimilarity similarity;
private final RefreshHelper refreshHelper;
public GenericUserBasedRecommender(DataModel dataModel,
UserNeighborhood neighborhood,
- UserCorrelation correlation) {
+ UserSimilarity similarity) {
super(dataModel);
if (neighborhood == null) {
throw new IllegalArgumentException("neighborhood is null");
}
this.neighborhood = neighborhood;
- this.correlation = correlation;
+ this.similarity = similarity;
this.refreshHelper = new RefreshHelper(null);
refreshHelper.addDependency(dataModel);
- refreshHelper.addDependency(correlation);
+ refreshHelper.addDependency(similarity);
refreshHelper.addDependency(neighborhood);
}
@@ -123,7 +123,7 @@
throw new IllegalArgumentException("rescorer is null");
}
User toUser = getDataModel().getUser(userID);
- TopItems.Estimator<User> estimator = new MostSimilarEstimator(toUser, correlation, rescorer);
+ TopItems.Estimator<User> estimator = new MostSimilarEstimator(toUser, similarity, rescorer);
return doMostSimilarUsers(userID, howMany, estimator);
}
@@ -152,7 +152,7 @@
// See GenericItemBasedRecommender.doEstimatePreference() too
Preference pref = user.getPreferenceFor(item.getID());
if (pref != null) {
- double theCorrelation = correlation.userCorrelation(theUser, user) + 1.0;
+ double theCorrelation = similarity.userCorrelation(theUser, user) + 1.0;
if (!Double.isNaN(theCorrelation)) {
preference += theCorrelation * pref.getValue();
totalCorrelation += theCorrelation;
@@ -190,14 +190,14 @@
private static class MostSimilarEstimator implements TopItems.Estimator<User> {
private final User toUser;
- private final UserCorrelation correlation;
+ private final UserSimilarity similarity;
private final Rescorer<Pair<User, User>> rescorer;
private MostSimilarEstimator(User toUser,
- UserCorrelation correlation,
+ UserSimilarity similarity,
Rescorer<Pair<User, User>> rescorer) {
this.toUser = toUser;
- this.correlation = correlation;
+ this.similarity = similarity;
this.rescorer = rescorer;
}
@@ -206,7 +206,7 @@
if (rescorer.isFiltered(pair)) {
return Double.NaN;
}
- double originalEstimate = correlation.userCorrelation(toUser, user);
+ double originalEstimate = similarity.userCorrelation(toUser, user);
return rescorer.rescore(pair, originalEstimate);
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/NearestNeighborClusterSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/NearestNeighborClusterSimilarity.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/NearestNeighborClusterSimilarity.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/NearestNeighborClusterSimilarity.java Tue Sep 2 09:22:47 2008
@@ -19,7 +19,7 @@
import org.apache.mahout.cf.taste.common.Refreshable;
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.common.RefreshHelper;
import org.apache.mahout.cf.taste.impl.common.RandomUtils;
import org.apache.mahout.cf.taste.model.User;
@@ -36,31 +36,31 @@
private static final Random random = RandomUtils.getRandom();
- private final UserCorrelation correlation;
+ private final UserSimilarity similarity;
private final double samplingPercentage;
/**
- * <p>Constructs a {@link NearestNeighborClusterSimilarity} based on the given {@link UserCorrelation}.
+ * <p>Constructs a {@link NearestNeighborClusterSimilarity} based on the given {@link org.apache.mahout.cf.taste.similarity.UserSimilarity}.
* All user-user correlations are examined.</p>
*/
- public NearestNeighborClusterSimilarity(UserCorrelation correlation) {
- this(correlation, 1.0);
+ public NearestNeighborClusterSimilarity(UserSimilarity similarity) {
+ this(similarity, 1.0);
}
/**
- * <p>Constructs a {@link NearestNeighborClusterSimilarity} based on the given {@link UserCorrelation}.
+ * <p>Constructs a {@link NearestNeighborClusterSimilarity} based on the given {@link org.apache.mahout.cf.taste.similarity.UserSimilarity}.
* By setting <code>samplingPercentage</code> to a value less than 1.0, this implementation will only examine
* that fraction of all user-user correlations between two clusters, increasing performance at the expense
* of accuracy.</p>
*/
- public NearestNeighborClusterSimilarity(UserCorrelation correlation, double samplingPercentage) {
- if (correlation == null) {
- throw new IllegalArgumentException("correlation is null");
+ public NearestNeighborClusterSimilarity(UserSimilarity similarity, double samplingPercentage) {
+ if (similarity == null) {
+ throw new IllegalArgumentException("similarity is null");
}
if (Double.isNaN(samplingPercentage) || samplingPercentage <= 0.0 || samplingPercentage > 1.0) {
throw new IllegalArgumentException("samplingPercentage is invalid: " + samplingPercentage);
}
- this.correlation = correlation;
+ this.similarity = similarity;
this.samplingPercentage = samplingPercentage;
}
@@ -73,7 +73,7 @@
for (User user1 : cluster1) {
if (samplingPercentage >= 1.0 || random.nextDouble() < samplingPercentage) {
for (User user2 : cluster2) {
- double theCorrelation = correlation.userCorrelation(user1, user2);
+ double theCorrelation = similarity.userCorrelation(user1, user2);
if (theCorrelation > greatestCorrelation) {
greatestCorrelation = theCorrelation;
}
@@ -82,19 +82,19 @@
}
// We skipped everything? well, at least try comparing the first Users to get some value
if (greatestCorrelation == Double.NEGATIVE_INFINITY) {
- return correlation.userCorrelation(cluster1.iterator().next(), cluster2.iterator().next());
+ return similarity.userCorrelation(cluster1.iterator().next(), cluster2.iterator().next());
}
return greatestCorrelation;
}
public void refresh(Collection<Refreshable> alreadyRefreshed) {
alreadyRefreshed = RefreshHelper.buildRefreshed(alreadyRefreshed);
- RefreshHelper.maybeRefresh(alreadyRefreshed, correlation);
+ RefreshHelper.maybeRefresh(alreadyRefreshed, similarity);
}
@Override
public String toString() {
- return "NearestNeighborClusterSimilarity[correlation:" + correlation + ']';
+ return "NearestNeighborClusterSimilarity[similarity:" + similarity + ']';
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/TopItems.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/TopItems.java?rev=691302&r1=691301&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/TopItems.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/TopItems.java Tue Sep 2 09:22:47 2008
@@ -18,7 +18,7 @@
package org.apache.mahout.cf.taste.impl.recommender;
import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.impl.correlation.GenericItemCorrelation;
+import org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity;
import org.apache.mahout.cf.taste.model.Item;
import org.apache.mahout.cf.taste.model.Preference;
import org.apache.mahout.cf.taste.model.User;
@@ -116,18 +116,18 @@
/**
* <p>Thanks to tsmorton for suggesting this functionality and writing part of the code.</p>
*
- * @see GenericItemCorrelation#GenericItemCorrelation(Iterable, int)
- * @see GenericItemCorrelation#GenericItemCorrelation(org.apache.mahout.cf.taste.correlation.ItemCorrelation , org.apache.mahout.cf.taste.model.DataModel , int)
+ * @see org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity#GenericItemCorrelation(Iterable, int)
+ * @see org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity#GenericItemCorrelation(org.apache.mahout.cf.taste.similarity.ItemSimilarity , org.apache.mahout.cf.taste.model.DataModel , int)
*/
- public static List<GenericItemCorrelation.ItemItemCorrelation> getTopItemItemCorrelations(
- int howMany, Iterable<GenericItemCorrelation.ItemItemCorrelation> allCorrelations) {
- LinkedList<GenericItemCorrelation.ItemItemCorrelation> topCorrelations =
- new LinkedList<GenericItemCorrelation.ItemItemCorrelation>();
+ public static List<GenericItemSimilarity.ItemItemCorrelation> getTopItemItemCorrelations(
+ int howMany, Iterable<GenericItemSimilarity.ItemItemCorrelation> allCorrelations) {
+ LinkedList<GenericItemSimilarity.ItemItemCorrelation> topCorrelations =
+ new LinkedList<GenericItemSimilarity.ItemItemCorrelation>();
boolean full = false;
- for (GenericItemCorrelation.ItemItemCorrelation correlation : allCorrelations) {
+ for (GenericItemSimilarity.ItemItemCorrelation correlation : allCorrelations) {
double value = correlation.getValue();
if (!full || value > topCorrelations.getLast().getValue()) {
- ListIterator<GenericItemCorrelation.ItemItemCorrelation> iterator =
+ ListIterator<GenericItemSimilarity.ItemItemCorrelation> iterator =
topCorrelations.listIterator(topCorrelations.size());
while (iterator.hasPrevious()) {
if (value <= iterator.previous().getValue()) {
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AbstractSimilarity.java (from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/AbstractCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AbstractSimilarity.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AbstractSimilarity.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/AbstractCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/AbstractCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AbstractSimilarity.java Tue Sep 2 09:22:47 2008
@@ -15,14 +15,14 @@
* 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.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.common.Weighting;
-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.impl.common.RefreshHelper;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.model.Item;
@@ -41,9 +41,9 @@
* implementations in this package, including the basic correlation algorithm,
* normalization, transforms, etc.
*/
-abstract class AbstractCorrelation implements UserCorrelation, ItemCorrelation {
+abstract class AbstractSimilarity implements UserSimilarity, ItemSimilarity {
- private static final Logger log = LoggerFactory.getLogger(AbstractCorrelation.class);
+ private static final Logger log = LoggerFactory.getLogger(AbstractSimilarity.class);
private final DataModel dataModel;
private PreferenceInferrer inferrer;
@@ -55,16 +55,16 @@
private final RefreshHelper refreshHelper;
/**
- * <p>Creates a normal (unweighted) {@link AbstractCorrelation}.</p>
+ * <p>Creates a normal (unweighted) {@link AbstractSimilarity}.</p>
*/
- AbstractCorrelation(DataModel dataModel) throws TasteException {
+ AbstractSimilarity(DataModel dataModel) throws TasteException {
this(dataModel, Weighting.UNWEIGHTED);
}
/**
- * <p>Creates a possibly weighted {@link AbstractCorrelation}.</p>
+ * <p>Creates a possibly weighted {@link AbstractSimilarity}.</p>
*/
- AbstractCorrelation(DataModel dataModel, Weighting weighting) throws TasteException {
+ AbstractSimilarity(DataModel dataModel, Weighting weighting) throws TasteException {
if (dataModel == null) {
throw new IllegalArgumentException("dataModel is null");
}
@@ -74,8 +74,8 @@
this.cachedNumUsers = dataModel.getNumUsers();
this.refreshHelper = new RefreshHelper(new Callable<Object>() {
public Object call() throws TasteException {
- cachedNumItems = AbstractCorrelation.this.dataModel.getNumItems();
- cachedNumUsers = AbstractCorrelation.this.dataModel.getNumUsers();
+ cachedNumItems = AbstractSimilarity.this.dataModel.getNumItems();
+ cachedNumUsers = AbstractSimilarity.this.dataModel.getNumUsers();
return null;
}
});
@@ -253,7 +253,7 @@
}
if (log.isTraceEnabled()) {
- log.trace("UserCorrelation between " + user1 + " and " + user2 + " is " + result);
+ log.trace("UserSimilarity between " + user1 + " and " + user2 + " is " + result);
}
return result;
}
@@ -341,7 +341,7 @@
}
if (log.isTraceEnabled()) {
- log.trace("ItemCorrelation between " + item1 + " and " + item2 + " is " + result);
+ log.trace("ItemSimilarity between " + item1 + " and " + item2 + " is " + result);
}
return result;
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrer.java?rev=691302&r1=688739&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrer.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrer.java Tue Sep 2 09:22:47 2008
@@ -15,11 +15,11 @@
* 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.Refreshable;
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.common.Cache;
import org.apache.mahout.cf.taste.impl.common.FullRunningAverage;
import org.apache.mahout.cf.taste.impl.common.Retriever;
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingItemSimilarity.java (from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/CachingItemCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingItemSimilarity.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingItemSimilarity.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/CachingItemCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/CachingItemCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingItemSimilarity.java Tue Sep 2 09:22:47 2008
@@ -15,11 +15,11 @@
* 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.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.correlation.ItemCorrelation;
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
import org.apache.mahout.cf.taste.impl.common.Cache;
import org.apache.mahout.cf.taste.impl.common.Pair;
import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
@@ -30,20 +30,20 @@
import java.util.Collection;
/**
- * Caches the results from an underlying {@link ItemCorrelation} implementation.
+ * Caches the results from an underlying {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} implementation.
*/
-public final class CachingItemCorrelation implements ItemCorrelation {
+public final class CachingItemSimilarity implements ItemSimilarity {
- private final ItemCorrelation correlation;
+ private final ItemSimilarity similarity;
private final Cache<Pair<Item, Item>, Double> correlationCache;
- public CachingItemCorrelation(ItemCorrelation correlation, DataModel dataModel) throws TasteException {
- if (correlation == null) {
- throw new IllegalArgumentException("correlation is null");
+ public CachingItemSimilarity(ItemSimilarity similarity, DataModel dataModel) throws TasteException {
+ if (similarity == null) {
+ throw new IllegalArgumentException("similarity is null");
}
- this.correlation = correlation;
+ this.similarity = similarity;
int maxCacheSize = dataModel.getNumItems(); // just a dumb heuristic for sizing
- this.correlationCache = new Cache<Pair<Item, Item>, Double>(new CorrelationRetriever(correlation), maxCacheSize);
+ this.correlationCache = new Cache<Pair<Item, Item>, Double>(new CorrelationRetriever(similarity), maxCacheSize);
}
public double itemCorrelation(Item item1, Item item2) throws TasteException {
@@ -59,16 +59,17 @@
public void refresh(Collection<Refreshable> alreadyRefreshed) {
correlationCache.clear();
alreadyRefreshed = RefreshHelper.buildRefreshed(alreadyRefreshed);
- RefreshHelper.maybeRefresh(alreadyRefreshed, correlation);
+ RefreshHelper.maybeRefresh(alreadyRefreshed, similarity);
}
private static final class CorrelationRetriever implements Retriever<Pair<Item, Item>, Double> {
- private final ItemCorrelation correlation;
- private CorrelationRetriever(ItemCorrelation correlation) {
- this.correlation = correlation;
+ private final ItemSimilarity similarity;
+
+ private CorrelationRetriever(ItemSimilarity similarity) {
+ this.similarity = similarity;
}
public Double get(Pair<Item, Item> key) throws TasteException {
- return correlation.itemCorrelation(key.getFirst(), key.getSecond());
+ return similarity.itemCorrelation(key.getFirst(), key.getSecond());
}
}
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingUserSimilarity.java (from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/CachingUserCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingUserSimilarity.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingUserSimilarity.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/CachingUserCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/CachingUserCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingUserSimilarity.java Tue Sep 2 09:22:47 2008
@@ -15,12 +15,12 @@
* 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.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.correlation.PreferenceInferrer;
-import org.apache.mahout.cf.taste.correlation.UserCorrelation;
+import org.apache.mahout.cf.taste.similarity.PreferenceInferrer;
+import org.apache.mahout.cf.taste.similarity.UserSimilarity;
import org.apache.mahout.cf.taste.impl.common.Cache;
import org.apache.mahout.cf.taste.impl.common.Pair;
import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
@@ -31,20 +31,20 @@
import java.util.Collection;
/**
- * Caches the results from an underlying {@link UserCorrelation} implementation.
+ * Caches the results from an underlying {@link org.apache.mahout.cf.taste.similarity.UserSimilarity} implementation.
*/
-public final class CachingUserCorrelation implements UserCorrelation {
+public final class CachingUserSimilarity implements UserSimilarity {
- private final UserCorrelation correlation;
+ private final UserSimilarity similarity;
private final Cache<Pair<User, User>, Double> correlationCache;
- public CachingUserCorrelation(UserCorrelation correlation, DataModel dataModel) throws TasteException {
- if (correlation == null) {
- throw new IllegalArgumentException("correlation is null");
+ public CachingUserSimilarity(UserSimilarity similarity, DataModel dataModel) throws TasteException {
+ if (similarity == null) {
+ throw new IllegalArgumentException("similarity is null");
}
- this.correlation = correlation;
+ this.similarity = similarity;
int maxCacheSize = dataModel.getNumUsers(); // just a dumb heuristic for sizing
- this.correlationCache = new Cache<Pair<User, User>, Double>(new CorrelationRetriever(correlation), maxCacheSize);
+ this.correlationCache = new Cache<Pair<User, User>, Double>(new CorrelationRetriever(similarity), maxCacheSize);
}
public double userCorrelation(User user1, User user2) throws TasteException {
@@ -59,22 +59,23 @@
public void setPreferenceInferrer(PreferenceInferrer inferrer) {
correlationCache.clear();
- correlation.setPreferenceInferrer(inferrer);
+ similarity.setPreferenceInferrer(inferrer);
}
public void refresh(Collection<Refreshable> alreadyRefreshed) {
correlationCache.clear();
alreadyRefreshed = RefreshHelper.buildRefreshed(alreadyRefreshed);
- RefreshHelper.maybeRefresh(alreadyRefreshed, correlation);
+ RefreshHelper.maybeRefresh(alreadyRefreshed, similarity);
}
private static final class CorrelationRetriever implements Retriever<Pair<User, User>, Double> {
- private final UserCorrelation correlation;
- private CorrelationRetriever(UserCorrelation correlation) {
- this.correlation = correlation;
+ private final UserSimilarity similarity;
+
+ private CorrelationRetriever(UserSimilarity similarity) {
+ this.similarity = similarity;
}
public Double get(Pair<User, User> key) throws TasteException {
- return correlation.userCorrelation(key.getFirst(), key.getSecond());
+ return similarity.userCorrelation(key.getFirst(), key.getSecond());
}
}
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarity.java (from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/EuclideanDistanceCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarity.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarity.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/EuclideanDistanceCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/EuclideanDistanceCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarity.java Tue Sep 2 09:22:47 2008
@@ -15,7 +15,7 @@
* 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.common.Weighting;
@@ -30,13 +30,13 @@
* along each dimension. The correlation is then computed as 1 / (1 + distance), so the
* resulting values are in the range (0,1].</p>
*/
-public final class EuclideanDistanceCorrelation extends AbstractCorrelation {
+public final class EuclideanDistanceSimilarity extends AbstractSimilarity {
- public EuclideanDistanceCorrelation(DataModel dataModel) throws TasteException {
+ public EuclideanDistanceSimilarity(DataModel dataModel) throws TasteException {
super(dataModel);
}
- public EuclideanDistanceCorrelation(DataModel dataModel, Weighting weighting) throws TasteException {
+ public EuclideanDistanceSimilarity(DataModel dataModel, Weighting weighting) throws TasteException {
super(dataModel, weighting);
}
@@ -50,7 +50,7 @@
}
// normalize a bit for magnitude
sumXYdiff2 /= denominator;
- // divide by n below to not automatically give users with more overlap more correlation
+ // divide by n below to not automatically give users with more overlap more similarity
return 1.0 / (1.0 + (Math.sqrt(sumXYdiff2) / (double) n));
}
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarity.java (from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/GenericItemCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarity.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarity.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/GenericItemCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/GenericItemCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarity.java Tue Sep 2 09:22:47 2008
@@ -15,11 +15,11 @@
* 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.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.correlation.ItemCorrelation;
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
import org.apache.mahout.cf.taste.impl.common.FastMap;
import org.apache.mahout.cf.taste.impl.common.IteratorIterable;
import org.apache.mahout.cf.taste.impl.common.IteratorUtils;
@@ -34,21 +34,21 @@
import java.util.NoSuchElementException;
/**
- * <p>A "generic" {@link ItemCorrelation} which takes a static list of precomputed {@link Item}
+ * <p>A "generic" {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} which takes a static list of precomputed {@link Item}
* correlations and bases its responses on that alone. The values may have been precomputed
* offline by another process, stored in a file, and then read and fed into an instance of this class.</p>
*
- * <p>This is perhaps the best {@link ItemCorrelation} to use with
+ * <p>This is perhaps the best {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} to use with
* {@link org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender}, for now, since the point of item-based
* recommenders is that they can take advantage of the fact that item similarity is relatively static,
* can be precomputed, and then used in computation to gain a significant performance advantage.</p>
*/
-public final class GenericItemCorrelation implements ItemCorrelation {
+public final class GenericItemSimilarity implements ItemSimilarity {
private final Map<Item, Map<Item, Double>> correlationMaps = new FastMap<Item, Map<Item, Double>>();
/**
- * <p>Creates a {@link GenericItemCorrelation} from a precomputed list of {@link ItemItemCorrelation}s. Each
+ * <p>Creates a {@link GenericItemSimilarity} from a precomputed list of {@link ItemItemCorrelation}s. Each
* represents the correlation between two distinct items. Since correlation is assumed to be symmetric,
* it is not necessary to specify correlation between item1 and item2, and item2 and item1. Both are the same.
* It is also not necessary to specify a correlation between any item and itself; these are assumed to be 1.0.</p>
@@ -58,7 +58,7 @@
*
* @param correlations set of {@link ItemItemCorrelation}s on which to base this instance
*/
- public GenericItemCorrelation(Iterable<ItemItemCorrelation> correlations) {
+ public GenericItemSimilarity(Iterable<ItemItemCorrelation> correlations) {
initCorrelationMaps(correlations);
}
@@ -72,46 +72,46 @@
* @param correlations set of {@link ItemItemCorrelation}s on which to base this instance
* @param maxToKeep maximum number of correlations to keep
*/
- public GenericItemCorrelation(Iterable<ItemItemCorrelation> correlations, int maxToKeep) {
+ public GenericItemSimilarity(Iterable<ItemItemCorrelation> correlations, int maxToKeep) {
Iterable<ItemItemCorrelation> keptCorrelations = TopItems.getTopItemItemCorrelations(maxToKeep, correlations);
initCorrelationMaps(keptCorrelations);
}
/**
- * <p>Builds a list of item-item correlations given an {@link ItemCorrelation} implementation and a
+ * <p>Builds a list of item-item correlations given an {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} implementation and a
* {@link DataModel}, rather than a list of {@link ItemItemCorrelation}s.</p>
*
- * <p>It's valid to build a {@link GenericItemCorrelation} this way, but perhaps missing some of the point
+ * <p>It's valid to build a {@link GenericItemSimilarity} this way, but perhaps missing some of the point
* of an item-based recommender. Item-based recommenders use the assumption that item-item correlations
* are relatively fixed, and might be known already independent of user preferences. Hence it is useful
* to inject that information, using {@link #GenericItemCorrelation(Iterable)}.</p>
*
- * @param otherCorrelation other {@link ItemCorrelation} to get correlations from
+ * @param otherSimilarity other {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} to get correlations from
* @param dataModel data model to get {@link Item}s from
* @throws TasteException if an error occurs while accessing the {@link DataModel} items
*/
- public GenericItemCorrelation(ItemCorrelation otherCorrelation, DataModel dataModel) throws TasteException {
+ public GenericItemSimilarity(ItemSimilarity otherSimilarity, DataModel dataModel) throws TasteException {
List<? extends Item> items = IteratorUtils.iterableToList(dataModel.getItems());
- Iterator<ItemItemCorrelation> it = new DataModelCorrelationsIterator(otherCorrelation, items);
+ Iterator<ItemItemCorrelation> it = new DataModelCorrelationsIterator(otherSimilarity, items);
initCorrelationMaps(new IteratorIterable<ItemItemCorrelation>(it));
}
/**
- * <p>Like {@link #GenericItemCorrelation(ItemCorrelation, DataModel)} )}, but will only
+ * <p>Like {@link #GenericItemCorrelation(org.apache.mahout.cf.taste.similarity.ItemSimilarity , DataModel)} )}, but will only
* keep the specified number of correlations from the given {@link DataModel}.
* It will keep those with the highest correlation -- those that are therefore most important.</p>
*
* <p>Thanks to tsmorton for suggesting this and providing part of the implementation.</p>
*
- * @param otherCorrelation other {@link ItemCorrelation} to get correlations from
+ * @param otherSimilarity other {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} to get correlations from
* @param dataModel data model to get {@link Item}s from
* @param maxToKeep maximum number of correlations to keep
* @throws TasteException if an error occurs while accessing the {@link DataModel} items
*/
- public GenericItemCorrelation(ItemCorrelation otherCorrelation, DataModel dataModel, int maxToKeep)
+ public GenericItemSimilarity(ItemSimilarity otherSimilarity, DataModel dataModel, int maxToKeep)
throws TasteException {
List<? extends Item> items = IteratorUtils.iterableToList(dataModel.getItems());
- Iterator<ItemItemCorrelation> it = new DataModelCorrelationsIterator(otherCorrelation, items);
+ Iterator<ItemItemCorrelation> it = new DataModelCorrelationsIterator(otherSimilarity, items);
Iterable<ItemItemCorrelation> keptCorrelations =
TopItems.getTopItemItemCorrelations(maxToKeep, new IteratorIterable<ItemItemCorrelation>(it));
initCorrelationMaps(keptCorrelations);
@@ -140,7 +140,7 @@
}
map.put(item2, iic.getValue());
}
- // else correlation between item and itself already assumed to be 1.0
+ // else similarity between item and itself already assumed to be 1.0
}
}
@@ -230,15 +230,15 @@
private static final class DataModelCorrelationsIterator implements Iterator<ItemItemCorrelation> {
- private final ItemCorrelation otherCorrelation;
+ private final ItemSimilarity otherSimilarity;
private final List<? extends Item> items;
private final int size;
private int i;
private Item item1;
private int j;
- private DataModelCorrelationsIterator(ItemCorrelation otherCorrelation, List<? extends Item> items) {
- this.otherCorrelation = otherCorrelation;
+ private DataModelCorrelationsIterator(ItemSimilarity otherSimilarity, List<? extends Item> items) {
+ this.otherSimilarity = otherSimilarity;
this.items = items;
this.size = items.size();
i = 0;
@@ -257,7 +257,7 @@
Item item2 = items.get(j);
double correlation;
try {
- correlation = otherCorrelation.itemCorrelation(item1, item2);
+ correlation = otherSimilarity.itemCorrelation(item1, item2);
} catch (TasteException te) {
// ugly:
throw new RuntimeException(te);
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarity.java (from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/LogLikelihoodCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarity.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarity.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/LogLikelihoodCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/LogLikelihoodCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarity.java Tue Sep 2 09:22:47 2008
@@ -15,11 +15,11 @@
* 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.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.correlation.ItemCorrelation;
+import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.model.Item;
@@ -29,11 +29,11 @@
/**
* See <a href="http://citeseer.ist.psu.edu/29096.html">http://citeseer.ist.psu.edu/29096.html</a>.
*/
-public final class LogLikelihoodCorrelation implements ItemCorrelation {
+public final class LogLikelihoodSimilarity implements ItemSimilarity {
private final DataModel dataModel;
- public LogLikelihoodCorrelation(DataModel dataModel) {
+ public LogLikelihoodSimilarity(DataModel dataModel) {
this.dataModel = dataModel;
}
@@ -70,7 +70,7 @@
@Override
public final String toString() {
- return "LogLikelihoodCorrelation[dataModel:" + dataModel + ']';
+ return "LogLikelihoodSimilarity[dataModel:" + dataModel + ']';
}
}
\ No newline at end of file
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarity.java (from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/PearsonCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarity.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarity.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/PearsonCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/PearsonCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarity.java Tue Sep 2 09:22:47 2008
@@ -15,7 +15,7 @@
* 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.common.Weighting;
@@ -47,13 +47,13 @@
* receives is assumed to be centered -- mean is 0. The correlation may be interpreted as the cosine of the
* angle between the two vectors defined by the users' preference values.</p>
*/
-public final class PearsonCorrelation extends AbstractCorrelation {
+public final class PearsonCorrelationSimilarity extends AbstractSimilarity {
- public PearsonCorrelation(DataModel dataModel) throws TasteException {
+ public PearsonCorrelationSimilarity(DataModel dataModel) throws TasteException {
super(dataModel);
}
- public PearsonCorrelation(DataModel dataModel, Weighting weighting) throws TasteException {
+ public PearsonCorrelationSimilarity(DataModel dataModel, Weighting weighting) throws TasteException {
super(dataModel, weighting);
}
@@ -68,7 +68,7 @@
double denominator = xTerm * yTerm;
if (denominator == 0.0) {
// One or both parties has -all- the same ratings;
- // can't really say much correlation under this measure
+ // can't really say much similarity under this measure
return Double.NaN;
}
return sumXY / denominator;
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarity.java (from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/SpearmanCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarity.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarity.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/SpearmanCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/SpearmanCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarity.java Tue Sep 2 09:22:47 2008
@@ -15,12 +15,12 @@
* 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.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.correlation.PreferenceInferrer;
-import org.apache.mahout.cf.taste.correlation.UserCorrelation;
+import org.apache.mahout.cf.taste.similarity.PreferenceInferrer;
+import org.apache.mahout.cf.taste.similarity.UserSimilarity;
import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
import org.apache.mahout.cf.taste.impl.model.ByItemPreferenceComparator;
import org.apache.mahout.cf.taste.impl.model.ByValuePreferenceComparator;
@@ -33,44 +33,44 @@
import java.util.Collection;
/**
- * <p>Like {@link PearsonCorrelation}, but compares relative ranking of preference values instead of preference
+ * <p>Like {@link PearsonCorrelationSimilarity}, but compares relative ranking of preference values instead of preference
* values themselves. That is, each {@link User}'s preferences are sorted and then assign a rank as their preference
* value, with 1 being assigned to the least preferred item. Then the Pearson itemCorrelation of these rank values is
* computed.</p>
*/
-public final class SpearmanCorrelation implements UserCorrelation {
+public final class SpearmanCorrelationSimilarity implements UserSimilarity {
- private final UserCorrelation rankingUserCorrelation;
+ private final UserSimilarity rankingUserSimilarity;
- public SpearmanCorrelation(DataModel dataModel) throws TasteException {
+ public SpearmanCorrelationSimilarity(DataModel dataModel) throws TasteException {
if (dataModel == null) {
throw new IllegalArgumentException("dataModel is null");
}
- this.rankingUserCorrelation = new PearsonCorrelation(dataModel);
+ this.rankingUserSimilarity = new PearsonCorrelationSimilarity(dataModel);
}
- public SpearmanCorrelation(UserCorrelation rankingUserCorrelation) {
- if (rankingUserCorrelation == null) {
- throw new IllegalArgumentException("rankingUserCorrelation is null");
+ public SpearmanCorrelationSimilarity(UserSimilarity rankingUserSimilarity) {
+ if (rankingUserSimilarity == null) {
+ throw new IllegalArgumentException("rankingUserSimilarity is null");
}
- this.rankingUserCorrelation = rankingUserCorrelation;
+ this.rankingUserSimilarity = rankingUserSimilarity;
}
public double userCorrelation(User user1, User user2) throws TasteException {
if (user1 == null || user2 == null) {
throw new IllegalArgumentException("user1 or user2 is null");
}
- return rankingUserCorrelation.userCorrelation(new RankedPreferenceUser(user1),
+ return rankingUserSimilarity.userCorrelation(new RankedPreferenceUser(user1),
new RankedPreferenceUser(user2));
}
public void setPreferenceInferrer(PreferenceInferrer inferrer) {
- rankingUserCorrelation.setPreferenceInferrer(inferrer);
+ rankingUserSimilarity.setPreferenceInferrer(inferrer);
}
public void refresh(Collection<Refreshable> alreadyRefreshed) {
alreadyRefreshed = RefreshHelper.buildRefreshed(alreadyRefreshed);
- RefreshHelper.maybeRefresh(alreadyRefreshed, rankingUserCorrelation);
+ RefreshHelper.maybeRefresh(alreadyRefreshed, rankingUserSimilarity);
}
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarity.java (from r688739, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/TanimotoCoefficientCorrelation.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarity.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarity.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/TanimotoCoefficientCorrelation.java&r1=688739&r2=691302&rev=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/correlation/TanimotoCoefficientCorrelation.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarity.java Tue Sep 2 09:22:47 2008
@@ -15,13 +15,13 @@
* 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.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
-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.impl.common.RefreshHelper;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.model.Item;
@@ -43,13 +43,13 @@
*
* <p>The value returned is in [0,1].</p>
*/
-public final class TanimotoCoefficientCorrelation implements UserCorrelation, ItemCorrelation {
+public final class TanimotoCoefficientSimilarity implements UserSimilarity, ItemSimilarity {
- private static final Logger log = LoggerFactory.getLogger(TanimotoCoefficientCorrelation.class);
+ private static final Logger log = LoggerFactory.getLogger(TanimotoCoefficientSimilarity.class);
private final DataModel dataModel;
- public TanimotoCoefficientCorrelation(DataModel dataModel) {
+ public TanimotoCoefficientSimilarity(DataModel dataModel) {
this.dataModel = dataModel;
}
@@ -110,7 +110,7 @@
double result = (double) intersectionSize / (double) unionSize;
if (log.isTraceEnabled()) {
- log.trace("User correlation between " + user1 + " and " + user2 + " is " + result);
+ log.trace("User similarity between " + user1 + " and " + user2 + " is " + result);
}
return result;
}
@@ -165,7 +165,7 @@
double result = (double) intersectionSize / (double) unionSize;
if (log.isTraceEnabled()) {
- log.trace("Item correlation between " + item1 + " and " + item2 + " is " + result);
+ log.trace("Item similarity between " + item1 + " and " + item2 + " is " + result);
}
return result;
}
@@ -177,7 +177,7 @@
@Override
public final String toString() {
- return "TanimotoCoefficientCorrelation[dataModel:" + dataModel + ']';
+ return "TanimotoCoefficientSimilarity[dataModel:" + dataModel + ']';
}
}
\ No newline at end of file
Added: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/ItemSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/ItemSimilarity.java?rev=691302&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/ItemSimilarity.java (added)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/ItemSimilarity.java Tue Sep 2 09:22:47 2008
@@ -0,0 +1,44 @@
+/**
+ * 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.similarity;
+
+import org.apache.mahout.cf.taste.common.Refreshable;
+import org.apache.mahout.cf.taste.common.TasteException;
+import org.apache.mahout.cf.taste.model.Item;
+
+/**
+ * <p>Implementations of this interface define a notion of itemCorrelation between two
+ * {@link org.apache.mahout.cf.taste.model.Item}s. Implementations should return values in the range -1.0 to 1.0, with
+ * 1.0 representing perfect correlation.</p>
+ *
+ * @see UserSimilarity
+ */
+public interface ItemSimilarity extends Refreshable {
+
+ /**
+ * <p>Returns the "itemCorrelation", or degree of similarity, of two {@link org.apache.mahout.cf.taste.model.Item}s, based
+ * on the preferences that {@link org.apache.mahout.cf.taste.model.User}s have expressed for the items.</p>
+ *
+ * @param item1 first item
+ * @param item2 second item
+ * @return itemCorrelation between the {@link org.apache.mahout.cf.taste.model.Item}s
+ * @throws TasteException if an error occurs while accessing the data
+ */
+ double itemCorrelation(Item item1, Item item2) throws TasteException;
+
+}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/PreferenceInferrer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/PreferenceInferrer.java?rev=691302&r1=688739&r2=691302&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/PreferenceInferrer.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/PreferenceInferrer.java Tue Sep 2 09:22:47 2008
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.mahout.cf.taste.correlation;
+package org.apache.mahout.cf.taste.similarity;
import org.apache.mahout.cf.taste.common.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
Added: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/UserSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/UserSimilarity.java?rev=691302&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/UserSimilarity.java (added)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/UserSimilarity.java Tue Sep 2 09:22:47 2008
@@ -0,0 +1,51 @@
+/**
+ * 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.similarity;
+
+import org.apache.mahout.cf.taste.common.Refreshable;
+import org.apache.mahout.cf.taste.common.TasteException;
+import org.apache.mahout.cf.taste.model.User;
+
+/**
+ * <p>Implementations of this interface define a notion of itemCorrelation between two
+ * {@link User}s. Implementations should return values in the range -1.0 to 1.0, with
+ * 1.0 representing perfect correlation.</p>
+ *
+ * @see ItemSimilarity
+ */
+public interface UserSimilarity extends Refreshable {
+
+ /**
+ * <p>Returns the "itemCorrelation", or degree of similarity, of two {@link User}s, based
+ * on the their preferences.</p>
+ *
+ * @param user1 first user
+ * @param user2 second user
+ * @return itemCorrelation between the two users
+ * @throws TasteException if an error occurs while accessing the data
+ */
+ double userCorrelation(User user1, User user2) throws TasteException;
+
+ /**
+ * <p>Attaches a {@link PreferenceInferrer} to the {@link UserSimilarity} implementation.</p>
+ *
+ * @param inferrer {@link PreferenceInferrer}
+ */
+ void setPreferenceInferrer(PreferenceInferrer inferrer);
+
+}