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 CachingRecommender(Recommender recommender)
        {
            Action refreshRunnable = null;

            this.recommender = recommender;
            this.maxHowMany  = new int[] { 1 };
            int maxEntries = recommender.getDataModel().getNumUsers();

            this.recommendationsRetriever = new RecommendationRetriever(this);
            this.recommendationCache      = new Cache <long, Recommendations>(this.recommendationsRetriever, maxEntries);
            this.estimatedPrefCache       = new Cache <Tuple <long, long>, float>(new EstimatedPrefRetriever(this), maxEntries);
            if (refreshRunnable == null)
            {
                refreshRunnable = () => this.clear();
            }
            this.refreshHelper = new RefreshHelper(refreshRunnable);
            this.refreshHelper.addDependency(recommender);
        }
Beispiel #3
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);
                }
            }
        }