@Override public void reduce(Text key, Iterable<DoublePair> values, Context context) throws IOException, InterruptedException { // YOUR CODE HERE // Add DoublePair values(distance, ocurrences) for the document, before return map to the // master Double total_distance = new Double(0.0); Double total_ocu = new Double(0.0); for (DoublePair value : values) { total_distance += new Double(value.getDouble1()); total_ocu += new Double(value.getDouble2()); } context.write(key, new DoublePair(total_distance, total_ocu)); } // end combine1
@Override public void reduce(Text key, Iterable<DoublePair> values, Context context) throws IOException, InterruptedException { // YOUR CODE HERE // Add DoublePair values(distance, ocurrences) for the whole corpus Double total_distance = new Double(0.0); Double total_ocu = new Double(0.0); for (DoublePair value : values) { total_distance += value.getDouble1(); total_ocu += value.getDouble2(); } // Calculate occurrence rate Double result = new Double(0.0); if (total_distance != 0) result = ((total_distance * Math.pow(Math.log(total_distance), 3)) / total_ocu) * -1; context.write(new DoubleWritable(result), key); }