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

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


        new GenericUserBasedRecommender(model, neighborhood, similarity);
    this.model = model;
    FastIDSet[] menWomen = GenderRescorer.parseMenWomen(readResourceToTempFile("gender.dat"));
    men = menWomen[0];
    women = menWomen[1];
    usersRateMoreMen = new FastIDSet(50000);
    usersRateLessMen = new FastIDSet(50000);
  }
View Full Code Here


    this.filterMen = ratesMoreMen(userID, model);
  }

  public static FastIDSet[] parseMenWomen(File genderFile)
      throws IOException {
    FastIDSet men = new FastIDSet(50000);
    FastIDSet women = new FastIDSet(50000);
    for (String line : new FileLineIterable(genderFile)) {
      int comma = line.indexOf(',');
      char gender = line.charAt(comma + 1);
      if (gender == 'U') {
        continue;
      }
      long profileID = Long.parseLong(line.substring(0, comma));
      if (gender == 'M') {
        men.add(profileID);
      } else {
        women.add(profileID);
      }
    }
    men.rehash();
    women.rehash();
    return new FastIDSet[] { men, women };
  }
View Full Code Here

      throw new IllegalArgumentException("userData is null");
    }
   
    this.preferenceFromUsers = userData;
    this.preferenceForItems = new FastByIDMap<FastIDSet>();
    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
View Full Code Here

 
  public static FastByIDMap<FastIDSet> toDataMap(FastByIDMap<PreferenceArray> data) {
    for (Map.Entry<Long,Object> entry : ((FastByIDMap<Object>) (FastByIDMap<?>) data).entrySet()) {
      PreferenceArray prefArray = (PreferenceArray) entry.getValue();
      int size = prefArray.length();
      FastIDSet itemIDs = new FastIDSet(size);
      for (int i = 0; i < size; i++) {
        itemIDs.add(prefArray.getItemID(i));
      }
      entry.setValue(itemIDs);
    }
    return (FastByIDMap<FastIDSet>) (FastByIDMap<?>) data;
  }
View Full Code Here

   * @throws NoSuchUserException
   *           if there is no such user
   */
  @Override
  public PreferenceArray getPreferencesFromUser(long userID) throws NoSuchUserException {
    FastIDSet itemIDs = preferenceFromUsers.get(userID);
    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++;
    }
View Full Code Here

    return prefArray;
  }
 
  @Override
  public FastIDSet getItemIDsFromUser(long userID) throws TasteException {
    FastIDSet itemIDs = preferenceFromUsers.get(userID);
    if (itemIDs == null) {
      throw new NoSuchUserException();
    }
    return itemIDs;
  }
View Full Code Here

    return new LongPrimitiveArrayIterator(itemIDs);
  }
 
  @Override
  public PreferenceArray getPreferencesForItem(long itemID) throws NoSuchItemException {
    FastIDSet userIDs = preferenceForItems.get(itemID);
    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++;
    }
View Full Code Here

    return prefArray;
  }
 
  @Override
  public Float getPreferenceValue(long userID, long itemID) throws NoSuchUserException {
    FastIDSet itemIDs = preferenceFromUsers.get(userID);
    if (itemIDs == null) {
      throw new NoSuchUserException();
    }
    if (itemIDs.contains(itemID)) {
      return 1.0f;
    }
    return null;
  }
View Full Code Here

  @Override
  public int getNumUsersWithPreferenceFor(long... itemIDs) throws NoSuchItemException {
    if (itemIDs.length == 0) {
      return 0;
    }
    FastIDSet userIDs = preferenceForItems.get(itemIDs[0]);
    if (userIDs == null) {
      throw new NoSuchItemException();
    }
    FastIDSet intersection = new FastIDSet(userIDs.size());
    intersection.addAll(userIDs);
    int i = 1;
    while (!intersection.isEmpty() && (i < itemIDs.length)) {
      userIDs = preferenceForItems.get(itemIDs[i]);
      if (userIDs == null) {
        throw new NoSuchItemException();
      }
      intersection.retainAll(userIDs);
      i++;
    }
    return intersection.size();
  }
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

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.