Chat with us, powered by LiveChat paste your code here, | Writedemy

paste your code here,

paste your code here,

The current program only run one iteration of the KMeans algorithm. Please revise it (in the main function) to implement iterative processing, paste your code here, and briefly describe how it works. Were you able to successfully compile and run your program (yes/no)?

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class KMeans {

public static class KMMapper
extends Mapper<Object, Text, IntWritable, Text>{

private double [][] _centroids;
private IntWritable cid = new IntWritable();

public void setup(Mapper.Context context){
Configuration conf = context.getConfiguration();
String filename = conf.get(“Centroids-file”);
_centroids = loadCentroids(filename, conf);
}

public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
double [] vec = parseVector(value.toString());
cid.set(closest(vec));
context.write(cid, value);
}

private int closest(double [] v){
double mindist = dist(v, _centroids[0]);
int label =0;
for (int i=1; i<_centroids.length; i++){
double t = dist(v, _centroids[i]);
if (mindist>t){
mindist = t;
label = i;
}
}
return label;
}

}

public static class KMReducer
extends Reducer<IntWritable, Text, IntWritable, Text> {
// write output: cid \t centroid_vector
private Text result = new Text();

public void reduce(IntWritable key, Iterable<Text> vectors,
Context context
) throws IOException, InterruptedException {
double [] sum = null;
int n=0;
for (Text vec : vectors) {
double [] v = parseVector(vec.toString());
if (sum == null) sum = v;
else
for (int i = 0; i < v.length; i++)
sum[i] += v[i];
n ++;
}
String out = Double.toString(sum[0]/n);
for (int i = 1; i < sum.length; i ++ ){
out +=  “,” + Double.toString(sum[i]/n); // csv output
}
result.set(out);
context.write(key, result);
}

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order