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

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


    while (recommendationVectorIterator.hasNext()) {
      Vector.Element element = recommendationVectorIterator.next();
      int index = element.index();
      float value = (float) element.get();
      if (topItems.size() < recommendationsPerUser) {
        topItems.add(new GenericRecommendedItem(indexItemIDMap
            .get(index), value));
      } else if (value > topItems.peek().getValue()) {
        topItems.add(new GenericRecommendedItem(indexItemIDMap
            .get(index), value));
        topItems.poll();
      }
    }
View Full Code Here


      Vector.Element element = recommendationVectorIterator.next();
      int index = element.index();
      if (userVector.get(index) == 0.0) {
        if (topItems.size() < recommendationsPerUser) {
          indexItemIDMap.get(new IntWritable(index), itemID);
          topItems.add(new GenericRecommendedItem(itemID.get(), (float) element.get()));
        } else if (element.get() > topItems.peek().getValue()) {
          indexItemIDMap.get(new IntWritable(index), itemID);
          topItems.add(new GenericRecommendedItem(itemID.get(), (float) element.get()));
          topItems.poll();
        }
      }
    }
   
View Full Code Here

    try {
      do {
        long itemID = in.readLong();
        float value = in.readFloat();
        if (!Float.isNaN(value)) {
          RecommendedItem recommendedItem = new GenericRecommendedItem(itemID, value);
          recommended.add(recommendedItem);
        }
      } while (true);
    } catch (EOFException eofe) {
      // continue; done
View Full Code Here

    int size = in.readInt();
    recommended = new ArrayList<RecommendedItem>(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

      Vector.Element prediction = predictions.next();
      /* NaN means the user already knows this item */
      if (!Double.isNaN(prediction.get())) {
        long itemID = indexItemIDMap.get(prediction.index());
        if (itemsToRecommendFor == null || itemsToRecommendFor.contains(itemID)) {
          recommendations.add(new GenericRecommendedItem(itemID, BOOLEAN_PREF_VALUE));
        }
      }
    }

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

      long itemID = indexItemIDMap.get(index);
      if (itemsToRecommendFor == null || itemsToRecommendFor.contains(itemID)) {
        float value = (float) element.get();
        if (!Float.isNaN(value)) {
          if (topItems.size() < recommendationsPerUser) {
            topItems.add(new GenericRecommendedItem(itemID, value));
          } else if (value > topItems.peek().getValue()) {
            topItems.add(new GenericRecommendedItem(itemID, value));
            topItems.poll();
          }
        }
      }
    }
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

  @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

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.