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

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


    InverseUserFrequency iuf = new InverseUserFrequency(dataModel, 10.0);

    PreferenceArray user5Prefs = dataModel.getPreferencesFromUser(5);

    for (int i = 0; i < 5; i++) {
      Preference pref = user5Prefs.get(i);
      assertNotNull(pref);
      assertEquals(Math.log(5.0 / (5.0 - i)) / Math.log(iuf.getLogBase()),
          iuf.getTransformedValue(pref),
          EPSILON);
    }
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

 
  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

  public GenericItemPreferenceArray(List<? extends Preference> prefs) {
    this(prefs.size());
    int size = prefs.size();
    long itemID = Long.MIN_VALUE;
    for (int i = 0; i < size; i++) {
      Preference pref = prefs.get(i);
      ids[i] = pref.getUserID();
      if (i == 0) {
        itemID = pref.getItemID();
      } else {
        if (itemID != pref.getItemID()) {
          throw new IllegalArgumentException("Not all item IDs are the same");
        }
      }
      values[i] = pref.getValue();
    }
    id = itemID;
  }
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

 
  public BooleanItemPreferenceArray(List<? extends Preference> prefs, boolean forOneUser) {
    this(prefs.size());
    int size = prefs.size();
    for (int i = 0; i < size; i++) {
      Preference pref = prefs.get(i);
      ids[i] = forOneUser ? pref.getItemID() : pref.getUserID();
    }
    if (size > 0) {
      id = forOneUser ? prefs.get(0).getUserID() : prefs.get(0).getItemID();
    }
  }
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

    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

      for (String line : new FileLineIterable(new File(judgingTxt))) {
        if (line.contains(MOVIE_DENOTER)) {
          currentMovieID = Long.parseLong(line.replaceAll(MOVIE_DENOTER, ""));
        } else {
          float rating = Float.parseFloat(SEPARATOR.split(line)[0]);
          Preference pref = probes.get(ratingsProcessed);
          Preconditions.checkState(pref.getItemID() == currentMovieID);
          ratingsProcessed++;
          writer.write(pref.getUserID() + TAB + pref.getItemID() + TAB + rating + NEWLINE);
          if (ratingsProcessed % 1000000 == 0) {
            log.info("{} ratings processed...", ratingsProcessed);
          }
        }
      }
View Full Code Here

  }

  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.