## org.apache.mahout.cf.taste.model
Interface DataModel

All Superinterfaces:
  Refreshable, Serializable

All Known Subinterfaces:
  JDBCDataModel

All Known Implementing Classes:
  AbstractDataModel, FileDataModel, GenericBooleanPrefDataModel, GenericDataModel, PlusAnonymousConcurrentUserDataModel, PlusAnonymousUserDataModel

    public interface DataModel

extends Refreshable, Serializable

Implementations represent a repository of information about users and their associated `Preference`s for items.

Method Summary
`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` `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.

Methods inherited from interface org.apache.mahout.cf.taste.common.Refreshable
`refresh`

Method Detail

### getUserIDs

    LongPrimitiveIterator getUserIDs()
                                     throws TasteException

  Returns:
    all user IDs in the model, in order
  Throws:
    `TasteException` - if an error occurs while accessing the data

### getPreferencesFromUser

    PreferenceArray getPreferencesFromUser(long userID)
                                           throws TasteException

  Parameters:
    `userID` - ID of user to get prefs for
  Returns:
    user's preferences, ordered by item ID
  Throws:
    `NoSuchUserException` - if the user does not exist
    `TasteException` - if an error occurs while accessing the data

### getItemIDsFromUser

    FastIDSet getItemIDsFromUser(long userID)
                                 throws TasteException

  Parameters:
    `userID` - ID of user to get prefs for
  Returns:
    IDs of items user expresses a preference for
  Throws:
    `NoSuchUserException` - if the user does not exist
    `TasteException` - if an error occurs while accessing the data

### getItemIDs

    LongPrimitiveIterator getItemIDs()
                                     throws TasteException

  Returns:
    a `LongPrimitiveIterator` of all item IDs in the model, in order
  Throws:
    `TasteException` - if an error occurs while accessing the data

### getPreferencesForItem

    PreferenceArray getPreferencesForItem(long itemID)
                                          throws TasteException

  Parameters:
    `itemID` - item ID
  Returns:
    all existing `Preference`s expressed for that item, ordered by user ID, as an array
  Throws:
    `NoSuchItemException` - if the item does not exist
    `TasteException` - if an error occurs while accessing the data

### getPreferenceValue

    Float getPreferenceValue(long userID,
                             long itemID)
                             throws TasteException

  Retrieves the preference value for a single user and item.

  Parameters:
    `userID` - user ID to get pref value from
    `itemID` - item ID to get pref value for
  Returns:
    preference value from the given user for the given item or null if none exists
  Throws:
    `NoSuchUserException` - if the user does not exist
    `TasteException` - if an error occurs while accessing the data

### getPreferenceTime

    Long getPreferenceTime(long userID,
                           long itemID)
                           throws TasteException

  Retrieves the time at which a preference value from a user and item was set, if known. Time is expressed in the usual way, as a number of milliseconds since the epoch.

  Parameters:
    `userID` - user ID for preference in question
    `itemID` - item ID for preference in question
  Returns:
    time at which preference was set or null if no preference exists or its time is not known
  Throws:
    `NoSuchUserException` - if the user does not exist
    `TasteException` - if an error occurs while accessing the data

### getNumItems

    int getNumItems()
                    throws TasteException

  Returns:
    total number of items known to the model. This is generally the union of all items preferred by at least one user but could include more.
  Throws:
    `TasteException` - if an error occurs while accessing the data

### getNumUsers

    int getNumUsers()
                    throws TasteException

  Returns:
    total number of users known to the model.
  Throws:
    `TasteException` - if an error occurs while accessing the data

### getNumUsersWithPreferenceFor

    int getNumUsersWithPreferenceFor(long itemID)
                                     throws TasteException

  Parameters:
    `itemID` - item ID to check for
  Returns:
    the number of users who have expressed a preference for the item
  Throws:
    `TasteException` - if an error occurs while accessing the data

### getNumUsersWithPreferenceFor

    int getNumUsersWithPreferenceFor(long itemID1,
                                     long itemID2)
                                     throws TasteException

  Parameters:
    `itemID1` - first item ID to check for
    `itemID2` - second item ID to check for
  Returns:
    the number of users who have expressed a preference for the items
  Throws:
    `TasteException` - if an error occurs while accessing the data

### setPreference

    void setPreference(long userID,
                       long itemID,
                       float value)
                       throws TasteException

  Sets a particular preference (item plus rating) for a user.

  Parameters:
    `userID` - user to set preference for
    `itemID` - item to set preference for
    `value` - preference value
  Throws:
    `NoSuchItemException` - if the item does not exist
    `NoSuchUserException` - if the user does not exist
    `TasteException` - if an error occurs while accessing the data

### removePreference

    void removePreference(long userID,
                          long itemID)
                          throws TasteException

  Removes a particular preference for a user.

  Parameters:
    `userID` - user from which to remove preference
    `itemID` - item to remove preference for
  Throws:
    `NoSuchItemException` - if the item does not exist
    `NoSuchUserException` - if the user does not exist
    `TasteException` - if an error occurs while accessing the data

### hasPreferenceValues

    boolean hasPreferenceValues()

  Returns:
    true if this implementation actually stores and returns distinct preference values; that is, if it is not a 'boolean' DataModel

### getMaxPreference

    float getMaxPreference()

  Returns:
    the maximum preference value that is possible in the current problem domain being evaluated. For example, if the domain is movie ratings on a scale of 1 to 5, this should be 5. While a `Recommender` 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 `Recommender`

### getMinPreference

    float getMinPreference()

  See Also:
    `getMaxPreference()`

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.