/** * Construct a rating vector that contains the ratings provided for each * item. If all ratings in <var>ratings</var> are by the same user, then * this will be a valid user rating vector. * * @param ratings A collection of ratings (should all be by the same user) * @return A sparse vector mapping item IDs to ratings */ public static Long2DoubleMap userRatingVector(@Nonnull Collection<Rating> ratings) { return extractVector(ratings.iterator(), IdExtractor.ITEM, ratings.size()); }
/** * Construct a rating vector that contains the ratings provided by each user. * If all ratings in <var>ratings</var> are for the same item, then this * will be a valid item rating vector. If multiple ratings are by the same * user, the one with the highest timestamp is retained. If two ratings * by the same user have identical timestamps, then the one that occurs last * when the collection is iterated is retained. * * @param ratings Some ratings (they should all be for the same item) * @return A sparse vector mapping user IDs to ratings. */ public static Long2DoubleMap itemRatingVector(@Nonnull Collection<? extends Rating> ratings) { return extractVector(ratings.iterator(), IdExtractor.USER, ratings.size()); }
/** * Extract a user rating vector from a rating stream. * * @param ratings The rating stream. * @return The user rating vector. * @see #userRatingVector(Collection) */ public static Long2DoubleMap userRatingVector(@WillClose ObjectStream<? extends Rating> ratings) { return extractVector(ratings.iterator(), IdExtractor.ITEM, -1); }
/** * Construct a rating vector that contains the ratings provided for each * item. If all ratings in <var>ratings</var> are by the same user, then * this will be a valid user rating vector. * * @param ratings A collection of ratings (should all be by the same user) * @return A sparse vector mapping item IDs to ratings */ public static Long2DoubleMap userRatingVector(@Nonnull Collection<Rating> ratings) { return extractVector(ratings.iterator(), IdExtractor.ITEM, ratings.size()); }
/** * Construct a rating vector that contains the ratings provided by each user. * If all ratings in <var>ratings</var> are for the same item, then this * will be a valid item rating vector. If multiple ratings are by the same * user, the one with the highest timestamp is retained. If two ratings * by the same user have identical timestamps, then the one that occurs last * when the collection is iterated is retained. * * @param ratings Some ratings (they should all be for the same item) * @return A sparse vector mapping user IDs to ratings. */ public static Long2DoubleMap itemRatingVector(@Nonnull Collection<? extends Rating> ratings) { return extractVector(ratings.iterator(), IdExtractor.USER, ratings.size()); }
/** * Extract a user rating vector from a rating stream. * * @param ratings The rating stream. * @return The user rating vector. * @see #userRatingVector(Collection) */ public static Long2DoubleMap userRatingVector(@WillClose ObjectStream<? extends Rating> ratings) { return extractVector(ratings.iterator(), IdExtractor.ITEM, -1); }