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


Java LongPrimitiveIterator.hasNext方法代码示例

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


在下文中一共展示了LongPrimitiveIterator.hasNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: intializeDelegate

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
private void intializeDelegate() {
    try {
    //iterate over all user ids
    LongPrimitiveIterator it = easyrecDataModelDelegate.getUserIDs();
    FastByIDMap<PreferenceArray> preferences = new FastByIDMap<PreferenceArray>(easyrecDataModelDelegate.getNumUsers());
    FastByIDMap<FastByIDMap<Long>> timestamps = new FastByIDMap<FastByIDMap<Long>>(easyrecDataModelDelegate.getNumUsers());
    while (it.hasNext()) {
        Long userId = it.next();
        //get preferences for each user
        PreferenceArray prefs = easyrecDataModelDelegate.getPreferencesFromUser(userId);
        preferences.put(userId,prefs);
        //get preference times for each user
        FastByIDMap<Long> timestampsForUser = new FastByIDMap<Long>(prefs.getIDs().length);
        for (Long itemId: prefs.getIDs()) {
            timestampsForUser.put(itemId,easyrecDataModelDelegate.getPreferenceTime(userId, itemId));
        }
        timestamps.put(userId, timestampsForUser);
    }
    //generate GenericDataModel
    setMaxPreference(easyrecDataModelDelegate.getMaxPreference());
    setMinPreference(easyrecDataModelDelegate.getMinPreference());
    this.inMemoryDelegate = new GenericDataModel(preferences,timestamps);
    } catch (TasteException e) {
        logger.warn("caught exception while reading preference data", e);
    }
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:27,代码来源:EasyrecInMemoryDataModel.java

示例3: 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

示例4: 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

示例5: writeKnownIDs

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
private static void writeKnownIDs(ObjectOutputStream out, FastByIDMap<FastIDSet> knownItemIDs) throws IOException {
  if (knownItemIDs == null) {
    out.writeInt(NULL_COUNT);
  } else {
    out.writeInt(knownItemIDs.size());
    for (FastByIDMap.MapEntry<FastIDSet> entry : knownItemIDs.entrySet()) {
      out.writeLong(entry.getKey());
      FastIDSet itemIDs = entry.getValue();
      out.writeInt(itemIDs.size());
      LongPrimitiveIterator it = itemIDs.iterator();
      while (it.hasNext()) {
        out.writeLong(it.nextLong());
      }
    }
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:17,代码来源:GenerationSerializer.java

示例6: writeClusters

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
private static void writeClusters(Collection<IDCluster> clusters, ObjectOutputStream out) throws IOException {
  if (clusters == null) {
    out.writeInt(0);
  } else {
    out.writeInt(clusters.size());
    for (IDCluster cluster : clusters) {
      FastIDSet members = cluster.getMembers();
      out.writeInt(members.size());
      LongPrimitiveIterator it = members.iterator();
      while (it.hasNext()) {
        out.writeLong(it.nextLong());
      }
      float[] centroid = cluster.getCentroid();
      out.writeInt(centroid.length);
      for (float f : centroid) {
        out.writeFloat(f);
      }
    }
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:21,代码来源:GenerationSerializer.java

示例7: 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

示例8: partialTransposeTimesSelf

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
/**
 * Like {@link MatrixUtils#transposeTimesSelf(FastByIDMap)}, but instead of computing MT * M, 
 * it computes MT * C * M, where C is a diagonal matrix of 1s and 0s. This is like pretending some
 * rows of M are 0.
 * 
 * @see MatrixUtils#transposeTimesSelf(FastByIDMap) 
 * @see #LOSS_IGNORES_UNSPECIFIED
 */
private static RealMatrix partialTransposeTimesSelf(FastByIDMap<float[]> M, 
                                                    int dimension, 
                                                    LongPrimitiveIterator keys) {
  RealMatrix result = new Array2DRowRealMatrix(dimension, dimension);
  while (keys.hasNext()) {
    long key = keys.next();
    float[] vector = M.get(key);
    for (int row = 0; row < dimension; row++) {
      float rowValue = vector[row];
      for (int col = 0; col < dimension; col++) {
        result.addToEntry(row, col, rowValue * vector[col]);
      }
    }
  }
  return result;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:25,代码来源:AlternatingLeastSquares.java

示例9: chooseAboutNFromStream

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
/**
 * @param n approximate number of items to choose
 * @param stream stream to choose from randomly
 * @param streamSize (approximate) stream size
 * @param random random number generator
 * @return up to n elements chosen uninformly at random from the stream
 */
public static long[] chooseAboutNFromStream(int n, 
                                            LongPrimitiveIterator stream,
                                            int streamSize, 
                                            RandomGenerator random) {
  LongPrimitiveIterator it;
  if (n < streamSize) {
    it = new SamplingLongPrimitiveIterator(random, stream, (double) n / streamSize);      
  } else {
    it = stream;
  }
  FastIDSet chosen = new FastIDSet(n);    
  while (it.hasNext()) {
    chosen.add(it.nextLong());
  }
  return chosen.toArray();
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:24,代码来源:RandomUtils.java

示例10: testEasyrecDataModel_getItemIDs

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
@Test
public void testEasyrecDataModel_getItemIDs() throws TasteException {
    EasyrecDataModel easyrecDataModel = new EasyrecDataModel(TENANT_ID, RATE_ACTION_TYPE_ID, HAS_RATING_VALUES, mahoutDataModelMappingDAO);
    LongPrimitiveIterator itemIds = easyrecDataModel.getItemIDs();

    String ids = "";
    while (itemIds.hasNext()) {
        ids += itemIds.next();
    }

    assertEquals("123", ids);

    //Test peek function of the iterator
    itemIds = easyrecDataModel.getItemIDs();


    ids = "";
    ids += itemIds.peek();

    while (itemIds.hasNext()) {
        ids += itemIds.peek() + "-" + itemIds.next();
        if (itemIds.hasNext()) {
            ids += "-" + itemIds.peek() + "-" + itemIds.peek() + "#";
        } else {
            ids += "#";
        }
    }
    assertEquals("11-1-2-2#2-2-3-3#3-3#", ids);
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:30,代码来源:EasyrecDataModelTest.java

示例11: testEasyrecDataModel_getUserIDs

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入方法依赖的package包/类
@Test
public void testEasyrecDataModel_getUserIDs() throws TasteException {
    EasyrecDataModel easyrecDataModel = new EasyrecDataModel(TENANT_ID, RATE_ACTION_TYPE_ID, HAS_RATING_VALUES, mahoutDataModelMappingDAO);
    LongPrimitiveIterator userIds = easyrecDataModel.getUserIDs();

    String ids = "";
    while (userIds.hasNext()) {
        ids += userIds.next();
    }

    assertEquals("12", ids);

}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:14,代码来源:EasyrecDataModelTest.java

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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