|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.mahout.cf.taste.impl.model.PlusAnonymousUserDataModel
public class PlusAnonymousUserDataModel
This DataModel decorator class is useful in a situation where you wish to recommend to a user that
doesn't really exist yet in your actual DataModel. For example maybe you wish to recommend DVDs to
a user who has browsed a few titles on your DVD store site, but, the user is not yet registered.
This enables you to temporarily add a temporary user to an existing DataModel in a way that
recommenders can then produce recommendations anyway. To do so, wrap your real implementation in this
class:
DataModel realModel = ...; DataModel plusModel = new PlusAnonymousUserDataModel(realModel); ... ItemSimilarity similarity = new LogLikelihoodSimilarity(realModel); // not plusModel
But, you may continue to use realModel as input to other components. To recommend, first construct and
set the temporary user information on the model and then simply call the recommender. The
synchronized block exists to remind you that this is of course not thread-safe. Only one set
of temp data can be inserted into the model and used at one time.
Recommender recommender = ...;
...
synchronized(...) {
PreferenceArray tempPrefs = ...;
plusModel.setTempPrefs(tempPrefs);
recommender.recommend(PlusAnonymousUserDataModel.TEMP_USER_ID, 10);
plusModel.setTempPrefs(null);
}
| Field Summary | |
|---|---|
static long |
TEMP_USER_ID
|
| Constructor Summary | |
|---|---|
PlusAnonymousUserDataModel(DataModel delegate)
|
|
| Method Summary | |
|---|---|
void |
clearTempPrefs()
|
protected DataModel |
getDelegate()
|
LongPrimitiveIterator |
getItemIDs()
|
FastIDSet |
getItemIDsFromUser(long userID)
|
float |
getMaxPreference()
|
float |
getMinPreference()
|
int |
getNumItems()
|
int |
getNumUsers()
|
int |
getNumUsersWithPreferenceFor(long itemID)
|
int |
getNumUsersWithPreferenceFor(long itemID1,
long itemID2)
|
PreferenceArray |
getPreferencesForItem(long itemID)
|
PreferenceArray |
getPreferencesFromUser(long userID)
|
Long |
getPreferenceTime(long userID,
long itemID)
Retrieves the time at which a preference value from a user and item was set, if known. |
Float |
getPreferenceValue(long userID,
long itemID)
Retrieves the preference value for a single user and item. |
LongPrimitiveIterator |
getUserIDs()
|
boolean |
hasPreferenceValues()
|
void |
refresh(Collection<Refreshable> alreadyRefreshed)
Triggers "refresh" -- whatever that means -- of the implementation. |
void |
removePreference(long userID,
long itemID)
Removes a particular preference for a user. |
void |
setPreference(long userID,
long itemID,
float value)
Sets a particular preference (item plus rating) for a user. |
void |
setTempPrefs(PreferenceArray prefs)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long TEMP_USER_ID
| Constructor Detail |
|---|
public PlusAnonymousUserDataModel(DataModel delegate)
| Method Detail |
|---|
protected DataModel getDelegate()
public void setTempPrefs(PreferenceArray prefs)
public void clearTempPrefs()
public LongPrimitiveIterator getUserIDs()
throws TasteException
getUserIDs in interface DataModelTasteException - if an error occurs while accessing the data
public PreferenceArray getPreferencesFromUser(long userID)
throws TasteException
getPreferencesFromUser in interface DataModeluserID - ID of user to get prefs for
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data
public FastIDSet getItemIDsFromUser(long userID)
throws TasteException
getItemIDsFromUser in interface DataModeluserID - ID of user to get prefs for
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data
public LongPrimitiveIterator getItemIDs()
throws TasteException
getItemIDs in interface DataModelLongPrimitiveIterator of all item IDs in the model, in order
TasteException - if an error occurs while accessing the data
public PreferenceArray getPreferencesForItem(long itemID)
throws TasteException
getPreferencesForItem in interface DataModelitemID - item ID
Preferences expressed for that item, ordered by user ID, as an array
NoSuchItemException - if the item does not exist
TasteException - if an error occurs while accessing the data
public Float getPreferenceValue(long userID,
long itemID)
throws TasteException
DataModel
getPreferenceValue in interface DataModeluserID - user ID to get pref value fromitemID - item ID to get pref value for
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data
public Long getPreferenceTime(long userID,
long itemID)
throws TasteException
DataModel
getPreferenceTime in interface DataModeluserID - user ID for preference in questionitemID - item ID for preference in question
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data
public int getNumItems()
throws TasteException
getNumItems in interface DataModelTasteException - if an error occurs while accessing the data
public int getNumUsers()
throws TasteException
getNumUsers in interface DataModelTasteException - if an error occurs while accessing the data
public int getNumUsersWithPreferenceFor(long itemID)
throws TasteException
getNumUsersWithPreferenceFor in interface DataModelitemID - item ID to check for
TasteException - if an error occurs while accessing the data
public int getNumUsersWithPreferenceFor(long itemID1,
long itemID2)
throws TasteException
getNumUsersWithPreferenceFor in interface DataModelitemID1 - first item ID to check foritemID2 - second item ID to check for
TasteException - if an error occurs while accessing the data
public void setPreference(long userID,
long itemID,
float value)
throws TasteException
DataModelSets a particular preference (item plus rating) for a user.
setPreference in interface DataModeluserID - user to set preference foritemID - item to set preference forvalue - preference value
NoSuchItemException - if the item does not exist
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data
public void removePreference(long userID,
long itemID)
throws TasteException
DataModelRemoves a particular preference for a user.
removePreference in interface DataModeluserID - user from which to remove preferenceitemID - item to remove preference for
NoSuchItemException - if the item does not exist
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the datapublic void refresh(Collection<Refreshable> alreadyRefreshed)
Refreshable
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.
refresh in interface RefreshablealreadyRefreshed - Refreshables that are known to have already been
refreshed as a result of an initial call to a Refreshable.refresh(Collection) method on some
object. This ensure that objects in a refresh dependency graph aren't refreshed twice
needlessly.public boolean hasPreferenceValues()
hasPreferenceValues in interface DataModelpublic float getMaxPreference()
getMaxPreference in interface DataModelRecommender may estimate a preference value above 5.0, it
isn't "fair" to consider that the system is actually suggesting an impossible rating of, say, 5.4 stars.
In practice the application would cap this estimate to 5.0. Since evaluators evaluate
the difference between estimated and actual value, this at least prevents this effect from unfairly
penalizing a Recommenderpublic float getMinPreference()
getMinPreference in interface DataModelDataModel.getMaxPreference()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||