Package org.apache.mahout.cf.taste.model

Examples of org.apache.mahout.cf.taste.model.User


  }

  @Override
  public double estimatePreference(Object userID, Object itemID) throws TasteException {
    DataModel model = getDataModel();
    User theUser = model.getUser(userID);
    Preference actualPref = theUser.getPreferenceFor(itemID);
    if (actualPref != null) {
      return actualPref.getValue();
    }
    Collection<User> theNeighborhood = neighborhood.getUserNeighborhood(userID);
    return doEstimatePreference(theUser, theNeighborhood, itemID);
View Full Code Here


  /**
   * @throws NoSuchUserException if there is no such {@link User}
   */
  @Override
  public User getUser(Object id) throws NoSuchUserException {
    User user = userMap.get(id);
    if (user == null) {
      throw new NoSuchUserException();
    }
    return user;
  }
View Full Code Here

  @Override
  public List<User> mostSimilarUsers(Object userID,
                                     int howMany,
                                     Rescorer<Pair<User, User>> rescorer) throws TasteException {
    User toUser = getDataModel().getUser(userID);
    TopItems.Estimator<User> estimator = new MostSimilarEstimator(toUser, similarity, rescorer);
    return doMostSimilarUsers(userID, howMany, estimator);
  }
View Full Code Here

  private List<User> doMostSimilarUsers(Object userID,
                                        int howMany,
                                        TopItems.Estimator<User> estimator) throws TasteException {
    DataModel model = getDataModel();
    User toUser = model.getUser(userID);
    Collection<User> allUsers = new FastSet<User>(model.getNumUsers());
    for (User user : model.getUsers()) {
      allUsers.add(user);
    }
    allUsers.remove(toUser);
View Full Code Here

  @Override
  public Collection<User> getUserNeighborhood(Object userID) throws TasteException {
    log.trace("Computing neighborhood around user ID '{}'", userID);

    DataModel dataModel = getDataModel();
    User theUser = dataModel.getUser(userID);
    UserSimilarity userSimilarityImpl = getUserSimilarity();

    TopItems.Estimator<User> estimator = new Estimator(userSimilarityImpl, theUser, minSimilarity);

    List<User> neighborhood = TopItems.getTopUsers(n, dataModel.getUsers(), null, estimator);
View Full Code Here

      throw new IllegalArgumentException("howMany must be at least 1");
    }

    log.debug("Recommending items for user ID '{}'", userID);

    User theUser = getDataModel().getUser(userID);
    Set<Item> allItems = diffStorage.getRecommendableItems(userID);

    TopItems.Estimator<Item> estimator = new Estimator(theUser);

    List<RecommendedItem> topItems = TopItems.getTopItems(howMany, allItems, rescorer, estimator);
View Full Code Here

  }

  @Override
  public double estimatePreference(Object userID, Object itemID) throws TasteException {
    DataModel model = getDataModel();
    User theUser = model.getUser(userID);
    Preference actualPref = theUser.getPreferenceFor(itemID);
    if (actualPref != null) {
      return actualPref.getValue();
    }
    return doEstimatePreference(theUser, itemID);
  }
View Full Code Here

  @Override
  public void setPreference(Object userID, Object itemID, double value) throws TasteException {
    DataModel dataModel = getDataModel();
    double prefDelta;
    try {
      User theUser = dataModel.getUser(userID);
      Preference oldPref = theUser.getPreferenceFor(itemID);
      prefDelta = oldPref == null ? value : value - oldPref.getValue();
    } catch (NoSuchUserException nsee) {
      prefDelta = value;
    }
    super.setPreference(userID, itemID, value);
View Full Code Here

  }

  @Override
  public void removePreference(Object userID, Object itemID) throws TasteException {
    DataModel dataModel = getDataModel();
    User theUser = dataModel.getUser(userID);
    Preference oldPref = theUser.getPreferenceFor(itemID);
    super.removePreference(userID, itemID);
    if (oldPref != null) {
      diffStorage.updateItemPref(itemID, oldPref.getValue(), true);
    }
  }
View Full Code Here

  @Override
  public Collection<User> getUserNeighborhood(Object userID) throws TasteException {
    log.trace("Computing neighborhood around user ID '{}'", userID);

    DataModel dataModel = getDataModel();
    User theUser = dataModel.getUser(userID);
    List<User> neighborhood = new ArrayList<User>();
    Iterator<? extends User> users = dataModel.getUsers().iterator();
    UserSimilarity userSimilarityImpl = getUserSimilarity();

    while (users.hasNext()) {
      User user = users.next();
      if (sampleForUser() && !userID.equals(user.getID())) {
        double theSimilarity = userSimilarityImpl.userSimilarity(theUser, user);
        if (!Double.isNaN(theSimilarity) && theSimilarity >= threshold) {
          neighborhood.add(user);
        }
      }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.model.User

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.