|
||||||||||
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.AbstractDataModel
org.apache.mahout.cf.taste.impl.model.GenericDataModel
public final class GenericDataModel
A simple DataModel
which uses a given List
of users as its data source. This implementation
is mostly useful for small experiments and is not recommended for contexts where performance is important.
Constructor Summary | |
---|---|
GenericDataModel(DataModel dataModel)
Deprecated. without direct replacement. Consider toDataMap(DataModel) with GenericDataModel(FastByIDMap) |
|
GenericDataModel(FastByIDMap<PreferenceArray> userData)
Creates a new GenericDataModel from the given users (and their preferences). |
|
GenericDataModel(FastByIDMap<PreferenceArray> userData,
FastByIDMap<FastByIDMap<Long>> timestamps)
Creates a new GenericDataModel from the given users (and their preferences). |
Method Summary | |
---|---|
LongPrimitiveArrayIterator |
getItemIDs()
|
FastIDSet |
getItemIDsFromUser(long userID)
|
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. |
FastByIDMap<PreferenceArray> |
getRawItemData()
This is used mostly internally to the framework, and shouldn't be relied upon otherwise. |
FastByIDMap<PreferenceArray> |
getRawUserData()
This is used mostly internally to the framework, and shouldn't be relied upon otherwise. |
LongPrimitiveArrayIterator |
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. |
static FastByIDMap<PreferenceArray> |
toDataMap(DataModel dataModel)
Exports the simple user IDs and preferences in the data model. |
static FastByIDMap<PreferenceArray> |
toDataMap(FastByIDMap<Collection<Preference>> data,
boolean byUser)
Swaps, in-place, List s for arrays in Map values . |
String |
toString()
|
Methods inherited from class org.apache.mahout.cf.taste.impl.model.AbstractDataModel |
---|
getMaxPreference, getMinPreference, setMaxPreference, setMinPreference |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public GenericDataModel(FastByIDMap<PreferenceArray> userData)
Creates a new GenericDataModel
from the given users (and their preferences). This
DataModel
retains all this information in memory and is effectively immutable.
userData
- users to include; (see also toDataMap(FastByIDMap, boolean)
)public GenericDataModel(FastByIDMap<PreferenceArray> userData, FastByIDMap<FastByIDMap<Long>> timestamps)
Creates a new GenericDataModel
from the given users (and their preferences). This
DataModel
retains all this information in memory and is effectively immutable.
userData
- users to include; (see also toDataMap(FastByIDMap, boolean)
)timestamps
- optionally, provided timestamps of preferences as milliseconds since the epoch.
User IDs are mapped to maps of item IDs to Long timestamps.@Deprecated public GenericDataModel(DataModel dataModel) throws TasteException
toDataMap(DataModel)
with GenericDataModel(FastByIDMap)
Creates a new GenericDataModel
containing an immutable copy of the data from another given
DataModel
.
dataModel
- DataModel
to copy
TasteException
- if an error occurs while retrieving the other DataModel
's usersMethod Detail |
---|
public static FastByIDMap<PreferenceArray> toDataMap(FastByIDMap<Collection<Preference>> data, boolean byUser)
List
s for arrays in Map
values .
public static FastByIDMap<PreferenceArray> toDataMap(DataModel dataModel) throws TasteException
FastByIDMap
mapping user IDs to PreferenceArray
s representing
that user's preferences
TasteException
public FastByIDMap<PreferenceArray> getRawUserData()
public FastByIDMap<PreferenceArray> getRawItemData()
public LongPrimitiveArrayIterator getUserIDs()
public PreferenceArray getPreferencesFromUser(long userID) throws NoSuchUserException
userID
- ID of user to get prefs for
NoSuchUserException
- if there is no such userpublic FastIDSet getItemIDsFromUser(long userID) throws TasteException
userID
- ID of user to get prefs for
NoSuchUserException
- if the user does not exist
TasteException
- if an error occurs while accessing the datapublic LongPrimitiveArrayIterator getItemIDs()
LongPrimitiveIterator
of all item IDs in the model, in orderpublic PreferenceArray getPreferencesForItem(long itemID) throws NoSuchItemException
itemID
- item ID
Preference
s expressed for that item, ordered by user ID, as an array
NoSuchItemException
- if the item does not existpublic Float getPreferenceValue(long userID, long itemID) throws TasteException
DataModel
userID
- 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 datapublic Long getPreferenceTime(long userID, long itemID) throws TasteException
DataModel
userID
- 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 datapublic int getNumItems()
public int getNumUsers()
public int getNumUsersWithPreferenceFor(long itemID)
itemID
- item ID to check for
public int getNumUsersWithPreferenceFor(long itemID1, long itemID2)
itemID1
- first item ID to check foritemID2
- second item ID to check for
public void removePreference(long userID, long itemID)
DataModel
Removes a particular preference for a user.
userID
- user from which to remove preferenceitemID
- item to remove preference forpublic void setPreference(long userID, long itemID, float value)
DataModel
Sets a particular preference (item plus rating) for a user.
userID
- user to set preference foritemID
- item to set preference forvalue
- preference valuepublic 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.
alreadyRefreshed
- Refreshable
s 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()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |