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

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


  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 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

      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

      List<Preference> prefs2 = Lists.newArrayListWithCapacity(prefs2Array.length());
      for (Preference pref : prefs2Array) {
        prefs2.add(pref);
      }
      for (Iterator<Preference> iterator = prefs2.iterator(); iterator.hasNext(); ) {
        Preference pref = iterator.next();
        if (relevantItemIDs.contains(pref.getItemID())) {
          iterator.remove();
        }
      }
      if (!prefs2.isEmpty()) {
        trainingUsers.put(otherUserID, new GenericUserPreferenceArray(prefs2));
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

    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

      }
    }

    //merge this part into shuffle() will make compiler-optimizer do some real absurd stuff, test on OpenJDK7
    private void swapCachedPreferences(int x, int y) {
      Preference p = unstagedPreferences[x];

      unstagedPreferences[x] = unstagedPreferences[y];
      unstagedPreferences[y] = p;
    }
View Full Code Here

    public GenericItemPreferenceArray(List<Preference> prefs) {
        this(prefs.size());
        int size = prefs.size();
        for (int i = 0; i < size; i++) {
            Preference pref = prefs.get(i);
            ids[i] = pref.getUserID();
            values[i] = pref.getValue();
        }
        if (size > 0) {
            id = prefs.get(0).getItemID();
        }
    }
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.