标签:xtend mapper map mapred 一个 span mat except for
<strong><span style="font-size:18px;">/*** * @author YangXin * @info K-Means算法会对向量元素进行多次顺序的遍历,上次表示最适合于这样的訪问模式。 * 利用Mapper输出的部分向量。Reducer通过简单的拼接得到一个完整的向量。*/ package unitTwelve; import java.io.IOException; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import org.apache.mahout.math.NamedVector; import org.apache.mahout.math.Vector; import org.apache.mahout.math.VectorWritable; public class VectorReducer extends Reducer<Text, VectorWritable, Text, VectorWritable>{ private VectorWritable writer = new VectorWritable(); protected void reduce(Text tag, Iterable<VectorWritable> values, Context context) throws IOException, InterruptedException{ Vector vector = null; for(VectorWritable partialVector : values){ if(vector == null){ vector = partialVector.get().like(); } partialVector.get().addTo(vector); } NamedVector namedVector = new NamedVector(vector, tag.toString()); writer.set(namedVector); context.write(tag, writer); } } </span></strong>
标签:xtend mapper map mapred 一个 span mat except for
原文地址:http://www.cnblogs.com/jhcelue/p/7136553.html