com.planetj.taste.impl.recommender
Class GenericItemBasedRecommender

java.lang.Object
  extended by com.planetj.taste.impl.recommender.AbstractRecommender
      extended by com.planetj.taste.impl.recommender.GenericItemBasedRecommender
All Implemented Interfaces:
Refreshable, ItemBasedRecommender, Recommender

public final class GenericItemBasedRecommender
extends AbstractRecommender
implements ItemBasedRecommender

A simple Recommender which uses a given DataModel and ItemCorrelation to produce recommendations. This class represents Taste's support for item-based recommenders.

The ItemCorrelation 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.

Thus it's strongly recommended that you use GenericItemCorrelation with pre-computed correlations if you're going to use this class. You can use PearsonCorrelation too, which computes correlations in real-time, but will probably find this painfully slow for large amounts of data.

Author:
Sean Owen

Constructor Summary
GenericItemBasedRecommender(DataModel dataModel, ItemCorrelation correlation)
           
 
Method Summary
 double estimatePreference(java.lang.Object userID, java.lang.Object itemID)
          
 java.util.List<RecommendedItem> mostSimilarItems(java.util.List<java.lang.Object> itemIDs, int howMany)
          
 java.util.List<RecommendedItem> mostSimilarItems(java.util.List<java.lang.Object> itemIDs, int howMany, Rescorer<Pair<Item,Item>> rescorer)
          
 java.util.List<RecommendedItem> mostSimilarItems(java.lang.Object itemID, int howMany)
          
 java.util.List<RecommendedItem> mostSimilarItems(java.lang.Object itemID, int howMany, Rescorer<Pair<Item,Item>> rescorer)
          
 java.util.List<RecommendedItem> recommend(java.lang.Object userID, int howMany, Rescorer<Item> rescorer)
          
 java.util.List<RecommendedItem> recommendedBecause(java.lang.Object userID, java.lang.Object itemID, int howMany)
          

Lists the Items that were most influential in recommending a given item to a given user.

 void refresh()
          

Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any Refreshable should always leave itself in a consistent, operational state, and that the refresh atomically updates internal state from old to new.

 java.lang.String toString()
           
 
Methods inherited from class com.planetj.taste.impl.recommender.AbstractRecommender
getAllOtherItems, getDataModel, recommend, removePreference, setPreference
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.planetj.taste.recommender.Recommender
getDataModel, recommend, removePreference, setPreference
 

Constructor Detail

GenericItemBasedRecommender

public GenericItemBasedRecommender(DataModel dataModel,
                                   ItemCorrelation correlation)
Method Detail

recommend

@NotNull
public java.util.List<RecommendedItem> recommend(java.lang.Object userID,
                                                         int howMany,
                                                         Rescorer<Item> rescorer)
                                          throws TasteException

Specified by:
recommend in interface Recommender
Parameters:
userID - user for which recommendations are to be computed
howMany - desired number of recommendations
rescorer - rescoring function to apply before final list of recommendations is determined
Returns:
List of recommended RecommendedItems, ordered from most strongly recommend to least
Throws:
TasteException - if an error occurs while accessing the DataModel

estimatePreference

public double estimatePreference(java.lang.Object userID,
                                 java.lang.Object itemID)
                          throws TasteException

Specified by:
estimatePreference in interface Recommender
Parameters:
userID - user ID whose preference is to be estimated
itemID - item ID to estimate preference for
Returns:
an estimated preference if the user has not expressed a preference for the item, or else the user's actual preference for the item. If a preference cannot be estimated, returns Double.NaN
Throws:
TasteException - if an error occurs while accessing the DataModel

mostSimilarItems

@NotNull
public java.util.List<RecommendedItem> mostSimilarItems(java.lang.Object itemID,
                                                                int howMany)
                                                 throws TasteException

Specified by:
mostSimilarItems in interface ItemBasedRecommender
Parameters:
itemID - ID of Item for which to find most similar other Items
howMany - desired number of most similar Items to find
Returns:
Items most similar to the given item, ordered from most similar to least
Throws:
TasteException - if an error occurs while accessing the DataModel

mostSimilarItems

@NotNull
public java.util.List<RecommendedItem> mostSimilarItems(java.lang.Object itemID,
                                                                int howMany,
                                                                Rescorer<Pair<Item,Item>> rescorer)
                                                 throws TasteException

Specified by:
mostSimilarItems in interface ItemBasedRecommender
Parameters:
itemID - ID of Item for which to find most similar other Items
howMany - desired number of most similar Items to find
rescorer - Rescorer which can adjust item-item correlation estimates used to determine most similar items
Returns:
Items most similar to the given item, ordered from most similar to least
Throws:
TasteException - if an error occurs while accessing the DataModel

mostSimilarItems

@NotNull
public java.util.List<RecommendedItem> mostSimilarItems(java.util.List<java.lang.Object> itemIDs,
                                                                int howMany)
                                                 throws TasteException

Specified by:
mostSimilarItems in interface ItemBasedRecommender
Parameters:
itemIDs - IDs of Item for which to find most similar other Items
howMany - desired number of most similar Items to find estimates used to determine most similar items
Returns:
Items most similar to the given items, ordered from most similar to least
Throws:
TasteException - if an error occurs while accessing the DataModel

mostSimilarItems

@NotNull
public java.util.List<RecommendedItem> mostSimilarItems(java.util.List<java.lang.Object> itemIDs,
                                                                int howMany,
                                                                Rescorer<Pair<Item,Item>> rescorer)
                                                 throws TasteException

Specified by:
mostSimilarItems in interface ItemBasedRecommender
Parameters:
itemIDs - IDs of Item for which to find most similar other Items
howMany - desired number of most similar Items to find
rescorer - Rescorer which can adjust item-item correlation estimates used to determine most similar items
Returns:
Items most similar to the given items, ordered from most similar to least
Throws:
TasteException - if an error occurs while accessing the DataModel

recommendedBecause

@NotNull
public java.util.List<RecommendedItem> recommendedBecause(java.lang.Object userID,
                                                                  java.lang.Object itemID,
                                                                  int howMany)
                                                   throws TasteException

Lists the Items that were most influential in recommending a given item to a given user. Exactly how this is determined is left to the implementation, but, generally this will return items that the user prefers and that are similar to the given item.

This returns a List of RecommendedItem which is a little misleading since it's returning recommending items, but, I thought it more natural to just reuse this class since it encapsulates an Item and value. The value here does not necessarily have a consistent interpretation or expected range; it will be higher the more influential the Item was in the recommendation.

Specified by:
recommendedBecause in interface ItemBasedRecommender
Parameters:
userID - ID of User who was recommended the Item
itemID - ID of Item that was recommended
howMany - maximum number of Items to return
Returns:
List of RecommendedItem, ordered from most influential in recommended the given Item to least
Throws:
TasteException - if an error occurs while accessing the DataModel

refresh

public void refresh()

Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any Refreshable should always leave itself in a consistent, operational state, and that the refresh atomically updates internal state from old to new.

Specified by:
refresh in interface Refreshable
Overrides:
refresh in class AbstractRecommender

toString

@NotNull
public java.lang.String toString()
Overrides:
toString in class java.lang.Object