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

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


    log.debug("Processing prefs for user {}", user);
    // Save off prefs for the life of this loop iteration
    Preference[] userPreferences = user.getPreferencesAsArray();
    int length = userPreferences.length;
    for (int i = 0; i < length; i++) {
      Preference prefA = userPreferences[i];
      double prefAValue = prefA.getValue();
      Object itemIDA = prefA.getItem().getID();
      FastMap<Object, RunningAverage> aMap = averageDiffs.get(itemIDA);
      if (aMap == null) {
        aMap = new FastMap<Object, RunningAverage>();
        averageDiffs.put(itemIDA, aMap);
      }
      for (int j = i + 1; j < length; j++) {
        // This is a performance-critical block
        Preference prefB = userPreferences[j];
        Object itemIDB = prefB.getItem().getID();
        RunningAverage average = aMap.get(itemIDB);
        if (average == null && averageCount < maxEntries) {
          average = buildRunningAverage();
          aMap.put(itemIDB, average);
          averageCount++;
        }
        if (average != null) {
          average.addDatum(prefB.getValue() - prefAValue);
        }

      }
      RunningAverage itemAverage = averageItemPref.get(itemIDA);
      if (itemAverage == null) {
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();
    }
    Collection<User> theNeighborhood = neighborhood.getUserNeighborhood(userID);
    Item item = model.getItem(itemID);
    return doEstimatePreference(theUser, theNeighborhood, item);
  }
View Full Code Here

    double preference = 0.0;
    double totalSimilarity = 0.0;
    for (User user : theNeighborhood) {
      if (!user.equals(theUser)) {
        // See GenericItemBasedRecommender.doEstimatePreference() too
        Preference pref = user.getPreferenceFor(item.getID());
        if (pref != null) {
          double theSimilarity = similarity.userSimilarity(theUser, user) + 1.0;
          if (!Double.isNaN(theSimilarity)) {
            preference += theSimilarity * pref.getValue();
            totalSimilarity += theSimilarity;
          }
        }
      }
    }
View Full Code Here

      rs = stmt.executeQuery();
      List<Preference> prefs = new ArrayList<Preference>();
      while (rs.next()) {
        double preference = rs.getDouble(1);
        String userID = rs.getString(2);
        Preference pref = buildPreference(buildUser(userID, null), item, preference);
        prefs.add(pref);
      }
      return prefs;
    } catch (SQLException sqle) {
      log.warn("Exception while retrieving prefs for item", sqle);
View Full Code Here

    if (userID == null || itemID == null) {
      throw new IllegalArgumentException("userID or itemID is null");
    }
    DataModel model = getDataModel();
    User theUser = model.getUser(userID);
    Preference actualPref = theUser.getPreferenceFor(itemID);
    if (actualPref != null) {
      return actualPref.getValue();
    }
    checkClustersBuilt();
    List<RecommendedItem> topRecsForUser = topRecsByUserID.get(userID);
    if (topRecsForUser != null) {
      for (RecommendedItem item : topRecsForUser) {
View Full Code Here

                              User user) {
    List<Preference> trainingPrefs = new ArrayList<Preference>();
    List<Preference> testPrefs = new ArrayList<Preference>();
    Preference[] prefs = user.getPreferencesAsArray();
    for (Preference pref : prefs) {
      Preference newPref = new GenericPreference(null, pref.getItem(), pref.getValue());
      if (random.nextDouble() < trainingPercentage) {
        trainingPrefs.add(newPref);
      } else {
        testPrefs.add(newPref);
      }
View Full Code Here

    if (preferenceValueString != null && preferenceValueString.length() == 0) {
      // remove pref
      Iterator<Preference> prefsIterator = prefs.iterator();
      while (prefsIterator.hasNext()) {
        Preference pref = prefsIterator.next();
        if (pref.getItem().getID().equals(itemID)) {
          prefsIterator.remove();
          break;
        }
      }
    } else {
View Full Code Here

    @Override
    public double estimate(Item item) {
      RunningAverage average = new FullRunningAverage();
      for (User user : cluster) {
        Preference pref = user.getPreferenceFor(item.getID());
        if (pref != null) {
          average.addDatum(pref.getValue());
        }
      }
      return average.getAverage();
    }
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();
    }
    Item item = model.getItem(itemID);
    return doEstimatePreference(theUser, item);
  }
View Full Code Here

      this.similarity = similarity;
    }

    @Override
    public double estimate(Item item) throws TasteException {
      Preference pref = user.getPreferenceFor(item.getID());
      if (pref == null) {
        return Double.NaN;
      }
      double similarityValue = similarity.itemSimilarity(recommendedItem, item);
      return (1.0 + similarityValue) * pref.getValue();
    }
View Full Code Here

TOP

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

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.