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

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


      if (clusteringByThreshold && (top.getSimilarity() < clusteringThreshold)) {
        done = true;
        break;
      }
     
      FastIDSet cluster1 = top.getCluster1();
      FastIDSet cluster2 = top.getCluster2();
     
      // Pull out current two clusters from clusters
      Iterator<FastIDSet> clusterIterator = clusters.iterator();
      boolean removed1 = false;
      boolean removed2 = false;
      while (clusterIterator.hasNext() && !(removed1 && removed2)) {
        FastIDSet current = clusterIterator.next();
        // Yes, use == here
        if (!removed1 && (cluster1 == current)) {
          clusterIterator.remove();
          removed1 = true;
        } else if (!removed2 && (cluster2 == current)) {
          clusterIterator.remove();
          removed2 = true;
        }
      }
     
      // The only catch is if a cluster showed it twice in the list of best cluster pairs;
      // have to remove the others. Pull out anything referencing these clusters from queue
      for (Iterator<ClusterClusterPair> queueIterator = queue.iterator(); queueIterator.hasNext();) {
        ClusterClusterPair pair = queueIterator.next();
        FastIDSet pair1 = pair.getCluster1();
        FastIDSet pair2 = pair.getCluster2();
        if ((pair1 == cluster1) || (pair1 == cluster2) || (pair2 == cluster1) || (pair2 == cluster2)) {
          queueIterator.remove();
        }
      }
     
      // Make new merged cluster
      FastIDSet merged = new FastIDSet(cluster1.size() + cluster2.size());
      merged.addAll(cluster1);
      merged.addAll(cluster2);
     
      // Compare against other clusters; update queue if needed
      // That new pair we're just adding might be pretty close to something else, so
      // catch that case here and put it back into our queue
      for (FastIDSet cluster : clusters) {
View Full Code Here


  protected float doEstimatePreference(long theUserID, long itemID) throws TasteException {
   
    DataModel dataModel = getDataModel();
    PreferenceArray prefs = dataModel.getPreferencesFromUser(theUserID);
    int size = prefs.length();
    FastIDSet possibleItemIDs = new FastIDSet(size);
    for (int i = 0; i < size; i++) {
      possibleItemIDs.add(prefs.getItemID(i));
    }
    possibleItemIDs.remove(itemID);
   
    List<RecommendedItem> mostSimilar = mostSimilarItems(itemID, possibleItemIDs.iterator(),
      neighborhoodSize, null);
    long[] theNeighborhood = new long[mostSimilar.size()];
    int nOffset = 0;
    for (RecommendedItem rec : mostSimilar) {
      theNeighborhood[nOffset++] = rec.getItemID();
View Full Code Here

    int i = 0;
    for (FastIDSet cluster1 : clusters) {
      i++;
      ListIterator<FastIDSet> it2 = clusters.listIterator(i);
      while (it2.hasNext()) {
        FastIDSet cluster2 = it2.next();
        double similarity = clusterSimilarity.getSimilarity(cluster1, cluster2);
        if (!Double.isNaN(similarity) && (!full || (similarity > queue.getLast().getSimilarity()))) {
          ListIterator<ClusterClusterPair> queueIterator = queue.listIterator(queue.size());
          while (queueIterator.hasPrevious()) {
            if (similarity <= queueIterator.previous().getSimilarity()) {
View Full Code Here

  }
 
  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

    this.compactAverages = compactAverages;
    this.maxEntries = maxEntries;
    this.averageDiffs = new FastByIDMap<FastByIDMap<RunningAverage>>();
    this.averageItemPref = new FastByIDMap<RunningAverage>();
    this.buildAverageDiffsLock = new ReentrantReadWriteLock();
    this.allRecommendableItemIDs = new FastIDSet(dataModel.getNumItems());
    this.refreshHelper = new RefreshHelper(new Callable<Object>() {
      @Override
      public Object call() throws TasteException {
        buildAverageDiffs();
        return null;
View Full Code Here

    }
  }
 
  @Override
  public FastIDSet getRecommendableItemIDs(long userID) throws TasteException {
    FastIDSet result;
    try {
      buildAverageDiffsLock.readLock().lock();
      result = allRecommendableItemIDs.clone();
    } finally {
      buildAverageDiffsLock.readLock().unlock();
    }
    Iterator<Long> it = result.iterator();
    while (it.hasNext()) {
      if (dataModel.getPreferenceValue(userID, it.next()) != null) {
        it.remove();
      }
    }
View Full Code Here

    }
    averageDiffs.rehash();
  }
 
  private void updateAllRecommendableItems() throws TasteException {
    FastIDSet ids = new FastIDSet(dataModel.getNumItems());
    for (Map.Entry<Long,FastByIDMap<RunningAverage>> entry : averageDiffs.entrySet()) {
      ids.add(entry.getKey());
      LongPrimitiveIterator it = entry.getValue().keySetIterator();
      while (it.hasNext()) {
        ids.add(it.next());
      }
    }
    allRecommendableItemIDs.clear();
    allRecommendableItemIDs.addAll(ids);
    allRecommendableItemIDs.rehash();
View Full Code Here

      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(userID);
   
    List<RecommendedItem> topItems = TopItems.getTopItems(howMany, possibleItemIDs.iterator(), rescorer,
      estimator);
   
    log.debug("Recommendations are: {}", topItems);
    return topItems;
  }
View Full Code Here

   
    if (theNeighborhood.length == 0) {
      return Collections.emptyList();
    }
   
    FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID);
   
    TopItems.Estimator<Long> estimator = new Estimator(userID, theNeighborhood);
   
    List<RecommendedItem> topItems = TopItems
        .getTopItems(howMany, allItemIDs.iterator(), rescorer, estimator);
   
    log.debug("Recommendations are: {}", topItems);
    return topItems;
  }
View Full Code Here

    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

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.