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

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


                                                      int n) {
    // Cache to avoid most synchronization
    float localQueueLeastValue = queueLeastValue[0];

    while (values.hasNext()) {
      RecommendedItem value = values.next();
      if (value != null) {
        long itemID = value.getItemID();
        float valueScore = value.getValue();
        if (valueScore >= localQueueLeastValue) {

          synchronized (topN) {
            if (topN.size() > n) {
              float currentQueueLeastValue = topN.peek().getValue();
View Full Code Here


public final class ByValueAscComparatorTest extends MyrrixTest {

  @Test
  public void testCompare() {
    RecommendedItem a = new SimpleRecommendedItem(1L, 2.0f);
    RecommendedItem b = new SimpleRecommendedItem(5L, 1.0f);
    assertTrue(ByValueAscComparator.INSTANCE.compare(a, b) > 0);
    assertTrue(ByValueAscComparator.INSTANCE.compare(b, a) < 0);
    assertEquals(0, ByValueAscComparator.INSTANCE.compare(a, a));
  }
View Full Code Here

    assertEquals(0, ByValueAscComparator.INSTANCE.compare(a, a));
  }

  @Test
  public void testSameValue() {
    RecommendedItem a = new SimpleRecommendedItem(1L, 2.0f);
    RecommendedItem b = new SimpleRecommendedItem(5L, 2.0f);
    assertTrue(ByValueAscComparator.INSTANCE.compare(a, b) > 0);
    assertTrue(ByValueAscComparator.INSTANCE.compare(b, a) < 0);
    assertEquals(0, ByValueAscComparator.INSTANCE.compare(a, a));
  }
View Full Code Here

        double maxScore = 0.0;
        Mean precisionAtI = new Mean();
        double averagePrecision = 0.0;
 
        for (int i = 0; i < numRecs; i++) {
          RecommendedItem rec = recs.get(i);
          double value = LN2 / Math.log(2.0 + i); // 1 / log_2(1 + (i+1))
          if (valueIDs.contains(rec.getItemID())) {
            intersectionSize++;
            score += value;
            precisionAtI.increment(1.0);
            averagePrecision += precisionAtI.getResult();           
          } else {
View Full Code Here

      // nDCG
      // In computing, assume relevant IDs have relevance 1 and others 0
      double cumulativeGain = 0.0;
      double idealizedGain = 0.0;
      for (int i = 0; i < recommendedItems.size(); i++) {
        RecommendedItem item = recommendedItems.get(i);
        double discount = i == 0 ? 1.0 : 1.0 / log2(i + 1);
        if (relevantItemIDs.contains(item.getItemID())) {
          cumulativeGain += discount;
        }
        // otherwise we're multiplying discount by relevance 0 so it doesn't do anything

        // Ideally results would be ordered with all relevant ones first, so this theoretical
View Full Code Here

  @Override
  public boolean equals(Object o) {
    if (!(o instanceof GenericRecommendedItem)) {
      return false;
    }
    RecommendedItem other = (RecommendedItem) o;
    return itemID == other.getItemID() && value == other.getValue();
  }
View Full Code Here

    for (Entry<Long,List<RecommendedItem>> entry : recommendations.entrySet()) {
      long userID = entry.getKey();
      List<RecommendedItem> items = entry.getValue();
      assertNotNull(items);
      RecommendedItem item1 = items.get(0);

      if (userID == 1L) {
        assertEquals(1, items.size());
        assertEquals(4L, item1.getItemID());
        assertEquals(4.3, item1.getValue(), 0.05);
      }
      if (userID == 2L) {
        assertEquals(1, items.size());
        assertEquals(2L, item1.getItemID());
        assertEquals(3.3, item1.getValue(), 0.05);
      }
      if (userID == 3L) {
        assertEquals(2, items.size());
        assertEquals(3L, item1.getItemID());
        assertEquals(4.1, item1.getValue(), 0.05);
        RecommendedItem item2 = items.get(1);
        assertEquals(1L, item2.getItemID());
        assertEquals(3.7, item2.getValue(), 0.05);
      }
      if (userID == 4L) {
        assertEquals(2, items.size());
        assertEquals(2L, item1.getItemID());
        assertEquals(4.0, item1.getValue(), 0.05);
        RecommendedItem item2 = items.get(1);
        assertEquals(3L, item2.getItemID());
        assertEquals(3.5, item2.getValue(), 0.05);
      }
    }
  }
View Full Code Here

    Map<Long,List<RecommendedItem>> recommendations = readRecommendations(new File(outputDir, "part-r-00000"));

    List<RecommendedItem> recommendedToCow = recommendations.get(3L);
    assertEquals(2, recommendedToCow.size());

    RecommendedItem item1 = recommendedToCow.get(0);
    RecommendedItem item2 = recommendedToCow.get(1);

    assertEquals(1L, item1.getItemID());
    assertEquals(3L, item2.getItemID());

    /* predicted pref must be the sum of similarities:
    *    item1: coocc(burger, hotdog) + coocc(burger, icecream) = 3
    *    item2: coocc(berries, hotdog) + coocc(berries, icecream) = 2 */
    assertEquals(3, item1.getValue(), 0.05);
    assertEquals(2, item2.getValue(), 0.05);
  }
View Full Code Here

     assertEquals(1, recommendations.size());
     assertTrue(recommendations.containsKey(4L));
     assertEquals(1, recommendations.get(4L).size());

     /* berries should have been recommended to the donkey */
     RecommendedItem recommendedItem = recommendations.get(4L).get(0);
     assertEquals(3L, recommendedItem.getItemID());
     assertEquals(3.5, recommendedItem.getValue(), 0.05);
   }
View Full Code Here

  public void testRecommender() throws Exception {
    Recommender recommender = buildRecommender();
    List<RecommendedItem> recommended = recommender.recommend(1, 1);
    assertNotNull(recommended);
    assertEquals(1, recommended.size());
    RecommendedItem firstRecommended = recommended.get(0);
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.1f, firstRecommended.getValue(), EPSILON);
    recommender.refresh(null);
    recommended = recommender.recommend(1, 1);
    firstRecommended = recommended.get(0);   
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.1f, firstRecommended.getValue(), EPSILON);
  }
View Full Code Here

TOP

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

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.