Package org.apache.mahout.cf.taste.impl.common

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


    if (getNumPreferences(userID) == 0) {
      return Collections.emptyList();
    }

    FastIDSet possibleItemIDs = getAllOtherItems(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


    DataModel model = getDataModel();
    TopItems.Estimator<Long> estimator = new RecommendedBecauseEstimator(userID, itemID, similarity);

    PreferenceArray prefs = model.getPreferencesFromUser(userID);
    int size = prefs.length();
    FastIDSet allUserItems = new FastIDSet(size);
    for (int i = 0; i < size; i++) {
      allUserItems.add(prefs.getItemID(i));
    }
    allUserItems.remove(itemID);

    return TopItems.getTopItems(howMany, allUserItems.iterator(), null, estimator);
  }
View Full Code Here

 
  private List<RecommendedItem> doMostSimilarItems(long[] itemIDs,
                                                   int howMany,
                                                   TopItems.Estimator<Long> estimator) throws TasteException {
    DataModel model = getDataModel();
    FastIDSet possibleItemsIDs = new FastIDSet();
    for (long itemID : itemIDs) {
      PreferenceArray prefs = model.getPreferencesForItem(itemID);
      int size = prefs.length();
      for (int i = 0; i < size; i++) {
        long userID = prefs.get(i).getUserID();
        possibleItemsIDs.addAll(model.getItemIDsFromUser(userID));
      }
    }
    possibleItemsIDs.removeAll(itemIDs);
    return TopItems.getTopItems(howMany, possibleItemsIDs.iterator(), null, estimator);
  }
View Full Code Here

  private PreferenceArray tempPrefs;
  private final FastIDSet prefItemIDs;
 
  public PlusAnonymousUserDataModel(DataModel delegate) {
    this.delegate = delegate;
    this.prefItemIDs = new FastIDSet();
  }
View Full Code Here

    }

    if (tokens.length == 3 && preferenceValueString.length() == 0) {
      // Then line is of form "userID,itemID,", meaning remove

      FastIDSet itemIDs = data.get(userID);
      if (itemIDs != null) {
        itemIDs.remove(itemID);
      }

      removeTimestamp(userID, itemID, timestamps);

    } else {

      FastIDSet itemIDs = data.get(userID);
      if (itemIDs == null) {
        itemIDs = new FastIDSet(2);
        data.put(userID, itemIDs);
      }
      itemIDs.add(itemID);

      addTimestamp(userID, itemID, timestampString, timestamps);

    }
  }
View Full Code Here

  }
 
  @Override
  public double userSimilarity(long userID1, long userID2) throws TasteException {
   
    FastIDSet prefs1 = dataModel.getItemIDsFromUser(userID1);
    FastIDSet prefs2 = dataModel.getItemIDsFromUser(userID2);
   
    int prefs1Size = prefs1.size();
    int prefs2Size = prefs2.size();
    int intersectionSize = prefs1Size < prefs2Size ? prefs2.intersectionSize(prefs1) : prefs1
        .intersectionSize(prefs2);
    if (intersectionSize == 0) {
      return Double.NaN;
    }
    int numItems = dataModel.getNumItems();
View Full Code Here

  }
 
  @Override
  public double userSimilarity(long userID1, long userID2) throws TasteException {
   
    FastIDSet xPrefs = dataModel.getItemIDsFromUser(userID1);
    FastIDSet yPrefs = dataModel.getItemIDsFromUser(userID2);
   
    if (xPrefs.isEmpty() && yPrefs.isEmpty()) {
      return Double.NaN;
    }
    if (xPrefs.isEmpty() || yPrefs.isEmpty()) {
      return 0.0;
    }
   
    int intersectionSize = xPrefs.intersectionSize(yPrefs);
    if (intersectionSize == 0) {
      return Double.NaN;
    }
   
    int unionSize = xPrefs.size() + yPrefs.size() - intersectionSize;
   
    return (double) intersectionSize / (double) unionSize;
  }
View Full Code Here

      if (itemFilePathString == null) {
        itemsToRecommendFor = null;
      } else {
        Path unqualifiedItemsFilePath = new Path(itemFilePathString);
        FileSystem fs = FileSystem.get(unqualifiedItemsFilePath.toUri(), jobConf);
        itemsToRecommendFor = new FastIDSet();
        Path itemsFilePath = unqualifiedItemsFilePath.makeQualified(fs);
        in = fs.open(itemsFilePath);
        for (String line : new FileLineIterable(in)) {
          itemsToRecommendFor.add(Long.parseLong(line));
        }
View Full Code Here

*/
public final class PreferredItemsNeighborhoodCandidateItemsStrategy implements CandidateItemsStrategy {

  @Override
  public FastIDSet getCandidateItems(long userID, DataModel dataModel) throws TasteException {
    FastIDSet possibleItemsIDs = new FastIDSet();
    FastIDSet itemIDs = dataModel.getItemIDsFromUser(userID);
    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

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

TOP

Related Classes of org.apache.mahout.cf.taste.impl.common.FastIDSet

Copyright © 2018 www.massapicom. 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.