Esempio n. 1
0
        public static List <RecommendedItem> getTopItems(int howMany, IEnumerator <long> possibleItemIDs, IDRescorer rescorer, Estimator <long> estimator)
        {
            SortedSet <RecommendedItem> collection = new SortedSet <RecommendedItem>(ByValueRecommendedItemComparator.getReverseInstance());
            bool   flag             = false;
            double negativeInfinity = double.NegativeInfinity;

            while (possibleItemIDs.MoveNext())
            {
                long current = possibleItemIDs.Current;
                if ((rescorer == null) || !rescorer.isFiltered(current))
                {
                    double num3;
                    try
                    {
                        num3 = estimator.estimate(current);
                    }
                    catch (NoSuchItemException)
                    {
                        continue;
                    }
                    double d = (rescorer == null) ? num3 : rescorer.rescore(current, num3);
                    if (!double.IsNaN(d) && (!flag || (d > negativeInfinity)))
                    {
                        collection.Add(new GenericRecommendedItem(current, (float)d));
                        if (flag)
                        {
                            collection.Remove(collection.Min);
                        }
                        else if (collection.Count > howMany)
                        {
                            flag = true;
                            collection.Remove(collection.Min);
                        }
                        negativeInfinity = collection.Min.getValue();
                    }
                }
            }
            int count = collection.Count;

            if (count == 0)
            {
                return(new List <RecommendedItem>());
            }
            List <RecommendedItem> list = new List <RecommendedItem>(count);

            list.AddRange(collection);
            list.Reverse();
            return(list);
        }
Esempio n. 2
0
        public static long[] getTopUsers(int howMany, IEnumerator <long> allUserIDs, IDRescorer rescorer, Estimator <long> estimator)
        {
            SortedSet <SimilarUser> set = new SortedSet <SimilarUser>();
            bool   flag             = false;
            double negativeInfinity = double.NegativeInfinity;

            while (allUserIDs.MoveNext())
            {
                long current = allUserIDs.Current;
                if ((rescorer == null) || !rescorer.isFiltered(current))
                {
                    double num3;
                    try
                    {
                        num3 = estimator.estimate(current);
                    }
                    catch (NoSuchUserException)
                    {
                        continue;
                    }
                    double d = (rescorer == null) ? num3 : rescorer.rescore(current, num3);
                    if (!double.IsNaN(d) && (!flag || (d > negativeInfinity)))
                    {
                        set.Add(new SimilarUser(current, d));
                        if (flag)
                        {
                            set.Remove(set.Max);
                        }
                        else if (set.Count > howMany)
                        {
                            flag = true;
                            set.Remove(set.Max);
                        }
                        negativeInfinity = set.Max.getSimilarity();
                    }
                }
            }
            int count = set.Count;

            if (count == 0)
            {
                return(NO_IDS);
            }
            List <SimilarUser> list = new List <SimilarUser>(count);

            return((from s in set select s.getUserID()).ToArray <long>());
        }