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


Java LongPrimitiveIterator.nextLong方法代码示例

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


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

示例1: buildRecommend

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
public void buildRecommend(String taskName) {
    String itemmodelsPath = RecommendConfig.class.getResource("/").getPath() + "itemmodels.csv";
    HadoopUtil.download(taskName, itemmodelsPath, true);
    try {
        DataModel dataModel = new FileDataModel(new File(itemmodelsPath));
        UserSimilarity similarity = new SpearmanCorrelationSimilarity(dataModel);
        UserNeighborhood userNeighborhood = new ThresholdUserNeighborhood(0.1, similarity, dataModel);
        LongPrimitiveIterator userIDs = dataModel.getUserIDs();
        while (userIDs.hasNext()) {
            Long userID = userIDs.nextLong();
            long[] neighborhoods = userNeighborhood.getUserNeighborhood(userID);
            for (long neighborhood : neighborhoods) {
                double userSimilarity = similarity.userSimilarity(userID, neighborhood);
                System.out.printf("(%s,%s,%f)", userID, neighborhood, userSimilarity);
                System.out.println();
            }
        }
    } catch (TasteException | IOException e) {
        log.error(e);
    }
}
 
开发者ID:babymm,项目名称:mmsns,代码行数:22,代码来源:MahoutRecommender.java

示例2: main

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
public static void main(String[] args) throws TasteException, IOException {
    String file = "other/testdata/pv.csv";
    DataModel dataModel = RecommendFactory.buildDataModelNoPref(file);
    //基于UserCF城市街区距离(曼哈顿)算法
    RecommenderBuilder rb1 = RecommenderEvaluator.userCityBlock(dataModel);
    //基于ItemCF对数自然相似度算法
    RecommenderBuilder rb2 = RecommenderEvaluator.itemCityBlock(dataModel);

    LongPrimitiveIterator iter = dataModel.getUserIDs();
    while (iter.hasNext()) {
        long uid = iter.nextLong();
        System.out.print("userCityBlock  =>");
        result(uid, rb1, dataModel);
        System.out.print("itemLoglikelihood=>");
        result(uid, rb2, dataModel);
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:18,代码来源:RecommenderResult.java

示例3: removeNotUpdated

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
private static void removeNotUpdated(LongPrimitiveIterator it,
                                     FastIDSet updated,
                                     FastIDSet recentlyActive,
                                     Lock writeLock) {
  writeLock.lock();
  try {
    while (it.hasNext()) {
      long id = it.nextLong();
      if (!updated.contains(id) && !recentlyActive.contains(id)) {
        it.remove();
      }
    }
  } finally {
    writeLock.unlock();
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:17,代码来源:GenerationLoader.java

示例4: getIDsFromKeys

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
private static FastIDSet getIDsFromKeys(FastByIDMap<float[]> map, Lock readLock, FastIDSet tagIDs) {
  readLock.lock();
  try {
    FastIDSet ids = new FastIDSet(map.size());
    LongPrimitiveIterator it = map.keySetIterator();
    while (it.hasNext()) {
      long id = it.nextLong();
      if (!tagIDs.contains(id)) {
        ids.add(id);
      }
    }
    return ids;
  } finally {
    readLock.unlock();
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:17,代码来源:ServerRecommender.java

示例5: main

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
public static void main(String[] args) throws TasteException, IOException {
    String file = "other/testdata/pv.csv";
    DataModel dataModel = RecommendFactory.buildDataModelNoPref(file);
    RecommenderBuilder rb1 = RecommenderEvaluator.userCityBlock(dataModel);
    RecommenderBuilder rb2 = RecommenderEvaluator.itemLoglikelihood(dataModel);

    LongPrimitiveIterator iter = dataModel.getUserIDs();
    while (iter.hasNext()) {
        long uid = iter.nextLong();
        System.out.print("userCityBlock    =>");
        filterOutdate(uid, rb1, dataModel);
        System.out.print("itemLoglikelihood=>");
        filterOutdate(uid, rb2, dataModel);
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:16,代码来源:RecommenderFilterOutdateResult.java

示例6: userCF

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
public static void userCF(DataModel dataModel) throws TasteException {
    UserSimilarity userSimilarity = RecommendFactory.userSimilarity(RecommendFactory.SIMILARITY.CITYBLOCK, dataModel);
    UserNeighborhood userNeighborhood = RecommendFactory.userNeighborhood(RecommendFactory.NEIGHBORHOOD.NEAREST, userSimilarity, dataModel, NEIGHBORHOOD_NUM);
    RecommenderBuilder recommenderBuilder = RecommendFactory.userRecommender(userSimilarity, userNeighborhood, true);

    RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
    RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);

    LongPrimitiveIterator iter = dataModel.getUserIDs();
    while (iter.hasNext()) {
        long uid = iter.nextLong();
        List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
        RecommendFactory.showItems(uid, list, true);
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:16,代码来源:RecommenderTest.java

示例7: itemCF

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
public static void itemCF(DataModel dataModel) throws TasteException {
    ItemSimilarity itemSimilarity = RecommendFactory.itemSimilarity(RecommendFactory.SIMILARITY.CITYBLOCK, dataModel);
    RecommenderBuilder recommenderBuilder = RecommendFactory.itemRecommender(itemSimilarity, true);
    RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
    RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
    LongPrimitiveIterator iter = dataModel.getUserIDs();
    while (iter.hasNext()) {
        long uid = iter.nextLong();
        List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
        RecommendFactory.showItems(uid, list, true);
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:13,代码来源:RecommenderTest.java

示例8: slopeOne

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
public static void slopeOne(DataModel dataModel) throws TasteException {
    RecommenderBuilder recommenderBuilder = RecommendFactory.slopeOneRecommender();

    RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
    RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);

    LongPrimitiveIterator iter = dataModel.getUserIDs();
    while (iter.hasNext()) {
        long uid = iter.nextLong();
        List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
        RecommendFactory.showItems(uid, list, true);
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:14,代码来源:RecommenderTest.java

示例9: itemKNN

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
public static void itemKNN(DataModel dataModel) throws TasteException {
    ItemSimilarity itemSimilarity = RecommendFactory.itemSimilarity(RecommendFactory.SIMILARITY.EUCLIDEAN, dataModel);
    RecommenderBuilder recommenderBuilder = RecommendFactory.itemKNNRecommender(itemSimilarity, new NonNegativeQuadraticOptimizer(), 10);

    RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
    RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);

    LongPrimitiveIterator iter = dataModel.getUserIDs();
    while (iter.hasNext()) {
        long uid = iter.nextLong();
        List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
        RecommendFactory.showItems(uid, list, true);
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:15,代码来源:RecommenderTest.java

示例10: svd

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
public static void svd(DataModel dataModel) throws TasteException {
    RecommenderBuilder recommenderBuilder = RecommendFactory.svdRecommender(new ALSWRFactorizer(dataModel, 10, 0.05, 10));

    RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
    RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);

    LongPrimitiveIterator iter = dataModel.getUserIDs();
    while (iter.hasNext()) {
        long uid = iter.nextLong();
        List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
        RecommendFactory.showItems(uid, list, true);
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:14,代码来源:RecommenderTest.java

示例11: treeCluster

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
public static void treeCluster(DataModel dataModel) throws TasteException {
    UserSimilarity userSimilarity = RecommendFactory.userSimilarity(RecommendFactory.SIMILARITY.LOGLIKELIHOOD, dataModel);
    ClusterSimilarity clusterSimilarity = RecommendFactory.clusterSimilarity(RecommendFactory.SIMILARITY.FARTHEST_NEIGHBOR_CLUSTER, userSimilarity);
    RecommenderBuilder recommenderBuilder = RecommendFactory.treeClusterRecommender(clusterSimilarity, 10);

    RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
    RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);

    LongPrimitiveIterator iter = dataModel.getUserIDs();
    while (iter.hasNext()) {
        long uid = iter.nextLong();
        List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
        RecommendFactory.showItems(uid, list, true);
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:16,代码来源:RecommenderTest.java

示例12: randomFrom

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
/**
 * @param set to choose from
 * @param random random number generator
 * @return element of the set chosen uniformly at random
 */
public static int randomFrom(FastIDSet set, RandomGenerator random) {
  int size = set.size();
  Preconditions.checkArgument(size > 0, "Empty set");
  LongPrimitiveIterator it = set.iterator();
  it.skip(random.nextInt(size));
  return (int) it.nextLong();
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:13,代码来源:RandomUtils.java

示例13: runALSSVDRecommender

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
private static void runALSSVDRecommender(DataModel dataModel)
		throws TasteException {

	System.out.println("Start of Running an ALS SVD Recommendation");
	RecommenderBuilder recommenderBuilder = EEGVideoRecommender.buildSVDRecommender();

	SVDRecommender recommender = (SVDRecommender) recommenderBuilder
			.buildRecommender(dataModel);

	RunningAverage runningAverage = new FullRunningAverage();

	LongPrimitiveIterator userIDs = dataModel.getUserIDs();

	while (userIDs.hasNext()) {
		long userID = userIDs.nextLong();

		for (Preference pref : dataModel.getPreferencesFromUser(userID)) {

			double ratingValue = pref.getValue();
			double preferenceEstimate = recommender.estimatePreference(
					userID, pref.getItemID());

			System.out.println(userID + "," + pref.getItemID() + ","
					+ ratingValue);
			double errorValue = ratingValue - preferenceEstimate;
			runningAverage.addDatum(errorValue * errorValue);
		}
	}

	double rmse = Math.sqrt(runningAverage.getAverage());
	System.out.println(rmse);

	// Recommender Evaluation -- Average Absolute Difference Evaluator
	RecommenderEvaluator absoluteDifferenceEvaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
	double score = absoluteDifferenceEvaluator.evaluate(recommenderBuilder,
			null, dataModel, 0.9, 1.0);
	System.out.println("ALS-based Recommender Average Score is: " + score);

	// Recommender Evaluation -- RMS Evaluator
	RecommenderEvaluator rmsEvaluator = new RMSRecommenderEvaluator();
	double rmsscore = rmsEvaluator.evaluate(recommenderBuilder, null,
			dataModel, 0.9, 1.0);
	System.out.println("ALS-based Recommender RMS Score is:" + rmsscore);

	// Recommender Evaluation -- IRStats Evaluator
	RecommenderIRStatsEvaluator irStatsEvaluator = new GenericRecommenderIRStatsEvaluator();
	IRStatistics stats = irStatsEvaluator.evaluate(recommenderBuilder,
			null, dataModel, null, 2,
			GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);

	System.out.println("Precision Valus is : " + stats.getPrecision());
	System.out.println("Recall Value is : " + stats.getRecall());

	System.out.println("End of Running an ALS SVD Recommendation");
}
 
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:56,代码来源:EEGVideoEvaluator.java

示例14: recommendedBecause

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
/**
 * <p>Lists the items that were most influential in recommending a given item to a given user. Exactly how this
 * is determined is left to the implementation, but, generally this will return items that the user prefers
 * and that are similar to the given item.</p>
 *
 * <p>These values by which the results are ordered are opaque values and have no interpretation
 * other than that larger means stronger.</p>
 *
 * @param userID ID of user who was recommended the item
 * @param itemID ID of item that was recommended
 * @param howMany maximum number of items to return
 * @return {@link List} of {@link RecommendedItem}, ordered from most influential in recommended the given
 *  item to least
 * @throws NoSuchUserException if the user is not known in the model
 * @throws NoSuchItemException if the item is not known in the model
 * @throws NotReadyException if the recommender has no model available yet
 */
@Override
public List<RecommendedItem> recommendedBecause(long userID, long itemID, int howMany)
    throws NoSuchUserException, NoSuchItemException, NotReadyException {

  Preconditions.checkArgument(howMany > 0, "howMany must be positive");

  Generation generation = getCurrentGeneration();
  FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
  if (knownItemIDs == null) {
    throw new UnsupportedOperationException("No known item IDs available");
  }

  Lock knownItemLock = generation.getKnownItemLock().readLock();
  FastIDSet userKnownItemIDs;
  knownItemLock.lock();
  try {
    userKnownItemIDs = knownItemIDs.get(userID);
  } finally {
    knownItemLock.unlock();
  }
  if (userKnownItemIDs == null) {
    throw new NoSuchUserException(userID);
  }

  FastByIDMap<float[]> Y = generation.getY();

  Lock yLock = generation.getYLock().readLock();
  yLock.lock();
  try {

    float[] features = Y.get(itemID);
    if (features == null) {
      throw new NoSuchItemException(itemID);
    }
    FastByIDMap<float[]> toFeatures;
    synchronized (userKnownItemIDs) {
      toFeatures = new FastByIDMap<float[]>(userKnownItemIDs.size());
      LongPrimitiveIterator it = userKnownItemIDs.iterator();
      while (it.hasNext()) {
        long fromItemID = it.nextLong();
        float[] fromFeatures = Y.get(fromItemID);
        toFeatures.put(fromItemID, fromFeatures);
      }
    }

    return TopN.selectTopN(new RecommendedBecauseIterator(toFeatures.entrySet().iterator(), 
                                                          generation.getUserTagIDs(), 
                                                          features), 
                           howMany);
  } finally {
    yLock.unlock();
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:71,代码来源:ServerRecommender.java


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