Examples of FastIDSet


Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

    return totalSimilarity == 0.0 ? Float.NaN : (float) (preference / totalSimilarity);
  }
 
  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID) throws TasteException {
    DataModel dataModel = getDataModel();
    FastIDSet possibleItemIDs = new FastIDSet();
    for (long userID : theNeighborhood) {
      possibleItemIDs.addAll(dataModel.getItemIDsFromUser(userID));
    }
    possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserID));
    return possibleItemIDs;
  }
View Full Code Here

Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

          new Configuration());
      String usersFilePathString = jobConf.get(USERS_FILE);
      if (usersFilePathString == null) {
        usersToRecommendFor = null;
      } else {
        usersToRecommendFor = new FastIDSet();
        Path usersFilePath = new Path(usersFilePathString).makeQualified(fs);
        FSDataInputStream in = fs.open(usersFilePath);
        for (String line : new FileLineIterable(in)) {
          usersToRecommendFor.add(Long.parseLong(line));
        }
View Full Code Here

Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

  }
 
  @Override
  public FastIDSet getCluster(long userID) throws TasteException {
    checkClustersBuilt();
    FastIDSet cluster = clustersByUserID.get(userID);
    return cluster == null ? new FastIDSet() : cluster;
  }
View Full Code Here

Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

      if (numUsers > 0) {
        List<FastIDSet> newClusters = new ArrayList<FastIDSet>(numUsers);
        // Begin with a cluster for each user:
        LongPrimitiveIterator it = model.getUserIDs();
        while (it.hasNext()) {
          FastIDSet newCluster = new FastIDSet();
          newCluster.add(it.nextLong());
          newClusters.add(newCluster);
        }
        if (numUsers > 1) {
          findClusters(newClusters);
        }
View Full Code Here

Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

 
  private void findClusters(List<FastIDSet> newClusters) throws TasteException {
    if (clusteringByThreshold) {
      Pair<FastIDSet,FastIDSet> nearestPair = findNearestClusters(newClusters);
      if (nearestPair != null) {
        FastIDSet cluster1 = nearestPair.getFirst();
        FastIDSet cluster2 = nearestPair.getSecond();
        while (clusterSimilarity.getSimilarity(cluster1, cluster2) >= clusteringThreshold) {
          newClusters.remove(cluster1);
          newClusters.remove(cluster2);
          FastIDSet merged = new FastIDSet(cluster1.size() + cluster2.size());
          merged.addAll(cluster1);
          merged.addAll(cluster2);
          newClusters.add(merged);
          nearestPair = findNearestClusters(newClusters);
          if (nearestPair == null) {
            break;
          }
          cluster1 = nearestPair.getFirst();
          cluster2 = nearestPair.getSecond();
        }
      }
    } else {
      while (newClusters.size() > numClusters) {
        Pair<FastIDSet,FastIDSet> nearestPair = findNearestClusters(newClusters);
        if (nearestPair == null) {
          break;
        }
        FastIDSet cluster1 = nearestPair.getFirst();
        FastIDSet cluster2 = nearestPair.getSecond();
        newClusters.remove(cluster1);
        newClusters.remove(cluster2);
        FastIDSet merged = new FastIDSet(cluster1.size() + cluster2.size());
        merged.addAll(cluster1);
        merged.addAll(cluster2);
        newClusters.add(merged);
      }
    }
  }
View Full Code Here

Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

  private Pair<FastIDSet,FastIDSet> findNearestClusters(List<FastIDSet> clusters) throws TasteException {
    int size = clusters.size();
    Pair<FastIDSet,FastIDSet> nearestPair = null;
    double bestSimilarity = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < size; i++) {
      FastIDSet cluster1 = clusters.get(i);
      for (int j = i + 1; j < size; j++) {
        if ((samplingRate >= 1.0) || (r.nextDouble() < samplingRate)) {
          FastIDSet cluster2 = clusters.get(j);
          double similarity = clusterSimilarity.getSimilarity(cluster1, cluster2);
          if (!Double.isNaN(similarity) && (similarity > bestSimilarity)) {
            bestSimilarity = similarity;
            nearestPair = new Pair<FastIDSet,FastIDSet>(cluster1, cluster2);
          }
View Full Code Here

Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

    return recsPerUser;
  }
 
  private List<RecommendedItem> computeTopRecsForCluster(FastIDSet cluster) throws TasteException {
    DataModel dataModel = getDataModel();
    FastIDSet possibleItemIDs = new FastIDSet();
    LongPrimitiveIterator it = cluster.iterator();
    while (it.hasNext()) {
      possibleItemIDs.addAll(dataModel.getItemIDsFromUser(it.next()));
    }
   
    TopItems.Estimator<Long> estimator = new Estimator(cluster);
   
    List<RecommendedItem> topItems = TopItems.getTopItems(NUM_CLUSTER_RECS,
      possibleItemIDs.iterator(), null, estimator);
   
    log.debug("Recommendations are: {}", topItems);
    return Collections.unmodifiableList(topItems);
  }
View Full Code Here

Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

   *         possibly be recommended to the user
   * @throws TasteException
   *           if an error occurs while listing items
   */
  protected FastIDSet getAllOtherItems(long theUserID) throws TasteException {
    FastIDSet possibleItemsIDs = new FastIDSet();
    FastIDSet itemIDs = dataModel.getItemIDsFromUser(theUserID);
    LongPrimitiveIterator itemIDIterator = itemIDs.iterator();
    while (itemIDIterator.hasNext()) {
      long itemID = itemIDIterator.next();
      PreferenceArray prefs2 = dataModel.getPreferencesForItem(itemID);
      int size2 = prefs2.length();
      for (int j = 0; j < size2; j++) {
View Full Code Here

Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

      throw new IllegalArgumentException("howMany must be at least 1");
    }
   
    log.debug("Recommending items for user ID '{}'", userID);
   
    FastIDSet possibleItemIDs = diffStorage.getRecommendableItemIDs(userID);
   
    TopItems.Estimator<Long> estimator = new Estimator(userID);
   
    List<RecommendedItem> topItems = TopItems.getTopItems(howMany, possibleItemIDs.iterator(), rescorer,
      estimator);
   
    log.debug("Recommendations are: {}", topItems);
    return topItems;
  }
View Full Code Here

Examples of org.apache.mahout.cf.taste.impl.common.FastIDSet

      throw new IllegalArgumentException("howMany must be at least 1");
    }
    log.debug("Recommending items for user ID '{}'", userID);
    checkAverageDiffsBuilt();
   
    FastIDSet possibleItemIDs = getAllOtherItems(userID);
   
    TopItems.Estimator<Long> estimator = new Estimator();
   
    List<RecommendedItem> topItems = TopItems.getTopItems(howMany, possibleItemIDs.iterator(), rescorer,
      estimator);
   
    log.debug("Recommendations are: {}", topItems);
    return topItems;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.