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

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


    }
    if (xPrefs.length == 0 || yPrefs.length == 0) {
      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) {
      int compare = xIndex.compareTo(yIndex);
      if (compare == 0) {
        intersectionSize++;
      }
      if (compare <= 0) {
        if (xPrefIndex == xPrefs.length) {
          break;
        }
        xPref = xPrefs[xPrefIndex++];
        xIndex = xPref.getItem();
      }
      if (compare >= 0) {
        if (yPrefIndex == yPrefs.length) {
          break;
        }
        yPref = yPrefs[yPrefIndex++];
        yIndex = yPref.getItem();
      }
    }

    int unionSize = xPrefs.length + yPrefs.length - intersectionSize;
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);
    return doEstimatePreference(theUser, theNeighborhood, itemID);
  }
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(itemID);
        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

  @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

    Preference[] prefs = theUser.getPreferencesAsArray();
    RunningAverage[] averages = diffStorage.getDiffs(theUser.getID(), itemID, prefs);
    for (int i = 0; i < prefs.length; i++) {
      RunningAverage averageDiff = averages[i];
      if (averageDiff != null) {
        Preference pref = prefs[i];
        double averageDiffValue = averageDiff.getAverage();
        if (weighted) {
          double weight = (double) averageDiff.getCount();
          if (stdDevWeighted) {
            double stdev = ((RunningAverageAndStdDev) averageDiff).getStandardDeviation();
            if (!Double.isNaN(stdev)) {
              weight /= 1.0 + stdev;
            }
            // If stdev is NaN, then it is because count is 1. Because we're weighting by count,
            // the weight is already relatively low. We effectively assume stdev is 0.0 here and
            // that is reasonable enough. Otherwise, dividing by NaN would yield a weight of NaN
            // and disqualify this pref entirely
            // (Thanks Daemmon)
          }
          totalPreference += weight * (pref.getValue() + averageDiffValue);
          count += weight;
        } else {
          totalPreference += pref.getValue() + averageDiffValue;
          count += 1.0;
        }
      }
    }
    if (count <= 0.0) {
View Full Code Here

  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);
    diffStorage.updateItemPref(itemID, prefDelta, false);
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 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();
    }
    checkAverageDiffsBuilt();
    return doEstimatePreference(userID, itemID);
  }
View Full Code Here

  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);
    try {
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) {
      double value = oldPref.getValue();
      try {
        buildAveragesLock.writeLock().lock();
        RunningAverage itemAverage = itemAverages.get(itemID);
        if (itemAverage == null) {
          throw new IllegalStateException("No preferences exist for item ID: " + itemID);
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.