Package ml.shifu.guagua.example.kmeans
Class KMeansWorker
- java.lang.Object
-
- ml.shifu.guagua.worker.AbstractWorkerComputable<KMeansMasterParams,KMeansWorkerParams,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.LongWritable>,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.Text>>
-
- ml.shifu.guagua.example.kmeans.KMeansWorker
-
- All Implemented Interfaces:
ml.shifu.guagua.worker.WorkerComputable<KMeansMasterParams,KMeansWorkerParams>
public class KMeansWorker extends ml.shifu.guagua.worker.AbstractWorkerComputable<KMeansMasterParams,KMeansWorkerParams,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.LongWritable>,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.Text>>
KMeansWorkerre-computes each record tagged with new category.To calculate new k centers in master,
KMeansWorkeralso help to accumulate worker info for new k centers by using sum list and count list.
-
-
Constructor Summary
Constructors Constructor Description KMeansWorker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KMeansWorkerParamsdoCompute(ml.shifu.guagua.worker.WorkerContext<KMeansMasterParams,KMeansWorkerParams> context)Using the new k centers to tag each record with index denoting the record belongs to which category.voidinit(ml.shifu.guagua.worker.WorkerContext<KMeansMasterParams,KMeansWorkerParams> context)voidinitRecordReader(ml.shifu.guagua.io.GuaguaFileSplit fileSplit)Reading input line by linevoidload(ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.LongWritable> currentKey, ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.Text> currentValue, ml.shifu.guagua.worker.WorkerContext<KMeansMasterParams,KMeansWorkerParams> workerContext)Loading data into memory.protected voidpostLoad(ml.shifu.guagua.worker.WorkerContext<KMeansMasterParams,KMeansWorkerParams> context)
-
-
-
Method Detail
-
initRecordReader
public void initRecordReader(ml.shifu.guagua.io.GuaguaFileSplit fileSplit) throws IOExceptionReading input line by line- Specified by:
initRecordReaderin classml.shifu.guagua.worker.AbstractWorkerComputable<KMeansMasterParams,KMeansWorkerParams,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.LongWritable>,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.Text>>- Throws:
IOException
-
init
public void init(ml.shifu.guagua.worker.WorkerContext<KMeansMasterParams,KMeansWorkerParams> context)
- Specified by:
initin classml.shifu.guagua.worker.AbstractWorkerComputable<KMeansMasterParams,KMeansWorkerParams,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.LongWritable>,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.Text>>
-
doCompute
public KMeansWorkerParams doCompute(ml.shifu.guagua.worker.WorkerContext<KMeansMasterParams,KMeansWorkerParams> context)
Using the new k centers to tag each record with index denoting the record belongs to which category.- Specified by:
doComputein classml.shifu.guagua.worker.AbstractWorkerComputable<KMeansMasterParams,KMeansWorkerParams,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.LongWritable>,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.Text>>
-
postLoad
protected void postLoad(ml.shifu.guagua.worker.WorkerContext<KMeansMasterParams,KMeansWorkerParams> context)
- Overrides:
postLoadin classml.shifu.guagua.worker.AbstractWorkerComputable<KMeansMasterParams,KMeansWorkerParams,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.LongWritable>,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.Text>>
-
load
public void load(ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.LongWritable> currentKey, ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.Text> currentValue, ml.shifu.guagua.worker.WorkerContext<KMeansMasterParams,KMeansWorkerParams> workerContext)Loading data into memory. any invalid data will be set to null.- Specified by:
loadin classml.shifu.guagua.worker.AbstractWorkerComputable<KMeansMasterParams,KMeansWorkerParams,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.LongWritable>,ml.shifu.guagua.hadoop.io.GuaguaWritableAdapter<org.apache.hadoop.io.Text>>
-
-