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

Examples of org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity


                new GenericItemSimilarity.ItemItemSimilarity(new GenericItem<String>(String.valueOf(i)),
                                                               new GenericItem<String>(String.valueOf(j)),
                                                               1.0 / (1.0 + (double) i + (double) j)));
      }
    }
    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
    Recommender recommender = new GenericItemBasedRecommender(dataModel, similarity);
    List<RecommendedItem> fewRecommended = recommender.recommend("test1", 2);
    List<RecommendedItem> moreRecommended = recommender.recommend("test1", 4);
    for (int i = 0; i < fewRecommended.size(); i++) {
      assertEquals(fewRecommended.get(i).getItem(), moreRecommended.get(i).getItem());
View Full Code Here


    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item3, 0.5));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item4, 0.2));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item2, item3, 0.7));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item2, item4, 0.5));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item3, item4, 0.9));
    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
    Recommender recommender = new GenericItemBasedRecommender(dataModel, similarity);
    List<RecommendedItem> originalRecommended = recommender.recommend("test1", 2);
    List<RecommendedItem> rescoredRecommended =
            recommender.recommend("test1", 2, new ReversingRescorer<Item>());
    assertNotNull(originalRecommended);
View Full Code Here

    Item item1 = new GenericItem<String>("0");
    Item item2 = new GenericItem<String>("1");
    Item item3 = new GenericItem<String>("2");
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item2, 1.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item3, 0.5));
    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
    return new GenericItemBasedRecommender(dataModel, similarity);
  }
View Full Code Here

    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item2, item4, 0.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item2, item2, 1.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item3, item4, -0.1));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item3, item5, 0.1));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item4, item5, -0.5));
    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
    return new GenericItemBasedRecommender(dataModel, similarity);
  }
View Full Code Here

  }

  @Test
  public void testFileItemItemSimilarityIterable() throws Exception {
    Iterable<ItemItemSimilarity> similarityIterable = new FileItemItemSimilarityIterable(testFile);
    GenericItemSimilarity similarity = new GenericItemSimilarity(similarityIterable);

    assertEquals(0.125, similarity.itemSimilarity(1L, 5L), EPSILON);
    assertEquals(0.125, similarity.itemSimilarity(5L, 1L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(1L, 7L), EPSILON);
    assertEquals(0.5, similarity.itemSimilarity(7L, 1L), EPSILON);

    assertTrue(Double.isNaN(similarity.itemSimilarity(7L, 8L)));

    double[] valuesForOne = similarity.itemSimilarities(1L, new long[] { 5L, 7L });
    assertNotNull(valuesForOne);
    assertEquals(2, valuesForOne.length);
    assertEquals(0.125, valuesForOne[0], EPSILON);
    assertEquals(0.5, valuesForOne[1], EPSILON);
  }
View Full Code Here

  }

  protected void reload() {
    if (reloadLock.tryLock()) {
      try {
        delegate = new GenericItemSimilarity(new JDBCSimilaritiesIterable(dataSource, getAllItemSimilaritiesSQL));
      } finally {
        reloadLock.unlock();
      }
    }
  }
View Full Code Here

      for (int j = i + 1; j < 6; j++) {
        similarities.add(
            new GenericItemSimilarity.ItemItemSimilarity(i, j, 1.0 / (1.0 + i + j)));
      }
    }
    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
    Recommender recommender = new GenericItemBasedRecommender(dataModel, similarity);
    List<RecommendedItem> fewRecommended = recommender.recommend(1, 2);
    List<RecommendedItem> moreRecommended = recommender.recommend(1, 4);
    for (int i = 0; i < fewRecommended.size(); i++) {
      assertEquals(fewRecommended.get(i).getItemID(), moreRecommended.get(i).getItemID());
View Full Code Here

    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(0, 2, 0.5));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(0, 3, 0.2));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(1, 2, 0.7));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(1, 3, 0.5));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(2, 3, 0.9));
    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
    Recommender recommender = new GenericItemBasedRecommender(dataModel, similarity);
    List<RecommendedItem> originalRecommended = recommender.recommend(1, 2);
    List<RecommendedItem> rescoredRecommended =
        recommender.recommend(1, 2, new ReversingRescorer<Long>());
    assertNotNull(originalRecommended);
View Full Code Here

    DataModel dataModel = getDataModel();
    Collection<GenericItemSimilarity.ItemItemSimilarity> similarities = Lists.newArrayList();
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(0, 1, 1.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(0, 2, 0.5));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(1, 2, 0.0));
    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
    return new GenericItemBasedRecommender(dataModel, similarity);
  }
View Full Code Here

    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(1, 3, 0.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(1, 1, 1.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(2, 3, -0.1));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(2, 4, 0.1));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(3, 4, -0.5));
    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
    return new GenericItemBasedRecommender(dataModel, similarity);
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity

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.