org.lenskit.data.ratings

## Interface RatingMatrix

• All Known Implementing Classes:
PackedRatingMatrix

@Immutable
@DefaultImplementation(value=PackedRatingMatrix.class)
public interface RatingMatrix

Snapshot of the ratings data for building a recommender.

This provides a snapshot of each user’s most current rating for each item. It may also represent synthetic ratings derived from other types of events, depending on the builder that is used for it.

The ratings obtained from a rating matrix do not have timestamps.

The users, items, and ratings in the rating matrix are associated with 0-based indexes, so that they can be used in conjunction with vectors or arrays. The rating matrix can be thought of as a sparse matrix in coordinate list (COO) format, and the index of the rating is its position in the coordinate list.

• ### Method Summary

All Methods
Modifier and Type Method and Description
LongCollection getItemIds()
Get the set of item IDs in the snapshot.
List<RatingMatrixEntry> getRatings()
Get the collection of ratings in the snapshot.
LongCollection getUserIds()
Get the set of user IDs in the snapshot.
Collection<RatingMatrixEntry> getUserRatings(long userId)
Get the ratings for a particular user.
Long2DoubleMap getUserRatingVector(long userId)
Get the current preferences of a particular user as a vector.
KeyIndex itemIndex()
Get the item ID index.
KeyIndex userIndex()
Get the user ID index.
• ### Method Detail

• #### getUserIds

LongCollection getUserIds()

Get the set of user IDs in the snapshot.

Returns:
A set of all known user IDs.
• #### getItemIds

LongCollection getItemIds()

Get the set of item IDs in the snapshot.

Returns:
A set of all known item IDs.
• #### userIndex

KeyIndex userIndex()

Get the user ID index.

Returns:
The index mapping between user IDs and user indices.
• #### itemIndex

KeyIndex itemIndex()

Get the item ID index.

Returns:
The index mapping between user IDs and user indices.
• #### getRatings

List<RatingMatrixEntry> getRatings()

Get the collection of ratings in the snapshot. The ratings are returned in an undetermined order. It is guaranteed that no duplicate ratings appear - each (user,item) pair is rated at most once. Each preference’s index is also in the range [0,len), where len is the size of this collection.

Modifying the returned indexed preferences will not modify the underlying snapshot.

Returns:
All ratings in the system.
• #### getUserRatings

Collection<RatingMatrixEntry> getUserRatings(long userId)

Get the ratings for a particular user. It is guaranteed that no duplicate ratings appear - each (user,item) pair is rated at most once.

Modifying the returned indexed preferences will not modify the underlying snapshot.

Parameters:
userId - The user’s ID.
Returns:
The user’s ratings, or an empty collection if the user is unknown.
• #### getUserRatingVector

Long2DoubleMap getUserRatingVector(long userId)

Get the current preferences of a particular user as a vector.

Parameters:
userId - The user’s ID.
Returns:
The user’s rating vector.