Examples of FastIDSet


Examples of net.myrrix.common.collection.FastIDSet

  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    try {
      FastByIDMap<FastIDSet> newKnownItemIDs = readKnownIDs(in);
      FastByIDMap<float[]> newX = readMatrix(in);
      FastByIDMap<float[]> newY = readMatrix(in);
      FastIDSet itemTagIDs = readIDSet(in);
      FastIDSet userTagIDs = readIDSet(in);
      List<IDCluster> userClusters = readClusters(in);
      List<IDCluster> itemClusters = readClusters(in);
      generation = new Generation(newKnownItemIDs,
                                  newX,
                                  newY,
View Full Code Here

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

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

    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

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

      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

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

 
  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

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

   * @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

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

    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

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

    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

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

    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

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

  @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
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.