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


Java LongPrimitiveIterator类代码示例

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


LongPrimitiveIterator类属于org.apache.mahout.cf.taste.impl.common包,在下文中一共展示了LongPrimitiveIterator类的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: getItemIDs

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入依赖的package包/类
@Override
public LongPrimitiveIterator getItemIDs() throws TasteException {
    FastIDSet itemIDs = new FastIDSet();
    try {
        Query.Builder query = Query.newBuilder();
        query.setLimit(Integer.MAX_VALUE);
        query.addKindBuilder().setName(DEFAULT_IMPRESSIONS_ITEMS_KIND_NAME);
        List<Key> results = runProjectionQuery(query.build(), "getItemIDs()");
        for (Key key : results) {
            itemIDs.add(key.getPathElement(0).getId());
        }
    } catch (DatastoreException e) {
        throw new TasteException(e);
    }
    return itemIDs.iterator();
}
 
开发者ID:balarj,项目名称:rmend-be,代码行数:17,代码来源:GoogleDatastoreDataModel.java

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

示例5: displayRecommendation

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入依赖的package包/类
public static void displayRecommendation(
		List<RecommendedItem> recommendations, DataModel dataModel)
		throws TasteException {

	for (LongPrimitiveIterator users = dataModel.getUserIDs(); users
			.hasNext();) {
		long userId = users.nextLong();
		// List<RecommendedItem> recommendations =
		// recommender.recommend(userId, 5);

		for (RecommendedItem recommendation : recommendations) {
			System.out.println(userId + "," + recommendation.getItemID()
					+ "," + recommendation.getValue());
		}
	}
}
 
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:17,代码来源:EEGVideoRecommender.java

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

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

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

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

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

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

示例12: getUserIDs

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入依赖的package包/类
@ShortCacheable
@Override
public LongPrimitiveIterator getUserIDs(int tenantId, Date cutoffDate, int actionTypeId) {
    Object[] args = new Object[]{tenantId, cutoffDate, actionTypeId};
    int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER};
    return new LongResultSetIteratorMysql(getDataSource(), getUserIDsQuery, args, argTypes);
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:8,代码来源:MahoutDataModelMappingDAOMysqlImpl.java

示例13: getItemIDs

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator; //导入依赖的package包/类
@ShortCacheable
@Override
public LongPrimitiveIterator getItemIDs(int tenantId, Date cutoffDate, int actionTypeId) {
    Object[] args = new Object[]{tenantId, cutoffDate, actionTypeId};
    int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER};

    return new LongResultSetIteratorMysql(getDataSource(), getItemIDsQuery, args, argTypes);
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:9,代码来源:MahoutDataModelMappingDAOMysqlImpl.java

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

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


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