Package org.apache.mahout.cf.taste.recommender

Examples of org.apache.mahout.cf.taste.recommender.CandidateItemsStrategy


    userData.put(456L, new GenericUserPreferenceArray(prefsOfUser456));
    userData.put(789L, new GenericUserPreferenceArray(prefsOfUser789));

    DataModel dataModel = new GenericDataModel(userData);

    CandidateItemsStrategy strategy = new SamplingCandidateItemsStrategy(1, 1);

    FastIDSet candidateItems = strategy.getCandidateItems(123L, dataModel);
    /* result can be either item2 or item3 or empty */
    assertTrue(candidateItems.size() <= 1);
    assertFalse(candidateItems.contains(1L));
  }
View Full Code Here


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

    CandidateItemsStrategy strategy = new AllUnknownItemsCandidateItemsStrategy();

    EasyMock.replay(dataModel);

    FastIDSet candidateItems = strategy.getCandidateItems(123L, dataModel);
    assertEquals(2, candidateItems.size());
    assertTrue(candidateItems.contains(1L));
    assertTrue(candidateItems.contains(3L));

    EasyMock.verify(dataModel);
View Full Code Here

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

    CandidateItemsStrategy strategy = new PreferredItemsNeighborhoodCandidateItemsStrategy();

    EasyMock.replay(dataModel);

    FastIDSet candidateItems = strategy.getCandidateItems(123L, dataModel);
    assertEquals(1, candidateItems.size());
    assertTrue(candidateItems.contains(2L));

    EasyMock.verify(dataModel);
  }
View Full Code Here

  @Test
  public void recommend() throws Exception {
    DataModel dataModel = EasyMock.createMock(DataModel.class);
    PreferenceArray preferencesFromUser = EasyMock.createMock(PreferenceArray.class);
    CandidateItemsStrategy candidateItemsStrategy = EasyMock.createMock(CandidateItemsStrategy.class);
    Factorizer factorizer = EasyMock.createMock(Factorizer.class);
    Factorization factorization = EasyMock.createMock(Factorization.class);

    FastIDSet candidateItems = new FastIDSet();
    candidateItems.add(5L);
    candidateItems.add(3L);

    EasyMock.expect(factorizer.factorize()).andReturn(factorization);
    EasyMock.expect(dataModel.getPreferencesFromUser(1L)).andReturn(preferencesFromUser);
    EasyMock.expect(candidateItemsStrategy.getCandidateItems(1L, preferencesFromUser, dataModel))
        .andReturn(candidateItems);
    EasyMock.expect(factorization.getUserFeatures(1L)).andReturn(new double[] { 0.4, 2 });
    EasyMock.expect(factorization.getItemFeatures(5L)).andReturn(new double[] { 1, 0.3 });
    EasyMock.expect(factorization.getUserFeatures(1L)).andReturn(new double[] { 0.4, 2 });
    EasyMock.expect(factorization.getItemFeatures(3L)).andReturn(new double[] { 2, 0.6 });
View Full Code Here

  @Test
  public void preferencesFetchedOnlyOnce() throws Exception {

    DataModel dataModel = EasyMock.createMock(DataModel.class);
    ItemSimilarity itemSimilarity = EasyMock.createMock(ItemSimilarity.class);
    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);
    EasyMock.expect(candidateItemsStrategy.getCandidateItems(1L, preferencesFromUser, dataModel))
        .andReturn(new FastIDSet(new long[] { 3L, 4L }));

    EasyMock.expect(itemSimilarity.itemSimilarities(3L, preferencesFromUser.getIDs()))
        .andReturn(new double[] { 0.5, 0.3 });
    EasyMock.expect(itemSimilarity.itemSimilarities(4L, preferencesFromUser.getIDs()))
View Full Code Here

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

    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel);
    assertEquals(1, candidateItems.size());
    assertTrue(candidateItems.contains(2L));

    EasyMock.verify(dataModel);
  }
View Full Code Here

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

    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel);
    assertEquals(2, candidateItems.size());
    assertTrue(candidateItems.contains(1L));
    assertTrue(candidateItems.contains(3L));

    EasyMock.verify(dataModel);
View Full Code Here

    userData.put(456L, new GenericUserPreferenceArray(prefsOfUser456));
    userData.put(789L, new GenericUserPreferenceArray(prefsOfUser789));

    DataModel dataModel = new GenericDataModel(userData);

    CandidateItemsStrategy strategy =
        new SamplingCandidateItemsStrategy(1, 1, 1, dataModel.getNumUsers(), dataModel.getNumItems());

    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel);
    /* result can be either item2 or item3 or empty */
    assertTrue(candidateItems.size() <= 1);
    assertFalse(candidateItems.contains(1L));
  }
View Full Code Here

    userData.put(456L, new GenericUserPreferenceArray(prefsOfUser456));
    userData.put(789L, new GenericUserPreferenceArray(prefsOfUser789));

    DataModel dataModel = new GenericDataModel(userData);

    CandidateItemsStrategy strategy = new SamplingCandidateItemsStrategy(1, 1);

    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel);
    /* result can be either item2 or item3 or empty */
    assertTrue(candidateItems.size() <= 1);
    assertFalse(candidateItems.contains(1L));
  }
View Full Code Here

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

    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel);
    assertEquals(2, candidateItems.size());
    assertTrue(candidateItems.contains(1L));
    assertTrue(candidateItems.contains(3L));

    EasyMock.verify(dataModel);
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.recommender.CandidateItemsStrategy

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.