Mahout Series: Minhash cluster

Source: Internet
Author: User
Tags hash
 map:vector featurevector = Features.get ();
    if (Featurevector.size () < minvectorsize) {return; }//Initialize the Minhash values to highest for (int i = 0; i < numhashfunctions; i++) {minhashvalues[
    I] = Integer.max_value;
        for (int i = 0; i < numhashfunctions i++) {for (vector.element ele:featureVector.nonZeroes ()) { int value = HashValue?
        (int) Ele.get (): Ele.index ();
        Bytestohash[0] = (byte) (value >> 24);
        BYTESTOHASH[1] = (byte) (value >> 16);
        BYTESTOHASH[2] = (byte) (value >> 8);
        BYTESTOHASH[3] = (byte) value;
        int hashindex = Hashfunction[i].hash (Bytestohash);
          If we are new hash value is less than the "old one," replace the old one if (Minhashvalues[i] > Hashindex) {
        Minhashvalues[i] = Hashindex; }}//output the cluster information for (int i = 0; i < numhashfunctions; i++) {StRingbuilder Clusteridbuilder = new StringBuilder (); for (int j = 0; J < keygroups J + +) {clusteridbuilder.append (minhashvalues[(i + j)% numhashfunctions]). Append
      ('-');
    
      }//remove the last dash Clusteridbuilder.deletecharat (Clusteridbuilder.length ()-1);
    
      Cluster.set (Clusteridbuilder.tostring ());
        if (debugoutput) {vector.set (featurevector);
      Context.write (cluster, vector);
      else {context.write (cluster, item); }
    }
protected void reduce (Text cluster, iterable<writable> points, context context)
   throws IOException, interruptedexception {
   collection<writable> pointlist = Lists.newarraylist ();
   for (writable point:points) {
     if (debugoutput) {
       Vector pointvector = ((vectorwritable) point). Get (). Clone (); 
  writable writablepointvector = new vectorwritable (pointvector);
       Pointlist.add (Writablepointvector);
     } else {
       writable pointtext = new Text (point.tostring ());
       Pointlist.add (Pointtext);
     }
   if (Pointlist.size () >= minclustersize) {
     context.getcounter (clusters.accepted). Increment (1);
     for (writable point:pointlist) {
       context.write (cluster, point);
     }
   } else {
     context.getcounter ( clusters.discarded). Increment (1);
   }
 }

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.