本文整理汇总了C#中Features.getItemFeatureColumn方法的典型用法代码示例。如果您正苦于以下问题:C# Features.getItemFeatureColumn方法的具体用法?C# Features.getItemFeatureColumn怎么用?C# Features.getItemFeatureColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Features
的用法示例。
在下文中一共展示了Features.getItemFeatureColumn方法的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());
//.........这里部分代码省略.........