Example usage for org.apache.mahout.cf.taste.hadoop.item VectorAndPrefsWritable VectorAndPrefsWritable

List of usage examples for org.apache.mahout.cf.taste.hadoop.item VectorAndPrefsWritable VectorAndPrefsWritable

Introduction

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

Prototype

public VectorAndPrefsWritable(Vector vector, List<Long> userIDs, List<Float> values) 

Source Link

Usage

From source file:com.skp.experiment.common.mapreduce.ToVectorAndPrefReducer.java

License:Apache License

@Override
protected void reduce(IntWritable key, Iterable<VectorOrPrefWritable> values, Context context)
        throws IOException, InterruptedException {

    List<Long> userIDs = Lists.newArrayList();
    List<Float> prefValues = Lists.newArrayList();
    Vector similarityMatrixColumn = null;
    for (VectorOrPrefWritable value : values) {
        if (value.getVector() == null) {
            // Then this is going into list
            userIDs.add(value.getUserID());
            prefValues.add(value.getValue());
        } else {/*from  w w  w.  j av  a2 s  . co  m*/
            // Then this is going into vector
            if (similarityMatrixColumn != null) {
                throw new IllegalStateException(" " + key.get());
            }
            similarityMatrixColumn = value.getVector();
        }
    }

    if (similarityMatrixColumn == null) {
        return;
    }

    VectorAndPrefsWritable vectorAndPrefs = new VectorAndPrefsWritable(similarityMatrixColumn, userIDs,
            prefValues);
    context.write(key, vectorAndPrefs);
}