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


C# Features.setFeatureColumnInU方法代码示例

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


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

示例1: Factorize

  public override Factorization Factorize() {
    log.Info("starting to compute the factorization...");
    Features features = new Features(this);

    /// feature maps necessary for solving for implicit feedback 
    IDictionary<int, double[] > userY = null;
    IDictionary<int, double[] > itemY = null;

    if (usesImplicitFeedback) {
      userY = userFeaturesMapping(dataModel.GetUserIDs(), dataModel.GetNumUsers(), features.getU());
      itemY = itemFeaturesMapping(dataModel.GetItemIDs(), dataModel.GetNumItems(), features.getM());
    }

    IList<Task> tasks;

    for (int iteration = 0; iteration < numIterations; iteration++) {
      log.Info("iteration {0}", iteration);

      /// fix M - compute U 
      tasks = new List<Task>();
      var userIDsIterator = dataModel.GetUserIDs();
      try {

        ImplicitFeedbackAlternatingLeastSquaresSolver implicitFeedbackSolver = usesImplicitFeedback
            ? new ImplicitFeedbackAlternatingLeastSquaresSolver(numFeatures, lambda, alpha, itemY) : null;

        while (userIDsIterator.MoveNext()) {
          long userID = userIDsIterator.Current;
          var itemIDsFromUser = dataModel.GetItemIDsFromUser(userID).GetEnumerator();
          IPreferenceArray userPrefs = dataModel.GetPreferencesFromUser(userID);
          
			tasks.Add(  Task.Factory.StartNew( () => {
				  List<double[]> featureVectors = new List<double[]>();
				  while (itemIDsFromUser.MoveNext()) {
					long itemID = itemIDsFromUser.Current;
					featureVectors.Add(features.getItemFeatureColumn(itemIndex(itemID)));
				  }

				  var userFeatures = usesImplicitFeedback
					  ? implicitFeedbackSolver.solve(sparseUserRatingVector(userPrefs))
					  : AlternatingLeastSquaresSolver.solve(featureVectors, ratingVector(userPrefs), lambda, numFeatures);

				  features.setFeatureColumnInU(userIndex(userID), userFeatures);
				}
			  ) );
        }
      } finally {
		 
       // queue.shutdown();
        try {
           Task.WaitAll(tasks.ToArray(), 1000*dataModel.GetNumUsers() );
        } catch (AggregateException e) {
          log.Warn("Error when computing user features", e);
		  throw e;
        }
      }

      /// fix U - compute M 
      //queue = createQueue();
	  tasks = new List<Task>();

      var itemIDsIterator = dataModel.GetItemIDs();
      try {

        ImplicitFeedbackAlternatingLeastSquaresSolver implicitFeedbackSolver = usesImplicitFeedback
            ? new ImplicitFeedbackAlternatingLeastSquaresSolver(numFeatures, lambda, alpha, userY) : null;

        while (itemIDsIterator.MoveNext()) {
          long itemID = itemIDsIterator.Current;
          IPreferenceArray itemPrefs = dataModel.GetPreferencesForItem(itemID);

          tasks.Add(  Task.Factory.StartNew( () => {

              var featureVectors = new List<double[]>();
              foreach (IPreference pref in itemPrefs) {
                long userID = pref.GetUserID();
                featureVectors.Add(features.getUserFeatureColumn(userIndex(userID)));
              }

              var itemFeatures = usesImplicitFeedback
                  ? implicitFeedbackSolver.solve(sparseItemRatingVector(itemPrefs))
                  : AlternatingLeastSquaresSolver.solve(featureVectors, ratingVector(itemPrefs), lambda, numFeatures);

              features.setFeatureColumnInM(itemIndex(itemID), itemFeatures);
           }) );
        }
      } finally {
        
        try {
			Task.WaitAll(tasks.ToArray(), 1000 * dataModel.GetNumItems());
          //queue.awaitTermination(dataModel.getNumItems(), TimeUnit.SECONDS);
		} catch (AggregateException e) {
          log.Warn("Error when computing item features", e);
		  throw e;
        }
      }
    }

    log.Info("finished computation of the factorization...");
    return createFactorization(features.getU(), features.getM());
//.........这里部分代码省略.........
开发者ID:yan6pz,项目名称:MovieRecommendation,代码行数:101,代码来源:ALSWRFactorizer.cs


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