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

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


    User theUser = getDataModel().getUser(userID);
    List<RecommendedItem> rescored = new ArrayList<RecommendedItem>(recommended.size());
    // Only add items the user doesn't already have a preference for.
    // And that the rescorer doesn't "reject".
    for (RecommendedItem recommendedItem : recommended) {
      Item item = recommendedItem.getItem();
      if (rescorer != null && rescorer.isFiltered(item)) {
        continue;
      }
      if (theUser.getPreferenceFor(item.getID()) == null &&
          (rescorer == null || !Double.isNaN(rescorer.rescore(item, recommendedItem.getValue())))) {
        rescored.add(recommendedItem);
      }
    }
    Collections.sort(rescored, new ByRescoreComparator(rescorer));
View Full Code Here


      return Double.NaN;
    }

    Preference xPref = xPrefs[0];
    Preference yPref = yPrefs[0];
    Item xIndex = xPref.getItem();
    Item yIndex = yPref.getItem();
    int xPrefIndex = 1;
    int yPrefIndex = 1;

    double sumX = 0.0;
    double sumX2 = 0.0;
View Full Code Here

    initSimilarityMaps(keptSimilarities);
  }

  private void initSimilarityMaps(Iterable<ItemItemSimilarity> similarities) {
    for (ItemItemSimilarity iic : similarities) {
      Item similarityItem1 = iic.getItem1();
      Item similarityItem2 = iic.getItem2();
      int compare = similarityItem1.compareTo(similarityItem2);
      if (compare != 0) {
        // Order them -- first key should be the "smaller" one
        Item item1;
        Item item2;
        if (compare < 0) {
          item1 = similarityItem1;
          item2 = similarityItem2;
        } else {
          item1 = similarityItem2;
View Full Code Here

  public double itemSimilarity(Item item1, Item item2) {
    int compare = item1.compareTo(item2);
    if (compare == 0) {
      return 1.0;
    }
    Item first;
    Item second;
    if (compare < 0) {
      first = item1;
      second = item2;
    } else {
      first = item2;
View Full Code Here

    @Override
    public ItemItemSimilarity next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      Item item2 = items.get(j);
      double similarity;
      try {
        similarity = otherSimilarity.itemSimilarity(item1, item2);
      } catch (TasteException te) {
        // ugly:
View Full Code Here

      return 0.0;
    }

    Preference xPref = xPrefs[0];
    Preference yPref = yPrefs[0];
    Item xIndex = xPref.getItem();
    Item yIndex = yPref.getItem();
    int xPrefIndex = 1;
    int yPrefIndex = 1;

    int intersectionSize = 0;
    while (true) {
View Full Code Here

    return new BookCrossingUser(id, prefs, city, state, country, age);
  }

  @Override
  protected Item buildItem(String id) {
    Item item = bookMap.get(id);
    if (item == null) {
      // some books aren't in books file?
      return new Book(id, null, null, 0, null);
    }
    return item;
View Full Code Here

    for (int itemIDNum = 1; itemIDNum < jokePrefs.length; itemIDNum++) { // yes skip first one, just a count
      String jokePref = jokePrefs[itemIDNum];
      if (!"99".equals(jokePref)) {
        double jokePrefValue = Double.parseDouble(jokePref);       
        String itemID = String.valueOf(itemIDNum);
        Item item = itemCache.get(itemID);
        if (item == null) {
          item = buildItem(itemID);
          itemCache.put(itemID, item);
        }
        prefs.add(new GenericPreference(null, item, jokePrefValue));
View Full Code Here

    Map<Object, Object> prefsForItems = new FastMap<Object, Object>();
    for (User user : users) {
      userMap.put(user.getID(), user);
      Preference[] prefsArray = user.getPreferencesAsArray();
      for (Preference preference : prefsArray) {
        Item item = preference.getItem();
        Object itemID = item.getID();
        itemMap.put(itemID, item);
        List<Preference> prefsForItem = (List<Preference>) prefsForItems.get(itemID);
        if (prefsForItem == null) {
          prefsForItem = new ArrayList<Preference>();
          prefsForItems.put(itemID, prefsForItem);
View Full Code Here

  /**
   * @throws NoSuchItemException if there is no such {@link Item}
   */
  @Override
  public Item getItem(Object id) throws NoSuchItemException {
    Item item = itemMap.get(id);
    if (item == null) {
      throw new NoSuchItemException();
    }
    return item;
  }
View Full Code Here

TOP

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

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.