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

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


    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, false))
        .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

  private final Recommender recommender;

  public Track1Recommender(DataModel dataModel) throws TasteException {
    // Change this to whatever you like!
    ItemSimilarity similarity = new UncenteredCosineSimilarity(dataModel);
    recommender = new GenericItemBasedRecommender(dataModel, similarity);
  }
View Full Code Here

  private final Recommender recommender;

  public Track2Recommender(DataModel dataModel, File dataFileDirectory) throws TasteException {
    // Change this to whatever you like!
    ItemSimilarity similarity;
    try {
      similarity = new HybridSimilarity(dataModel, dataFileDirectory);
    } catch (IOException ioe) {
      throw new TasteException(ioe);
    }
View Full Code Here

  public Recommender getRecommender() {
    return this.recommender;
  }

  private Recommender buildRecommender(DataModel dataModel, MahoutAlgoParams params) {
    ItemSimilarity similarity;
    switch (params.itemSimilarity) {
      case MahoutAlgoParams.LOG_LIKELIHOOD:
        similarity = new LogLikelihoodSimilarity(dataModel);
        break;
      case MahoutAlgoParams.TANIMOTO_COEFFICIENT:
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.