Ejemplo n.º 1
0
		public override double GetEvaluation(IDictionary<User, ICollection<Preference>> testUserPrefs,
		                     Recommender recommender)
		{
			RunningAverage average = new FullRunningAverage();
			foreach (KeyValuePair<User, ICollection<Preference>> entry in testUserPrefs) 
			{
				foreach (Preference realPref in entry.Value) 
				{
					User testUser = entry.Key;
					try 
					{
						double estimatedPreference =
							recommender.EstimatePreference(testUser.ID, realPref.Item.ID);
						if (!double.IsNaN(estimatedPreference)) 
						{
							double diff = realPref.Value - estimatedPreference;
							average.AddDatum(diff * diff);
						}
					} 
                    catch (NoSuchElementException nsee) 
                    {
						// 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("Element exists in test data but not training data: " + testUser.ID, nsee);
					}
				}
			}
			return Math.Sqrt(average.Average);
		}
Ejemplo n.º 2
0
        public override double GetEvaluation(IDictionary <User, ICollection <Preference> > testUserPrefs,
                                             Recommender recommender)
        {
            RunningAverage average = new FullRunningAverage();

            foreach (KeyValuePair <User, ICollection <Preference> > entry in testUserPrefs)
            {
                foreach (Preference realPref in entry.Value)
                {
                    User testUser = entry.Key;
                    try
                    {
                        double estimatedPreference =
                            recommender.EstimatePreference(testUser.ID, realPref.Item.ID);
                        if (!double.IsNaN(estimatedPreference))
                        {
                            double diff = realPref.Value - estimatedPreference;
                            average.AddDatum(diff * diff);
                        }
                    }
                    catch (NoSuchElementException nsee)
                    {
                        // 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("Element exists in test data but not training data: " + testUser.ID, nsee);
                    }
                }
            }
            return(Math.Sqrt(average.Average));
        }
Ejemplo n.º 3
0
            public Double GetValue(Pair <object, object> key)
            {
                Object userID = key.First;
                Object itemID = key.Second;

                if (log.IsDebugEnabled)
                {
                    log.Debug("Retrieving estimated preference for user ID '" + userID + "\' and item ID \'" +
                              itemID.ToString() + '\'');
                }
                return(recommender.EstimatePreference(userID, itemID));
            }
Ejemplo n.º 4
0
        public void TestEstimatePref()
        {
            Recommender recommender = buildRecommender();

            Assert.AreEqual(0.3, recommender.EstimatePreference("test1", "2"));
        }
Ejemplo n.º 5
0
        public void TestEstimatePref()
        {
            Recommender recommender = buildRecommender();

            Assert.AreEqual(0.34803885284992736, recommender.EstimatePreference("test1", "2"), EPSILON);
        }