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

Examples of org.apache.mahout.cf.taste.impl.model.GenericPreference


          Collection<Preference> userPrefs = userIDPrefMap.get(userID);
          if (userPrefs == null) {
            userPrefs = Lists.newArrayListWithCapacity(2);
            userIDPrefMap.put(userID, userPrefs);
          }
          userPrefs.add(new GenericPreference(userID, itemID, ratingValue));
          if (user.containsKey("created_at")
              && mongoTimestamp.compareTo(getDate(user.get("created_at"))) < 0) {
            mongoTimestamp = getDate(user.get("created_at"));
          }
        }
View Full Code Here


  @Before
  public void setUp() throws Exception {
    super.setUp();
    FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();

    userData.put(1L, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1L, 1L, 5.0f),
                                                                  new GenericPreference(1L, 2L, 5.0f),
                                                                  new GenericPreference(1L, 3L, 2.0f))));

    userData.put(2L, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2L, 1L, 2.0f),
                                                                  new GenericPreference(2L, 3L, 3.0f),
                                                                  new GenericPreference(2L, 4L, 5.0f))));

    userData.put(3L, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(3L, 2L, 5.0f),
                                                                  new GenericPreference(3L, 4L, 3.0f))));

    userData.put(4L, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(4L, 1L, 3.0f),
                                                                  new GenericPreference(4L, 4L, 5.0f))));

    dataModel = new GenericDataModel(userData);
    factorizer = new ALSWRFactorizer(dataModel, 3, 0.065, 10);
  }
View Full Code Here

    FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
    for (int userIndex = 0; userIndex < numUsers; userIndex++) {
      List<Preference> row= Lists.newArrayList();
      for (int itemIndex = 0; itemIndex < numItems; itemIndex++) {
        if (random.nextDouble() <= sparsity) {
          row.add(new GenericPreference(userIndex, itemIndex, (float) ratings.get(userIndex, itemIndex)));
        }
      }

      userData.put(userIndex, new GenericUserPreferenceArray(row));
    }
View Full Code Here

    this.lambda = 0.01;
    this.numIterations = 1000;

    FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();

    userData.put(1L, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1L, 1L, 5.0f),
        new GenericPreference(1L, 2L, 5.0f),
        new GenericPreference(1L, 3L, 2.0f))));

    userData.put(2L, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2L, 1L, 2.0f),
        new GenericPreference(2L, 3L, 3.0f),
        new GenericPreference(2L, 4L, 5.0f))));

    userData.put(3L, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(3L, 2L, 5.0f),
        new GenericPreference(3L, 4L, 3.0f))));

    userData.put(4L, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(4L, 1L, 3.0f),
        new GenericPreference(4L, 4L, 5.0f))));
    dataModel = new GenericDataModel(userData);
  }
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(qualifyingTxt))) {
      if (line.contains(MOVIE_DENOTER)) {
        currentMovieID = Long.parseLong(line.replaceAll(MOVIE_DENOTER, ""));
      } else {
        long userID = Long.parseLong(SEPARATOR.split(line)[0]);
        probes.add(new GenericPreference(userID, currentMovieID, 0));
      }
    }
    log.info("{} probes read...", probes.size());

    log.info("Reading ratings, creating probe set at {}/probeSet/ratings.tsv ...", outputPath);
View Full Code Here

        if (!exists) {
          if (prefs == null) {
            prefs = Lists.newArrayListWithCapacity(2);
            ((FastByIDMap<Collection<Preference>>) data).put(userID, prefs);
          }
          prefs.add(new GenericPreference(userID, itemID, preferenceValue));
        }

        addTimestamp(userID, itemID, timestampString, timestamps);

      }
View Full Code Here

    FastByIDMap<PreferenceArray> result = new FastByIDMap<PreferenceArray>();
    for (int i = 0; i < userIDs.length; i++) {
      List<Preference> prefsList = Lists.newArrayList();
      for (int j = 0; j < prefValues[i].length; j++) {
        if (prefValues[i][j] != null) {
          prefsList.add(new GenericPreference(userIDs[i], j, prefValues[i][j].floatValue()));
        }
      }
      if (!prefsList.isEmpty()) {
        result.put(userIDs[i], new GenericUserPreferenceArray(prefsList));
      }
View Full Code Here

    DataModel dataModel = EasyMock.createMock(DataModel.class);
    EasyMock.expect(dataModel.getNumItems()).andReturn(3);
    EasyMock.expect(dataModel.getItemIDs()).andReturn(allItemIDs.iterator());

    PreferenceArray prefArrayOfUser123 = new GenericUserPreferenceArray(Arrays.asList(
        new GenericPreference(123L, 2L, 1.0f)));

    CandidateItemsStrategy strategy = new AllUnknownItemsCandidateItemsStrategy();

    EasyMock.replay(dataModel);
View Full Code Here

    FastIDSet itemIDsFromUser456 = new FastIDSet();
    itemIDsFromUser456.add(1L);
    itemIDsFromUser456.add(2L);

    List<Preference> prefs = Lists.newArrayList();
    prefs.add(new GenericPreference(123L, 1L, 1.0f));
    prefs.add(new GenericPreference(456L, 1L, 1.0f));
    PreferenceArray preferencesForItem1 = new GenericItemPreferenceArray(prefs);

    DataModel dataModel = EasyMock.createMock(DataModel.class);
    EasyMock.expect(dataModel.getPreferencesForItem(1L)).andReturn(preferencesForItem1);
    EasyMock.expect(dataModel.getItemIDsFromUser(123L)).andReturn(itemIDsFromUser123);
    EasyMock.expect(dataModel.getItemIDsFromUser(456L)).andReturn(itemIDsFromUser456);

    PreferenceArray prefArrayOfUser123 =
        new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(123L, 1L, 1.0f)));

    CandidateItemsStrategy strategy = new PreferredItemsNeighborhoodCandidateItemsStrategy();

    EasyMock.replay(dataModel);
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.impl.model.GenericPreference

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.