コード例 #1
0
            public double Estimate(Item item)
            {
                Preference pref = user.GetPreferenceFor(item.ID);

                if (pref == null)
                {
                    return(Double.NaN);
                }
                double correlationValue = correlation.GetItemCorrelation(recommendedItem, item);

                return((1.0 + correlationValue) * pref.Value);
            }
コード例 #2
0
            public double Estimate(Item item)
            {
                Pair <Item, Item> pair = new Pair <Item, Item>(toItem, item);

                if (rescorer.IsFiltered(pair))
                {
                    return(Double.NaN);
                }

                double originalEstimate = correlation.GetItemCorrelation(toItem, item);

                return(rescorer.Rescore(pair, originalEstimate));
            }
コード例 #3
0
            public double Estimate(Item item)
            {
                RunningAverage average = new FullRunningAverage();

                foreach (Item toItem in toItems)
                {
                    Pair <Item, Item> pair = new Pair <Item, Item>(toItem, item);
                    if (rescorer.IsFiltered(pair))
                    {
                        continue;
                    }
                    double estimate = correlation.GetItemCorrelation(toItem, item);
                    estimate = rescorer.Rescore(pair, estimate);
                    average.AddDatum(estimate);
                }
                return(average.Average);
            }
コード例 #4
0
        /// <summary>
        /// <p>Builds a list of item-item correlations given an {@link ItemCorrelation} implementation and a
        /// <see cref="DataModel">DataModel</see>, rather than a list of {@link ItemItemCorrelation}s.</p>
        /// <p>It's valid to build a <see cref="GenericItemCorrelation"/> this way, but perhaps missing some of the point
        /// of an item-based Recommender. Item-based recommenders use the assumption that item-item correlations
        /// are relatively fixed, and might be known already independent of user preferences. Hence it is useful
        /// to inject that information, using {@link GenericItemCorrelation(java.util.Collection)}.</p>
        /// </summary>
        /// <param name="otherCorrelation">otherCorrelation other {@link ItemCorrelation} to get correlations from</param>
        /// <param name="dataModel">dataModel data Model to get {@link Item}s from</param>
        public GenericItemCorrelation(ItemCorrelation otherCorrelation, DataModel dataModel)
        {
            List <Item> items = EnumeratorUtils.EnumerableToList <Item>(dataModel.GetItems());
            int         size  = items.Count;

            for (int i = 0; i < size; i++)
            {
                Item item1 = items[i];
                for (int j = i + 1; j < size; j++)
                {
                    Item   item2                  = items[j];
                    double correlation            = otherCorrelation.GetItemCorrelation(item1, item2);
                    Dictionary <Item, Double> map = null;
                    if (!correlationMaps.TryGetValue(item1, out map))
                    {
                        map = new Dictionary <Item, Double>(1009);
                        correlationMaps.Add(item1, map);
                    }
                    map.Add(item2, correlation);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// <p>Builds a list of item-item correlations given an {@link ItemCorrelation} implementation and a
        /// <see cref="DataModel">DataModel</see>, rather than a list of {@link ItemItemCorrelation}s.</p>
        /// <p>It's valid to build a <see cref="GenericItemCorrelation"/> this way, but perhaps missing some of the point 
        /// of an item-based Recommender. Item-based recommenders use the assumption that item-item correlations
        /// are relatively fixed, and might be known already independent of user preferences. Hence it is useful
        /// to inject that information, using {@link GenericItemCorrelation(java.util.Collection)}.</p>
        /// </summary>
        /// <param name="otherCorrelation">otherCorrelation other {@link ItemCorrelation} to get correlations from</param>
        /// <param name="dataModel">dataModel data Model to get {@link Item}s from</param>
		public GenericItemCorrelation(ItemCorrelation otherCorrelation, DataModel dataModel)
		{
			List<Item> items = EnumeratorUtils.EnumerableToList<Item>(dataModel.GetItems());
			int size = items.Count;
			for (int i = 0; i < size; i++) 
            {
				Item item1 = items[i];
				for (int j = i + 1; j < size; j++) 
                {
					Item item2 = items[j];
					double correlation = otherCorrelation.GetItemCorrelation(item1, item2);
					Dictionary<Item, Double> map = null;
					if (!correlationMaps.TryGetValue(item1, out map)) 
                    {
						map = new Dictionary<Item, Double>(1009);
						correlationMaps.Add(item1, map);
					}
					map.Add(item2, correlation);
				}
			}
		}