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

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


      while (userIDsIterator.hasNext()) {
        long userID = userIDsIterator.nextLong();
        userIDs.add(userID);
        for (Preference preference : dataModel.getPreferencesFromUser(userID)) {
          itemIDs.add(preference.getItemID());
          preferences.add(new GenericPreference(userID, preference.getItemID(), preference.getValue()));
        }
      }
    } catch (TasteException te) {
      throw new IllegalStateException("Unable to create factorizable preferences!", te);
    }
View Full Code Here


    Collection<Preference> prefs = Lists.newArrayListWithCapacity(count);
    for (int itemID = 1; itemID < jokePrefs.length; itemID++) { // yes skip first one, just a count
      String jokePref = jokePrefs[itemID];
      if (!"99".equals(jokePref)) {
        float jokePrefValue = Float.parseFloat(jokePref);
        prefs.add(new GenericPreference(userBeingRead, itemID, jokePrefValue));
      }
    }
    data.put(userBeingRead, prefs);
    userBeingRead++;
  }
View Full Code Here

    CandidateItemsStrategy candidateItemsStrategy = EasyMock.createMock(CandidateItemsStrategy.class);
    MostSimilarItemsCandidateItemsStrategy mostSimilarItemsCandidateItemsStrategy =
        EasyMock.createMock(MostSimilarItemsCandidateItemsStrategy.class);

    PreferenceArray preferencesFromUser = new GenericUserPreferenceArray(
        Arrays.asList(new GenericPreference(1L, 1L, 5.0f), new GenericPreference(1L, 2L, 4.0f)));

    EasyMock.expect(dataModel.getMinPreference()).andReturn(Float.NaN);
    EasyMock.expect(dataModel.getMaxPreference()).andReturn(Float.NaN);

    EasyMock.expect(dataModel.getPreferencesFromUser(1L)).andReturn(preferencesFromUser);
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

  @Test
  public void testStdev() throws Exception {
    DataModel dataModel = getDataModel(new long[] {1}, new Double[][] {{-1.0,-2.0}});
    PreferenceTransform zScore = new ZScore(dataModel);
    assertEquals(Math.sqrt(2.0)/2.0, zScore.getTransformedValue(new GenericPreference(1, 0, -1.0f)), EPSILON);
    assertEquals(-Math.sqrt(2.0)/2.0, zScore.getTransformedValue(new GenericPreference(1, 1, -2.0f)), EPSILON);
  }
View Full Code Here

  @Test
  public void testExample() throws Exception {
    DataModel dataModel = getDataModel(new long[] {1}, new Double[][] {{5.0, 7.0, 9.0}});
    PreferenceTransform zScore = new ZScore(dataModel);
    assertEquals(-1.0, zScore.getTransformedValue(new GenericPreference(1, 0, 5.0f)), EPSILON);
    assertEquals(0.0, zScore.getTransformedValue(new GenericPreference(1, 1, 7.0f)), EPSILON);
    assertEquals(1.0, zScore.getTransformedValue(new GenericPreference(1, 2, 9.0f)), EPSILON);
  }
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

    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(Collections.singletonList(new GenericPreference(123L, 1L, 1.0f)));

    CandidateItemsStrategy strategy = new PreferredItemsNeighborhoodCandidateItemsStrategy();

    EasyMock.replay(dataModel);
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(Collections.singletonList(
        new GenericPreference(123L, 2L, 1.0f)));

    CandidateItemsStrategy strategy = new AllUnknownItemsCandidateItemsStrategy();

    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.