public static void evaluate(Recommender recommender, DataModel model, int samples, RunningAverage tracker, string tag)
        {
            printHeader();
            IEnumerator <long> enumerator = recommender.getDataModel().getUserIDs();

            while (enumerator.MoveNext())
            {
                long current = enumerator.Current;
                List <RecommendedItem> items = recommender.recommend(current, model.getNumItems());
                PreferenceArray        prefs = model.getPreferencesFromUser(current);
                prefs.sortByValueReversed();
                FastIDSet modelSet = new FastIDSet();
                long      num2     = setBits(modelSet, items, samples);
                FastIDSet set2     = new FastIDSet();
                num2 = Math.Max(num2, setBits(set2, prefs, samples));
                int max = Math.Min(mask(modelSet, set2, num2), samples);
                if (max >= 2)
                {
                    long[] itemsL = getCommonItems(modelSet, items, max);
                    long[] itemsR = getCommonItems(modelSet, prefs, max);
                    double datum  = scoreCommonSubset(tag, current, samples, max, itemsL, itemsR);
                    tracker.addDatum(datum);
                }
            }
        }
Beispiel #2
0
        public static LoadStatistics runLoad(Recommender recommender, int howMany)
        {
            DataModel          model        = recommender.getDataModel();
            int                num          = model.getNumUsers();
            double             samplingRate = 1000.0 / ((double)num);
            IEnumerator <long> enumerator   = SamplingLongPrimitiveIterator.maybeWrapIterator(model.getUserIDs(), samplingRate);

            if (enumerator.MoveNext())
            {
                recommender.recommend(enumerator.Current, howMany);
            }
            List <Action> callables = new List <Action>();

            while (enumerator.MoveNext())
            {
                callables.Add(new Action(new LoadCallable(recommender, enumerator.Current).call));
            }
            AtomicInteger           noEstimateCounter = new AtomicInteger();
            RunningAverageAndStdDev timing            = new FullRunningAverageAndStdDev();

            AbstractDifferenceRecommenderEvaluator.execute(callables, noEstimateCounter, timing);
            return(new LoadStatistics(timing));
        }
        public static void evaluate(Recommender recommender1, Recommender recommender2, int samples, RunningAverage tracker, string tag)
        {
            printHeader();
            IEnumerator <long> enumerator = recommender1.getDataModel().getUserIDs();

            while (enumerator.MoveNext())
            {
                long current = enumerator.Current;
                List <RecommendedItem> items = recommender1.recommend(current, samples);
                List <RecommendedItem> list2 = recommender2.recommend(current, samples);
                FastIDSet modelSet           = new FastIDSet();
                long      num2 = setBits(modelSet, items, samples);
                FastIDSet set2 = new FastIDSet();
                num2 = Math.Max(num2, setBits(set2, list2, samples));
                int max = Math.Min(mask(modelSet, set2, num2), samples);
                if (max >= 2)
                {
                    long[] itemsL = getCommonItems(modelSet, items, max);
                    long[] itemsR = getCommonItems(modelSet, list2, max);
                    double datum  = scoreCommonSubset(tag, current, samples, max, itemsL, itemsR);
                    tracker.addDatum(datum);
                }
            }
        }
        public IRStatistics evaluate(RecommenderBuilder recommenderBuilder, DataModelBuilder dataModelBuilder, DataModel dataModel, IDRescorer rescorer, int at, double relevanceThreshold, double evaluationPercentage)
        {
            int                num        = dataModel.getNumItems();
            RunningAverage     average    = new FullRunningAverage();
            RunningAverage     average2   = new FullRunningAverage();
            RunningAverage     average3   = new FullRunningAverage();
            RunningAverage     average4   = new FullRunningAverage();
            int                num2       = 0;
            int                num3       = 0;
            IEnumerator <long> enumerator = dataModel.getUserIDs();

            while (enumerator.MoveNext())
            {
                long current = enumerator.Current;
                if (this.random.nextDouble() < evaluationPercentage)
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    PreferenceArray prefs           = dataModel.getPreferencesFromUser(current);
                    double          num5            = double.IsNaN(relevanceThreshold) ? computeThreshold(prefs) : relevanceThreshold;
                    FastIDSet       relevantItemIDs = this.dataSplitter.getRelevantItemsIDs(current, at, num5, dataModel);
                    int             num6            = relevantItemIDs.size();
                    if (num6 > 0)
                    {
                        FastByIDMap <PreferenceArray> trainingUsers = new FastByIDMap <PreferenceArray>(dataModel.getNumUsers());
                        IEnumerator <long>            enumerator2   = dataModel.getUserIDs();
                        while (enumerator2.MoveNext())
                        {
                            this.dataSplitter.processOtherUser(current, relevantItemIDs, trainingUsers, enumerator2.Current, dataModel);
                        }
                        DataModel model = (dataModelBuilder == null) ? new GenericDataModel(trainingUsers) : dataModelBuilder.buildDataModel(trainingUsers);
                        try
                        {
                            model.getPreferencesFromUser(current);
                        }
                        catch (NoSuchUserException)
                        {
                            continue;
                        }
                        int num7 = num6 + model.getItemIDsFromUser(current).size();
                        if (num7 >= (2 * at))
                        {
                            Recommender            recommender = recommenderBuilder.buildRecommender(model);
                            int                    num8        = 0;
                            List <RecommendedItem> list        = recommender.recommend(current, at, rescorer);
                            foreach (RecommendedItem item in list)
                            {
                                if (relevantItemIDs.contains(item.getItemID()))
                                {
                                    num8++;
                                }
                            }
                            int count = list.Count;
                            if (count > 0)
                            {
                                average.addDatum(((double)num8) / ((double)count));
                            }
                            average2.addDatum(((double)num8) / ((double)num6));
                            if (num6 < num7)
                            {
                                average3.addDatum(((double)(count - num8)) / ((double)(num - num6)));
                            }
                            double num10 = 0.0;
                            double num11 = 0.0;
                            for (int i = 0; i < count; i++)
                            {
                                RecommendedItem item2 = list[i];
                                double          num13 = 1.0 / log2(i + 2.0);
                                if (relevantItemIDs.contains(item2.getItemID()))
                                {
                                    num10 += num13;
                                }
                                if (i < num6)
                                {
                                    num11 += num13;
                                }
                            }
                            if (num11 > 0.0)
                            {
                                average4.addDatum(num10 / num11);
                            }
                            num2++;
                            if (count > 0)
                            {
                                num3++;
                            }
                            stopwatch.Stop();
                            log.info("Evaluated with user {} in {}ms", new object[] { current, stopwatch.ElapsedMilliseconds });
                            log.info("Precision/recall/fall-out/nDCG/reach: {} / {} / {} / {} / {}", new object[] { average.getAverage(), average2.getAverage(), average3.getAverage(), average4.getAverage(), ((double)num3) / ((double)num2) });
                        }
                    }
                }
            }
            return(new IRStatisticsImpl(average.getAverage(), average2.getAverage(), average3.getAverage(), average4.getAverage(), ((double)num3) / ((double)num2)));
        }