Beispiel #1
0
        private void pruneInconsequentialDiffs()
        {
            // Go back and prune inconsequential diffs. "Inconsequential" means, here, only represented by one
            // data point, so possibly unreliable
            var it1 = averageDiffs.entrySet().ToList();

            for (int i = 0; i < it1.Count; i++)
            {
                FastByIDMap <RunningAverage> map = it1[i].Value;

                var it2 = map.entrySet().ToList();
                for (int j = 0; j < it2.Count; j++)
                {
                    RunningAverage average = it2[j].Value;
                    if (average.getCount() <= 1)
                    {
                        map.remove(it2[j].Key);
                    }
                }
                if (map.isEmpty())
                {
                    averageDiffs.remove(it1[i].Key);
                }
                else
                {
                    map.rehash();
                }
            }
            averageDiffs.rehash();
        }
        private double getEvaluation(FastByIDMap <PreferenceArray> testPrefs, Recommender recommender)
        {
            this.reset();
            List <Action> callables         = new List <Action>();
            AtomicInteger noEstimateCounter = new AtomicInteger();

            using (IEnumerator <KeyValuePair <long, PreferenceArray> > enumerator = testPrefs.entrySet().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Action item = null;
                    KeyValuePair <long, PreferenceArray> entry = enumerator.Current;
                    if (item == null)
                    {
                        item = delegate
                        {
                            long            userID = entry.Key;
                            PreferenceArray array  = entry.Value;
                            foreach (Preference preference in array)
                            {
                                float f = float.NaN;
                                try
                                {
                                    f = recommender.estimatePreference(userID, preference.getItemID());
                                }
                                catch (NoSuchUserException)
                                {
                                    log.info("User exists in test data but not training data: {}", new object[] { userID });
                                }
                                catch (NoSuchItemException)
                                {
                                    log.info("Item exists in test data but not training data: {}", new object[] { preference.getItemID() });
                                }
                                if (float.IsNaN(f))
                                {
                                    noEstimateCounter.incrementAndGet();
                                }
                                else
                                {
                                    f = this.capEstimatedPreference(f);
                                    this.processOneEstimate(f, preference);
                                }
                            }
                        };
                    }
                    callables.Add(item);
                }
            }
            log.info("Beginning evaluation of {} users", new object[] { callables.Count });
            RunningAverageAndStdDev timing = new FullRunningAverageAndStdDev();

            execute(callables, noEstimateCounter, timing);
            return(this.computeFinalEvaluation());
        }
Beispiel #3
0
        public static FastByIDMap <PreferenceArray> toDataMap(FastByIDMap <List <Preference> > data, bool byUser)
        {
            FastByIDMap <PreferenceArray> map = new FastByIDMap <PreferenceArray>(data.size());

            foreach (KeyValuePair <long, List <Preference> > pair in data.entrySet())
            {
                List <Preference> prefs = pair.Value;
                map.put(pair.Key, byUser ? ((PreferenceArray) new GenericUserPreferenceArray(prefs)) : ((PreferenceArray) new GenericItemPreferenceArray(prefs)));
            }
            return(map);
        }
Beispiel #4
0
 public void updateItemPref(long itemID, float prefDelta)
 {
     if (stdDevWeighted)
     {
         throw new Exception("Can't update only when stdDevWeighted is set");
     }
     try
     {
         buildAverageDiffsLock.EnterReadLock();
         foreach (var entry in averageDiffs.entrySet())
         {
             bool matchesItemID1 = itemID == entry.Key;
             foreach (var entry2 in entry.Value.entrySet())
             {
                 RunningAverage average = entry2.Value;
                 if (matchesItemID1)
                 {
                     average.changeDatum(-prefDelta);
                 }
                 else if (itemID == entry2.Key)
                 {
                     average.changeDatum(prefDelta);
                 }
             }
         }
         RunningAverage itemAverage = averageItemPref.get(itemID);
         if (itemAverage != null)
         {
             itemAverage.changeDatum(prefDelta);
         }
     }
     finally
     {
         buildAverageDiffsLock.ExitReadLock();
     }
 }
        public static FastByIDMap <FastIDSet> toDataMap(FastByIDMap <PreferenceArray> data)
        {
            FastByIDMap <FastIDSet> map = new FastByIDMap <FastIDSet>(data.size());

            foreach (KeyValuePair <long, PreferenceArray> pair in data.entrySet())
            {
                PreferenceArray array = pair.Value;
                int             size  = array.length();
                FastIDSet       set   = new FastIDSet(size);
                for (int i = 0; i < size; i++)
                {
                    set.add(array.getItemID(i));
                }
                map.put(pair.Key, set);
            }
            return(map);
        }