Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright [2013-2014] eBay Software Foundation
   *  
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *  
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package ml.shifu.guagua.mapreduce.example.kmeans;
 
 import java.util.List;
 
KMeansMasterParams is the master results for KMeans distributed guagua application.

Master result for each iteration is the new k center points after accumulating from all workers' result.

 
 public class KMeansMasterParams extends HaltBytable {

    
K category pre-defined
 
     private int k;

    
How many dimensions used for each record.
 
     private int c;

    
For the first iteration, this is the k initial centroids selected. For other iterations, this is the new centriods after worker iteration.
 
     private List<double[]> pointList;
 
     @Override
     public void doWrite(DataOutput outthrows IOException {
         validate();
         out.writeInt(this.);
         out.writeInt(this.);
         for(int i = 0; i < this.i++) {
             for(int j = 0; j < this.j++) {
                 out.writeDouble(this..get(i)[j]);
             }
         }
     }
 
     private void validate() {
         validateK();
         validateC();
 
         if(this. != this..size()) {
             throw new IllegalArgumentException("In-consistent sum list.");
         }
     }
 
     @Override
     public void doReadFields(DataInput inthrows IOException {
         this. = in.readInt();
         validateK();
         this. = in.readInt();
         validateC();
         this. = new LinkedList<double[]>();
         for(int i = 0; i < this.i++) {
             double[] units = new double[this.];
             for(int j = 0; j < this.j++) {
                 units[j] = in.readDouble();
             }
             this..add(units);
         }
     }
 
     private void validateK() {
         if(this. <= 0) {
             throw new IllegalArgumentException("'k' should be a positive number.");
         }
     }
 
     private void validateC() {
         if(this. <= 0) {
             throw new IllegalArgumentException("'c' (cloumn number) should be a positive number.");
         }
     }
 
     public int getK() {
        return ;
    }
    public void setK(int k) {
        this. = k;
    }
    public int getC() {
        return ;
    }
    public void setC(int c) {
        this. = c;
    }
    public List<double[]> getPointList() {
        return ;
    }
    public void setPointList(List<double[]> pointList) {
        this. = pointList;
    }
New to GrepCode? Check out our FAQ X