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

Examples of org.apache.mahout.cf.taste.impl.recommender.GenericRecommendedItem


  @Test
  public void testAggregateAndRecommendReducer() throws Exception {
    Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);

    context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new GenericRecommendedItem(1L, 2.8f),
        new GenericRecommendedItem(2L, 2.0f)));

    EasyMock.replay(context);

    RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumnOne.set(1, 0.1);
View Full Code Here


  @Test
  public void testAggregateAndRecommendReducerExcludeRecommendationsBasedOnOneItem() throws Exception {
    Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);

    context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new GenericRecommendedItem(1L, 2.8f)));

    EasyMock.replay(context);

    RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumnOne.set(1, 0.1);
View Full Code Here

  @Test
  public void testAggregateAndRecommendReducerLimitNumberOfRecommendations() throws Exception {
    Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context =
      EasyMock.createMock(Reducer.Context.class);

    context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new GenericRecommendedItem(1L, 2.8f)));

    EasyMock.replay(context);

    RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumnOne.set(1, 0.1);
View Full Code Here

      List<RecommendedItem> items = new LinkedList<RecommendedItem>();
      for (String token : tokens) {
        String[] itemTokens = token.split(":");
        long itemID = Long.parseLong(itemTokens[0]);
        float value = Float.parseFloat(itemTokens[1]);
        items.add(new GenericRecommendedItem(itemID, value));
      }
      recommendations.put(userID, items);
    }
    return recommendations;
  }
View Full Code Here

      List<RecommendedItem> items = Lists.newLinkedList();
      for (String token : tokens) {
        String[] itemTokens = token.split(":");
        long itemID = Long.parseLong(itemTokens[0]);
        float value = Float.parseFloat(itemTokens[1]);
        items.add(new GenericRecommendedItem(itemID, value));
      }
      recommendations.put(userID, items);
    }
    return recommendations;
  }
View Full Code Here

        itemID = index;
      }
      if (itemsToRecommendFor == null || itemsToRecommendFor.contains(itemID)) {
        float value = (float) element.get();
        if (!Float.isNaN(value)) {
          topKItems.offer(new GenericRecommendedItem(itemID, value));
        }
      }
    }

    if (!topKItems.isEmpty()) {
View Full Code Here

    int size = in.readInt();
    recommended = Lists.newArrayListWithCapacity(size);
    for (int i = 0; i < size; i++) {
      long itemID = Varint.readSignedVarLong(in);
      float value = in.readFloat();
      RecommendedItem recommendedItem = new GenericRecommendedItem(itemID, value);
      recommended.add(recommendedItem);
    }
  }
View Full Code Here

      M.forEachPair(new IntObjectProcedure<Vector>() {
        @Override
        public boolean apply(int itemID, Vector itemFeatures) {
          if (!alreadyRatedItems.contains(itemID)) {
            double predictedRating = U.get(userID).dot(itemFeatures);
            topKItems.offer(new GenericRecommendedItem(itemID, (float) predictedRating));
          }
          return true;
        }
      });

      List<RecommendedItem> recommendedItems = Lists.newArrayListWithExpectedSize(recommendationsPerUser);
      for (RecommendedItem topItem : topKItems.retrieve()) {
        recommendedItems.add(new GenericRecommendedItem(topItem.getItemID(), Math.min(topItem.getValue(), maxRating)));
      }

      if (!topKItems.isEmpty()) {
        ctx.write(userIDWritable, new RecommendedItemsWritable(recommendedItems));
      }
View Full Code Here

  @Test
  public void testAggregateAndRecommendReducer() throws Exception {
    Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);

    context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new GenericRecommendedItem(1L, 2.8f),
        new GenericRecommendedItem(2L, 2.0f)));

    EasyMock.replay(context);

    RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumnOne.set(1, 0.1);
View Full Code Here

  @Test
  public void testAggregateAndRecommendReducerExcludeRecommendationsBasedOnOneItem() throws Exception {
    Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);

    context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new GenericRecommendedItem(1L, 2.8f)));

    EasyMock.replay(context);

    RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumnOne.set(1, 0.1);
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.impl.recommender.GenericRecommendedItem

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.