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

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


                      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


    if (args.length > 1) {
      howMany = Integer.parseInt(args[1]);
    }

    System.out.println("Run Items");
    ItemSimilarity similarity = new EuclideanDistanceSimilarity(model);
    Recommender recommender = new GenericItemBasedRecommender(model, similarity); // Use an item-item recommender
    for (int i = 0; i < LOOPS; i++) {
      LoadStatistics loadStats = LoadEvaluator.runLoad(recommender, howMany);
      System.out.println(loadStats);
    }
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

                      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

   */
  @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

    statement.close();
    connection.close();

    EasyMock.replay(dataSource, connection, statement, resultSet);

    ItemSimilarity similarity = new MySQLJDBCInMemoryItemSimilarity(dataSource);

    assertEquals(0.5, similarity.itemSimilarity(1L, 2L), EPSILON);
    assertEquals(0.4, similarity.itemSimilarity(1L, 3L), EPSILON);
    assertEquals(0.1, similarity.itemSimilarity(3L, 4L), EPSILON);
    assertTrue(Double.isNaN(similarity.itemSimilarity(1L, 4L)));

    EasyMock.verify(dataSource, connection, statement, resultSet);
  }
View Full Code Here

      for (int j = i + 1; j < 6; j++) {
        similarities.add(
            new GenericItemSimilarity.ItemItemSimilarity(i, 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(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

    Collection<GenericItemSimilarity.ItemItemSimilarity> similarities =
        new ArrayList<GenericItemSimilarity.ItemItemSimilarity>(3);
    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

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.