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

Examples of org.apache.mahout.cf.taste.similarity.ItemSimilarity


            new Double[][] {
                    {0.1, 0.2},
                    {0.2, 0.3, 0.3, 0.6},
                    {0.4, 0.5, 0.5, 0.9},
            });
    ItemSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    Optimizer optimizer = new ConjugateGradientOptimizer();
    Recommender recommender = new KnnItemBasedRecommender(dataModel, similarity, optimizer, 5);
    List<RecommendedItem> originalRecommended = recommender.recommend(1, 2);
    List<RecommendedItem> rescoredRecommended =
        recommender.recommend(1, 2, new ReversingRescorer<Long>());
View Full Code Here


    assertEquals(0.1f, firstRecommended.getValue(), EPSILON);
  }

  private static Recommender buildRecommender() throws TasteException {
    DataModel dataModel = getDataModel();
    ItemSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    Optimizer optimizer = new ConjugateGradientOptimizer();
    return new KnnItemBasedRecommender(dataModel, similarity, optimizer, 5);
  }
View Full Code Here

            new Double[][] {
                    {1.0, 2.0},
                    {2.0, 5.0},
                    {3.0, 6.0},
            });
    ItemSimilarity itemSimilarity = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED);
    double correlation = itemSimilarity.itemSimilarity(0, 1);
    assertCorrelationEquals(0.8210911630511055, correlation);
  }
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

   */
  @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()))
        .andReturn(new double[] { 0.4, 0.1 });

    EasyMock.replay(dataModel, itemSimilarity, candidateItemsStrategy, mostSimilarItemsCandidateItemsStrategy);

    Recommender recommender = new GenericItemBasedRecommender(dataModel, itemSimilarity,
View Full Code Here

            new Double[][] {
                    {1.0, 2.0},
                    {2.0, 5.0},
                    {3.0, 6.0},
            });
    ItemSimilarity otherSimilarity = new PearsonCorrelationSimilarity(dataModel);
    ItemSimilarity itemSimilarity = new GenericItemSimilarity(otherSimilarity, dataModel);
    assertCorrelationEquals(1.0, itemSimilarity.itemSimilarity(0, 0));
    assertCorrelationEquals(0.960768922830523, itemSimilarity.itemSimilarity(0, 1));
  }
View Full Code Here

                      new GenericItemSimilarity.ItemItemSimilarity(1L, 3L, 0.2),
                      new GenericItemSimilarity.ItemItemSimilarity(2L, 1L, 0.2),
                      new GenericItemSimilarity.ItemItemSimilarity(3L, 5L, 0.2),
                      new GenericItemSimilarity.ItemItemSimilarity(3L, 4L, 0.2));

    ItemSimilarity similarity = new GenericItemSimilarity(itemItemSimilarities);

    assertTrue(containsExactly(similarity.allSimilarItemIDs(1L), 2L, 3L));
    assertTrue(containsExactly(similarity.allSimilarItemIDs(2L), 1L));
    assertTrue(containsExactly(similarity.allSimilarItemIDs(3L), 1L, 5L, 4L));
    assertTrue(containsExactly(similarity.allSimilarItemIDs(4L), 3L));
    assertTrue(containsExactly(similarity.allSimilarItemIDs(5L), 3L));
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.similarity.ItemSimilarity

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.