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

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


    PreferenceArray sortedPrefs = rawPrefs.clone();
    sortedPrefs.sortByValueReversed();
    // Cap this at NUM_TOP_PREFERENCES just to be brief
    int max = Math.min(NUM_TOP_PREFERENCES, length);
    for (int i = 0; i < max; i++) {
      Preference pref = sortedPrefs.get(i);
      writer.print(pref.getValue());
      writer.print('\t');
      writer.println(pref.getItemID());
    }
    writer.println();
    writer.println("Recommendations:");
    for (RecommendedItem recommendedItem : items) {
      writer.print(recommendedItem.getValue());
View Full Code Here


    List<Preference> trainingPrefs = null;
    List<Preference> testPrefs = null;
    PreferenceArray prefs = dataModel.getPreferencesFromUser(userID);
    int size = prefs.length();
    for (int i = 0; i < size; i++) {
      Preference newPref = new GenericPreference(userID, prefs.getItemID(i), prefs.getValue(i));
      if (random.nextDouble() < trainingPercentage) {
        if (trainingPrefs == null) {
          trainingPrefs = new ArrayList<Preference>(3);
        }
        trainingPrefs.add(newPref);
View Full Code Here

  public GenericUserPreferenceArray(List<? extends Preference> prefs) {
    this(prefs.size());
    int size = prefs.size();
    long userID = Long.MIN_VALUE;
    for (int i = 0; i < size; i++) {
      Preference pref = prefs.get(i);
      if (i == 0) {
        userID = pref.getUserID();
      } else {
        if (userID != pref.getUserID()) {
          throw new IllegalArgumentException("Not all user IDs are the same");
        }
      }
      ids[i] = pref.getItemID();
      values[i] = pref.getValue();
    }
    id = userID;
  }
View Full Code Here

 
  public BooleanUserPreferenceArray(List<? extends Preference> prefs) {
    this(prefs.size());
    int size = prefs.size();
    for (int i = 0; i < size; i++) {
      Preference pref = prefs.get(i);
      ids[i] = pref.getItemID();
    }
    if (size > 0) {
      id = prefs.get(0).getUserID();
    }
  }
View Full Code Here

        // Then line is of form "userID,itemID,", meaning remove
        if (prefs != null) {
          // remove pref
          Iterator<Preference> prefsIterator = prefs.iterator();
          while (prefsIterator.hasNext()) {
            Preference pref = prefsIterator.next();
            if (pref.getItemID() == itemID) {
              prefsIterator.remove();
              break;
            }
          }
        }

        removeTimestamp(userID, itemID, timestamps);
       
      } else {

        float preferenceValue = Float.parseFloat(preferenceValueString);

        boolean exists = false;
        if (prefs != null) {
          for (Preference pref : prefs) {
            if (pref.getItemID() == itemID) {
              exists = true;
              pref.setValue(preferenceValue);
              break;
            }
          }
        }
View Full Code Here

  @Test
  public void testPreferencesForItem() throws Exception {
    PreferenceArray prefs = model.getPreferencesForItem(456);
    assertNotNull(prefs);
    Preference pref1 = prefs.get(0);
    assertEquals(123, pref1.getUserID());
    assertEquals(456, pref1.getItemID());
    Preference pref2 = prefs.get(1);
    assertEquals(456, pref2.getUserID());
    assertEquals(456, pref2.getItemID());
    assertEquals(2, prefs.length());
  }
View Full Code Here

        // Then line is of form "userID,itemID,", meaning remove
        if (prefs != null) {
          // remove pref
          Iterator<Preference> prefsIterator = prefs.iterator();
          while (prefsIterator.hasNext()) {
            Preference pref = prefsIterator.next();
            if (pref.getItemID() == itemID) {
              prefsIterator.remove();
              break;
            }
          }
        }

        removeTimestamp(userID, itemID, timestamps);
       
      } else {

        float preferenceValue = Float.parseFloat(preferenceValueString);

        boolean exists = false;
        if (prefs != null) {
          for (Preference pref : prefs) {
            if (pref.getItemID() == itemID) {
              exists = true;
              pref.setValue(preferenceValue);
              break;
            }
          }
        }
View Full Code Here

    List<Preference> oneUserTrainingPrefs = null;
    List<Preference> oneUserTestPrefs = null;
    PreferenceArray prefs = dataModel.getPreferencesFromUser(userID);
    int size = prefs.length();
    for (int i = 0; i < size; i++) {
      Preference newPref = new GenericPreference(userID, prefs.getItemID(i), prefs.getValue(i));
      if (random.nextDouble() < trainingPercentage) {
        if (oneUserTrainingPrefs == null) {
          oneUserTrainingPrefs = Lists.newArrayListWithCapacity(3);
        }
        oneUserTrainingPrefs.add(newPref);
View Full Code Here

    shuffler.stage();

    FastByIDMap<FastByIDMap<Boolean>> checked = new FastByIDMap<FastByIDMap<Boolean>>();

    for (int i = 0; i < shuffler.size(); i++) {
      Preference pref=shuffler.get(i);

      float value = dataModel.getPreferenceValue(pref.getUserID(), pref.getItemID());
      assertEquals(pref.getValue(), value, 0.0);
      if (!checked.containsKey(pref.getUserID())) {
        checked.put(pref.getUserID(), new FastByIDMap<Boolean>());
      }

      assertNull(checked.get(pref.getUserID()).get(pref.getItemID()));

      checked.get(pref.getUserID()).put(pref.getItemID(), true);
    }

    LongPrimitiveIterator userIDs = dataModel.getUserIDs();
    int index=0;
    while (userIDs.hasNext()) {
View Full Code Here

  @Test
  public void testPreferencesForItem() throws Exception {
    PreferenceArray prefs = model.getPreferencesForItem(456);
    assertNotNull(prefs);
    Preference pref1 = prefs.get(0);
    assertEquals(123, pref1.getUserID());
    assertEquals(456, pref1.getItemID());
    Preference pref2 = prefs.get(1);
    assertEquals(456, pref2.getUserID());
    assertEquals(456, pref2.getItemID());
    assertEquals(2, prefs.length());
  }
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.