public void outputPointWithClusterInfo(Vector vector,
Iterable<Cluster> clusters,
Mapper<?,?,IntWritable,WeightedPropertyVectorWritable>.Context context)
throws IOException, InterruptedException {
AbstractCluster nearestCluster = null;
double nearestDistance = Double.MAX_VALUE;
for (AbstractCluster cluster : clusters) {
Vector clusterCenter = cluster.getCenter();
double distance = measure.distance(clusterCenter.getLengthSquared(), clusterCenter, vector);
if (distance < nearestDistance || nearestCluster == null) {
nearestCluster = cluster;
nearestDistance = distance;
}
}
Map<Text, Text> props = new HashMap<Text, Text>();
props.put(new Text("distance"), new Text(String.valueOf(nearestDistance)));
context.write(new IntWritable(nearestCluster.getId()), new WeightedPropertyVectorWritable(1, vector, props));
}