|
||||||||||
| 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
org.apache.mahout.cf.taste.impl.model.PlusAnonymousConcurrentUserDataModel
public final class PlusAnonymousConcurrentUserDataModel
This is a special thread-safe version of PlusAnonymousUserDataModel
which allow multiple concurrent anonymous requests.
To use it, you have to estimate the number of concurrent anonymous users of your application. The pool of users with the given size will be created. For each anonymous recommendations request, a user has to be taken from the pool and returned back immediately afterwards.
If no more users are available in the pool, anonymous recommendations cannot be produced.
Setup:int concurrentUsers = 100; DataModel realModel = .. PlusAnonymousConcurrentUserDataModel plusModel = new PlusAnonymousConcurrentUserDataModel(realModel, concurrentUsers); Recommender recommender = ...;Real-time recommendation:
PlusAnonymousConcurrentUserDataModel plusModel = (PlusAnonymousConcurrentUserDataModel) recommender.getDataModel(); // Take the next available anonymous user from the pool Long anonymousUserID = plusModel.takeAvailableUser(); PreferenceArray tempPrefs = .. tempPrefs.setUserID(0, anonymousUserID); tempPrefs.setItemID(0, itemID); plusModel.setTempPrefs(tempPrefs, anonymousUserID); // Produce recommendations recommender.recommend(anonymousUserID, howMany); // It is very IMPORTANT to release user back to the pool plusModel.releaseUser(anonymousUserID);
| Field Summary |
|---|
| Fields inherited from class org.apache.mahout.cf.taste.impl.model.PlusAnonymousUserDataModel |
|---|
TEMP_USER_ID |
| Constructor Summary | |
|---|---|
PlusAnonymousConcurrentUserDataModel(DataModel delegate,
int maxConcurrentUsers)
|
|
| Method Summary | |
|---|---|
void |
clearTempPrefs(long anonymousUserID)
Clears temporary preferences for a given anonymous user. |
FastIDSet |
getItemIDsFromUser(long userID)
|
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 |
releaseUser(Long userID)
Release previously taken anonymous user and return it to the pool. |
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,
long anonymousUserID)
Sets temporary preferences for a given anonymous user. |
Long |
takeAvailableUser()
Take the next available concurrent anonymous users from the pool. |
| Methods inherited from class org.apache.mahout.cf.taste.impl.model.PlusAnonymousUserDataModel |
|---|
clearTempPrefs, getDelegate, getItemIDs, getMaxPreference, getMinPreference, getNumItems, hasPreferenceValues, refresh, setTempPrefs |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PlusAnonymousConcurrentUserDataModel(DataModel delegate,
int maxConcurrentUsers)
delegate - Real model where anonymous users will be added tomaxConcurrentUsers - Maximum allowed number of concurrent anonymous users| Method Detail |
|---|
public Long takeAvailableUser()
public boolean releaseUser(Long userID)
userID - ID of a previously taken anonymous user
public void setTempPrefs(PreferenceArray prefs,
long anonymousUserID)
public void clearTempPrefs(long anonymousUserID)
public LongPrimitiveIterator getUserIDs()
throws TasteException
getUserIDs in interface DataModelgetUserIDs in class PlusAnonymousUserDataModelTasteException - if an error occurs while accessing the data
public PreferenceArray getPreferencesFromUser(long userID)
throws TasteException
getPreferencesFromUser in interface DataModelgetPreferencesFromUser in class PlusAnonymousUserDataModeluserID - 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 DataModelgetItemIDsFromUser in class PlusAnonymousUserDataModeluserID - ID of user to get prefs for
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data
public PreferenceArray getPreferencesForItem(long itemID)
throws TasteException
getPreferencesForItem in interface DataModelgetPreferencesForItem in class PlusAnonymousUserDataModelitemID - 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 DataModelgetPreferenceValue in class PlusAnonymousUserDataModeluserID - 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 DataModelgetPreferenceTime in class PlusAnonymousUserDataModeluserID - 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 getNumUsers()
throws TasteException
getNumUsers in interface DataModelgetNumUsers in class PlusAnonymousUserDataModelTasteException - if an error occurs while accessing the data
public int getNumUsersWithPreferenceFor(long itemID)
throws TasteException
getNumUsersWithPreferenceFor in interface DataModelgetNumUsersWithPreferenceFor in class PlusAnonymousUserDataModelitemID - 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 DataModelgetNumUsersWithPreferenceFor in class PlusAnonymousUserDataModelitemID1 - 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 DataModelsetPreference in class PlusAnonymousUserDataModeluserID - 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 DataModelremovePreference in class PlusAnonymousUserDataModeluserID - 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 data
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||