@Override
protected void reduce(ClusterCenter key, Iterable<VectorWritable> values,
Context context) throws IOException, InterruptedException {
List<VectorWritable> vectorList = new ArrayList<>();
DoubleVector newCenter = null;
for (VectorWritable value : values) {
vectorList.add(new VectorWritable(value));
if (newCenter == null)
newCenter = value.getVector().deepCopy();
else
newCenter = newCenter.add(value.getVector());
}
newCenter = newCenter.divide(vectorList.size());
ClusterCenter center = new ClusterCenter(newCenter);
centers.add(center);
for (VectorWritable vector : vectorList) {
context.write(center, vector);
}