private double getEvaluation(FastByIDMap <IPreferenceArray> testPrefs, IRecommender recommender) { reset(); var estimateCallables = new List <Action>(); AtomicInteger noEstimateCounter = new AtomicInteger(); foreach (var entry in testPrefs.EntrySet()) { estimateCallables.Add(() => { var testUserID = entry.Key; var prefs = entry.Value; foreach (IPreference realPref in prefs) { float estimatedPreference = float.NaN; try { estimatedPreference = recommender.EstimatePreference(testUserID, realPref.GetItemID()); } catch (NoSuchUserException nsue) { // It's possible that an item exists in the test data but not training data in which case // NSEE will be thrown. Just ignore it and move on. log.Info("User exists in test data but not training data: {}", testUserID); } catch (NoSuchItemException nsie) { log.Info("Item exists in test data but not training data: {}", realPref.GetItemID()); } if (float.IsNaN(estimatedPreference)) { noEstimateCounter.incrementAndGet(); } else { estimatedPreference = capEstimatedPreference(estimatedPreference); processOneEstimate(estimatedPreference, realPref); } } }); // new PreferenceEstimateCallable(recommender, entry.Key, entry.Value, noEstimateCounter)); } log.Info("Beginning evaluation of {} users", estimateCallables.Count); IRunningAverageAndStdDev timing = new FullRunningAverageAndStdDev(); execute(estimateCallables, noEstimateCounter, timing); return(computeFinalEvaluation()); }
private double getEvaluation(FastByIDMap<IPreferenceArray> testPrefs, IRecommender recommender) { reset(); var estimateCallables = new List<Action>(); AtomicInteger noEstimateCounter = new AtomicInteger(); foreach (var entry in testPrefs.EntrySet()) { estimateCallables.Add( () => { var testUserID = entry.Key; var prefs = entry.Value; foreach (IPreference realPref in prefs) { float estimatedPreference = float.NaN; try { estimatedPreference = recommender.EstimatePreference(testUserID, realPref.GetItemID()); } catch (NoSuchUserException nsue) { // It's possible that an item exists in the test data but not training data in which case // NSEE will be thrown. Just ignore it and move on. log.Info("User exists in test data but not training data: {}", testUserID); } catch (NoSuchItemException nsie) { log.Info("Item exists in test data but not training data: {}", realPref.GetItemID()); } if (float.IsNaN(estimatedPreference)) { noEstimateCounter.incrementAndGet(); } else { estimatedPreference = capEstimatedPreference(estimatedPreference); processOneEstimate(estimatedPreference, realPref); } } }); // new PreferenceEstimateCallable(recommender, entry.Key, entry.Value, noEstimateCounter)); } log.Info("Beginning evaluation of {} users", estimateCallables.Count); IRunningAverageAndStdDev timing = new FullRunningAverageAndStdDev(); execute(estimateCallables, noEstimateCounter, timing); return computeFinalEvaluation(); }
public void testEstimatePref() { IRecommender recommender = buildRecommender(); Assert.AreEqual(0.1f, recommender.EstimatePreference(1, 2), EPSILON); }