Combine part of a label vector and accumulate it into a full vector

Source: Internet
Author: User

<strong><span style= "FONT-SIZE:18PX;" >/*** * @author yangxin * @info the K-means algorithm iterates through the vector elements in multiple sequential order, and the last representation is best for this access pattern. * Using the partial vector of the mapper output, the reducer obtains a complete vector through simple stitching. */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>

Combine part of a label vector and accumulate it into a full vector

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.