Example usage for org.apache.mahout.cf.taste.hadoop MutableRecommendedItem getValue

List of usage examples for org.apache.mahout.cf.taste.hadoop MutableRecommendedItem getValue

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.hadoop MutableRecommendedItem getValue.

Prototype

@Override
    public float getValue() 

Source Link

Usage

From source file:hadoop.api.AggregateAndRecommendReducer.java

License:Apache License

/**
 * find the top entries in recommendationVector, map them to the real itemIDs and write back the result
 *//*w  w w . ja v  a 2s  . c o  m*/
private void writeRecommendedItems(VarLongWritable userID, Vector recommendationVector, Context context)
        throws IOException, InterruptedException {

    TopItemsQueue topKItems = new TopItemsQueue(recommendationsPerUser);

    for (Element element : recommendationVector.nonZeroes()) {
        int index = element.index();
        long itemID;
        if (indexItemIDMap != null && !indexItemIDMap.isEmpty()) {
            itemID = indexItemIDMap.get(index);
        } else { //we don't have any mappings, so just use the original
            itemID = index;
        }
        if (itemsToRecommendFor == null || itemsToRecommendFor.contains(itemID)) {
            float value = (float) element.get();
            if (!Float.isNaN(value)) {

                MutableRecommendedItem topItem = topKItems.top();
                if (value > topItem.getValue()) {
                    topItem.set(itemID, value);
                    topKItems.updateTop();
                }
            }
        }
    }

    List<RecommendedItem> topItems = topKItems.getTopItems();
    if (!topItems.isEmpty()) {
        recommendedItems.set(topItems);
        context.write(userID, recommendedItems);
    }
}