当前位置: 首页>>代码示例>>C#>>正文


C# DataModel.GetUsers方法代码示例

本文整理汇总了C#中DataModel.GetUsers方法的典型用法代码示例。如果您正苦于以下问题:C# DataModel.GetUsers方法的具体用法?C# DataModel.GetUsers怎么用?C# DataModel.GetUsers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataModel的用法示例。


在下文中一共展示了DataModel.GetUsers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenericDataModel

		/**
		 * <p>Creates a new {@link GenericDataModel} containing an immutable copy of the data from another
		 * given {@link DataModel}.</p>
		 *
		 * @param dataModel {@link DataModel} to copy
		 * @if an error occurs while retrieving the other {@link DataModel}'s users
		 */
		public GenericDataModel(DataModel dataModel)
            :this(dataModel.GetUsers())
		{
		}
开发者ID:ccollie,项目名称:taste.net,代码行数:11,代码来源:GenericDataModel.cs

示例2: Evaluate

		/**
		 * {@inheritDoc}
		 */
		public double Evaluate(RecommenderBuilder recommenderBuilder,
		                       DataModel dataModel,
		                       double trainingPercentage,
		                       double evaluationPercentage)
		{

			if (recommenderBuilder == null) 
            {
				throw new ArgumentNullException("recommenderBuilder is null");
			}
			if (dataModel == null) 
            {
				throw new ArgumentNullException("dataModel is null");
			}
			if (double.IsNaN(trainingPercentage) || trainingPercentage <= 0.0 || trainingPercentage >= 1.0) 
            {
				throw new ArgumentException("Invalid trainingPercentage: " + trainingPercentage);
			}
			if (double.IsNaN(evaluationPercentage) || evaluationPercentage <= 0.0 || evaluationPercentage > 1.0) 
            {
				throw new ArgumentException("Invalid evaluationPercentage: " + evaluationPercentage);
			}

			log.Info("Beginning evaluation using " + trainingPercentage + " of " + dataModel);

			int numUsers = dataModel.GetNumUsers();
			ICollection<User> trainingUsers = new List<User>(1 + (int) (trainingPercentage * (double) numUsers));
			IDictionary<User, ICollection<Preference>> testUserPrefs =
				new Dictionary<User, ICollection<Preference>>(1 + (int) ((1.0 - trainingPercentage) * (double) numUsers));

			foreach (User user in dataModel.GetUsers()) 
            {
				if (random.NextDouble() < evaluationPercentage) 
                {
					ICollection<Preference> trainingPrefs = new List<Preference>();
					ICollection<Preference> testPrefs = new List<Preference>();
                    Preference[] prefs = user.GetPreferencesAsArray();

					foreach (Preference pref in prefs) 
					{
						Item itemCopy = new GenericItem<String>(pref.Item.ID.ToString());
						Preference newPref = new GenericPreference(null, itemCopy, pref.Value);
						if (random.NextDouble() < trainingPercentage) 
						{
							trainingPrefs.Add(newPref);
						} else {
							testPrefs.Add(newPref);
						}
					}
					if (log.IsDebugEnabled) {
						log.Debug("Training against " + trainingPrefs.Count + " preferences");
						log.Debug("Evaluating accuracy of " + testPrefs.Count + " preferences");
					}
					if (trainingPrefs.Count > 0) 
					{
						User trainingUser = new GenericUser<String>(user.ID.ToString(), trainingPrefs);
						trainingUsers.Add(trainingUser);
						if (testPrefs.Count > 0) 
						{
							testUserPrefs.Add(trainingUser, testPrefs);
						}
					}
				}
			}

			DataModel trainingModel = new GenericDataModel(trainingUsers);
			Recommender recommender = recommenderBuilder.BuildRecommender(trainingModel);
			double result = GetEvaluation(testUserPrefs, recommender);
			log.Info("Evaluation result: " + result);
			return result;
		}
开发者ID:ccollie,项目名称:taste.net,代码行数:74,代码来源:AbstractDifferenceRecommenderEvaluator.cs

示例3: Evaluate

		public IRStatistics Evaluate(RecommenderBuilder recommenderBuilder,
		                             DataModel dataModel,
		                             int at,
		                             double relevanceThreshold,
		                             double evaluationPercentage) 
		{

			if (recommenderBuilder == null) {
				throw new ArgumentNullException("recommenderBuilder is null");
			}
			if (dataModel == null) {
				throw new ArgumentNullException("dataModel is null");
			}
			if (at < 1) {
				throw new ArgumentException("at must be at least 1");
			}
			if (double.IsNaN(evaluationPercentage) || evaluationPercentage <= 0.0 || evaluationPercentage > 1.0) 
			{
				throw new ArgumentException("Invalid evaluationPercentage: " + evaluationPercentage);
			}
			if (double.IsNaN(relevanceThreshold)) {
				throw new ArgumentException("Invalid relevanceThreshold: " + evaluationPercentage);
			}

			RunningAverage precision = new FullRunningAverage();
			RunningAverage recall = new FullRunningAverage();
			foreach (User user in dataModel.GetUsers()) 
			{
				Object id = user.ID;
				if (random.NextDouble() < evaluationPercentage) 
				{
					ICollection<Item> relevantItems = new HashedSet<Item>(/* at */);
                    Preference[] prefs = user.GetPreferencesAsArray();

					foreach (Preference pref in prefs) 
					{
						if (pref.Value >= relevanceThreshold) 
                        {
							relevantItems.Add(pref.Item);
						}
					}
					int numRelevantItems = relevantItems.Count;
					if (numRelevantItems > 0) 
                    {
						ICollection<User> trainingUsers = new List<User>(dataModel.GetNumUsers());
						foreach (User user2 in dataModel.GetUsers()) 
                        {
							if (id.Equals(user2.ID)) 
							{
								ICollection<Preference> trainingPrefs = new List<Preference>();
                                prefs = user2.GetPreferencesAsArray();
								foreach (Preference pref in prefs) 
								{
									if (!relevantItems.Contains(pref.Item)) 
									{
										trainingPrefs.Add(pref);
									}
								}
								if (trainingPrefs.Count > 0) 
								{
									User trainingUser = new GenericUser<String>(id.ToString(), trainingPrefs);
									trainingUsers.Add(trainingUser);
								}
							} 
                            else 
                            {
								trainingUsers.Add(user2);
							}

						}
						DataModel trainingModel = new GenericDataModel(trainingUsers);
						Recommender recommender = recommenderBuilder.BuildRecommender(trainingModel);

						try 
						{
							trainingModel.GetUser(id);
						} 
                        catch (NoSuchElementException) 
                        {
							continue; // Oops we excluded all prefs for the user -- just move on
						}
						
						int intersectionSize = 0;
						foreach (RecommendedItem recommendedItem in recommender.Recommend(id, at)) 
						{
							if (relevantItems.Contains(recommendedItem.Item)) 
							{
								intersectionSize++;
							}
						}
						precision.AddDatum((double) intersectionSize / (double) at);
						recall.AddDatum((double) intersectionSize / (double) numRelevantItems);					
					}
				}
			}

			return new IRStatisticsImpl(precision.Average, recall.Average);
		}
开发者ID:ccollie,项目名称:taste.net,代码行数:98,代码来源:GenericRecommenderIRStatsEvaluator.cs


注:本文中的DataModel.GetUsers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。