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

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


    FastByIDMap<PreferenceArray> trainingUsers = new FastByIDMap<PreferenceArray>(
        1 + (int) (evaluationPercentage * numUsers));
    FastByIDMap<PreferenceArray> testUserPrefs = new FastByIDMap<PreferenceArray>(
        1 + (int) (evaluationPercentage * numUsers));
   
    LongPrimitiveIterator it = dataModel.getUserIDs();
    while (it.hasNext()) {
      long userID = it.nextLong();
      if (random.nextDouble() < evaluationPercentage) {
        processOneUser(trainingPercentage, trainingUsers, testUserPrefs, userID, dataModel);
      }
    }
   
View Full Code Here


 
  public static void runLoad(Recommender recommender) throws TasteException {
    DataModel dataModel = recommender.getDataModel();
    int numUsers = dataModel.getNumUsers();
    double sampleRate = 1000.0 / numUsers;
    LongPrimitiveIterator userSampler = SamplingLongPrimitiveIterator.maybeWrapIterator(dataModel
        .getUserIDs(), sampleRate);
    recommender.recommend(userSampler.next(), 10); // Warm up
    Collection<Callable<Void>> callables = new ArrayList<Callable<Void>>();
    while (userSampler.hasNext()) {
      callables.add(new LoadCallable(recommender, userSampler.next()));
    }
    AbstractDifferenceRecommenderEvaluator.execute(callables);
  }
View Full Code Here

    FastIDSet itemIDSet = new FastIDSet();
    for (Map.Entry<Long,FastIDSet> entry : preferenceFromUsers.entrySet()) {
      long userID = entry.getKey();
      FastIDSet itemIDs = entry.getValue();
      itemIDSet.addAll(itemIDs);
      LongPrimitiveIterator it = itemIDs.iterator();
      while (it.hasNext()) {
        long itemID = it.next();
        FastIDSet userIDs = preferenceForItems.get(itemID);
        if (userIDs == null) {
          userIDs = new FastIDSet(2);
          preferenceForItems.put(itemID, userIDs);
        }
        userIDs.add(userID);
      }
    }
   
    this.itemIDs = itemIDSet.toArray();
    itemIDSet = null; // Might help GC -- this is big
    Arrays.sort(itemIDs);
   
    this.userIDs = new long[userData.size()];
    int i = 0;
    LongPrimitiveIterator it = userData.keySetIterator();
    while (it.hasNext()) {
      userIDs[i++] = it.next();
    }
    Arrays.sort(userIDs);
   
  }
View Full Code Here

    this(toDataMap(dataModel));
  }
 
  private static FastByIDMap<FastIDSet> toDataMap(DataModel dataModel) throws TasteException {
    FastByIDMap<FastIDSet> data = new FastByIDMap<FastIDSet>(dataModel.getNumUsers());
    LongPrimitiveIterator it = dataModel.getUserIDs();
    while (it.hasNext()) {
      long userID = it.nextLong();
      data.put(userID, dataModel.getItemIDsFromUser(userID));
    }
    return data;
  }
View Full Code Here

    if (itemIDs == null) {
      throw new NoSuchUserException();
    }
    PreferenceArray prefArray = new BooleanUserPreferenceArray(itemIDs.size());
    int i = 0;
    LongPrimitiveIterator it = itemIDs.iterator();
    while (it.hasNext()) {
      prefArray.setUserID(i, userID);
      prefArray.setItemID(i, it.next());
      i++;
    }
    return prefArray;
  }
View Full Code Here

    if (userIDs == null) {
      throw new NoSuchItemException();
    }
    PreferenceArray prefArray = new BooleanItemPreferenceArray(userIDs.size());
    int i = 0;
    LongPrimitiveIterator it = userIDs.iterator();
    while (it.hasNext()) {
      prefArray.setUserID(i, it.next());
      prefArray.setItemID(i, itemID);
      i++;
    }
    return prefArray;
  }
View Full Code Here

  }
 
  private synchronized void recompute() throws TasteException {
    Counters itemPreferenceCounts = new Counters();
    int numUsers = 0;
    LongPrimitiveIterator it = dataModel.getUserIDs();
    while (it.hasNext()) {
      PreferenceArray prefs = dataModel.getPreferencesFromUser(it.nextLong());
      int size = prefs.length();
      for (int i = 0; i < size; i++) {
        itemPreferenceCounts.increment(prefs.getItemID(i));
      }
      numUsers++;
View Full Code Here

    DataModel dataModel = getDataModel();
    UserSimilarity userSimilarityImpl = getUserSimilarity();
   
    TopItems.Estimator<Long> estimator = new Estimator(userSimilarityImpl, userID, minSimilarity);
   
    LongPrimitiveIterator userIDs = SamplingLongPrimitiveIterator.maybeWrapIterator(dataModel.getUserIDs(),
      getSamplingRate());
   
    return TopItems.getTopUsers(n, userIDs, null, estimator);
  }
View Full Code Here

  @Override
  public long[] getUserNeighborhood(long userID) throws TasteException {
   
    DataModel dataModel = getDataModel();
    FastIDSet neighborhood = new FastIDSet();
    LongPrimitiveIterator usersIterable = SamplingLongPrimitiveIterator.maybeWrapIterator(dataModel
        .getUserIDs(), getSamplingRate());
    UserSimilarity userSimilarityImpl = getUserSimilarity();
   
    while (usersIterable.hasNext()) {
      long otherUserID = usersIterable.next();
      if (userID != otherUserID) {
        double theSimilarity = userSimilarityImpl.userSimilarity(userID, otherUserID);
        if (!Double.isNaN(theSimilarity) && (theSimilarity >= threshold)) {
          neighborhood.add(otherUserID);
        }
View Full Code Here

   
    int numItems = dataModel.getNumItems();
    RunningAverage precision = new FullRunningAverage();
    RunningAverage recall = new FullRunningAverage();
    RunningAverage fallOut = new FullRunningAverage();
    LongPrimitiveIterator it = dataModel.getUserIDs();
    while (it.hasNext()) {
      long userID = it.nextLong();
      if (random.nextDouble() < evaluationPercentage) {
        long start = System.currentTimeMillis();
        FastIDSet relevantItemIDs = new FastIDSet(at);
        PreferenceArray prefs = dataModel.getPreferencesFromUser(userID);
        int size = prefs.length();
        if (size < 2 * at) {
          // Really not enough prefs to meaningfully evaluate this user
          continue;
        }
       
        // List some most-preferred items that would count as (most) "relevant" results
        double theRelevanceThreshold = Double.isNaN(relevanceThreshold) ?
            computeThreshold(prefs) : relevanceThreshold;
        prefs.sortByValueReversed();
        for (int i = 0; (i < size) && (relevantItemIDs.size() < at); i++) {
          if (prefs.getValue(i) >= theRelevanceThreshold) {
            relevantItemIDs.add(prefs.getItemID(i));
          }
        }
        int numRelevantItems = relevantItemIDs.size();
        if (numRelevantItems > 0) {
          FastByIDMap<PreferenceArray> trainingUsers = new FastByIDMap<PreferenceArray>(dataModel
              .getNumUsers());
          LongPrimitiveIterator it2 = dataModel.getUserIDs();
          while (it2.hasNext()) {
            processOtherUser(userID, relevantItemIDs, trainingUsers, it2
                .nextLong(), dataModel);
          }
         
          DataModel trainingModel = dataModelBuilder == null ? new GenericDataModel(trainingUsers)
              : dataModelBuilder.buildDataModel(trainingUsers);
View Full Code Here

TOP

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

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.