Пример #1
0
        /// <p>
        /// Like {@link #GenericItemSimilarity(ItemSimilarity, DataModel)} )}, but will only keep the specified
        /// number of similarities from the given {@link DataModel}. It will keep those with the highest similarity
        /// -- those that are therefore most important.
        /// </p>
        ///
        /// <p>
        /// Thanks to tsmorton for suggesting this and providing part of the implementation.
        /// </p>
        ///
        /// @param otherSimilarity
        ///          other {@link ItemSimilarity} to get similarities from
        /// @param dataModel
        ///          data model to get items from
        /// @param maxToKeep
        ///          maximum number of similarities to keep
        /// @throws TasteException
        ///           if an error occurs while accessing the {@link DataModel} items
        public GenericItemSimilarity(IItemSimilarity otherSimilarity,
                                     IDataModel dataModel,
                                     int maxToKeep)
        {
            long[] itemIDs          = GenericUserSimilarity.longIteratorToList(dataModel.GetItemIDs());
            var    it               = new DataModelSimilaritiesIterator(otherSimilarity, itemIDs);
            var    keptSimilarities = TopItems.GetTopItemItemSimilarities(maxToKeep, it);

            initSimilarityMaps(keptSimilarities.GetEnumerator());
        }
Пример #2
0
 /// <p>
 /// Builds a list of item-item similarities given an {@link ItemSimilarity} implementation and a
 /// {@link DataModel}, rather than a list of {@link ItemItemSimilarity}s.
 /// </p>
 ///
 /// <p>
 /// It's valid to build a {@link GenericItemSimilarity} this way, but perhaps missing some of the point of an
 /// item-based recommender. Item-based recommenders use the assumption that item-item similarities are
 /// relatively fixed, and might be known already independent of user preferences. Hence it is useful to
 /// inject that information, using {@link #GenericItemSimilarity(Iterable)}.
 /// </p>
 ///
 /// @param otherSimilarity
 ///          other {@link ItemSimilarity} to get similarities from
 /// @param dataModel
 ///          data model to get items from
 /// @throws TasteException
 ///           if an error occurs while accessing the {@link DataModel} items
 public GenericItemSimilarity(IItemSimilarity otherSimilarity, IDataModel dataModel)
 {
     long[] itemIDs = GenericUserSimilarity.longIteratorToList(dataModel.GetItemIDs());
     initSimilarityMaps(new DataModelSimilaritiesIterator(otherSimilarity, itemIDs));
 }