/// <summary>
        /// Initializes a new instance of the
        /// <see cref="RecommenderEvaluator{TInstanceSource, TUser, TItem, TGroundTruthRating, TPredictedRating, TPredictedRatingDist}"/> class.
        /// </summary>
        /// <param name="mapping">The mapping used for accessing data.</param>
        /// <exception cref="ArgumentNullException">Thrown if the given mapping is null.</exception>
        public RecommenderEvaluator(IRecommenderEvaluatorMapping <TInstanceSource, TUser, TItem, TGroundTruthRating> mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException("mapping");
            }

            this.mapping = mapping;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds all the items which have been rated by the same user as <paramref name="queryItem"/>.
        /// </summary>
        /// <typeparam name="TInstanceSource">The type of a source of instances.</typeparam>
        /// <typeparam name="TUser">The type of a user.</typeparam>
        /// <typeparam name="TItem">The type of an item.</typeparam>
        /// <typeparam name="TRating">The type of a rating.</typeparam>
        /// <param name="mapping">The mapping.</param>
        /// <param name="instanceSource">The instance source with items.</param>
        /// <param name="queryItem">The query item.</param>
        /// <returns>
        /// A dictionary which maps items from the <paramref name="instanceSource"/> to the lists of users
        /// who has rated both the item and <paramref name="queryItem"/>. Only items with at least one such user are returned.
        /// </returns>
        public static Dictionary <TItem, List <TUser> > GetItemsRatedBySameUsers <TInstanceSource, TUser, TItem, TRating>(
            this IRecommenderEvaluatorMapping <TInstanceSource, TUser, TItem, TRating> mapping,
            TInstanceSource instanceSource,
            TItem queryItem)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException("mapping");
            }

            return(GetEntitiesWithCommonRatedEntities(
                       queryItem,
                       i => mapping.GetUsersWhoRatedItem(instanceSource, i),
                       u => mapping.GetItemsRatedByUser(instanceSource, u)));
        }