}
public void reduce(Text key, Iterator<Text> values,
OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
// new scores estimated for the current node
TObjectDoubleHashMap newEstimatedScores = new TObjectDoubleHashMap();
// set to true only if the message sent to itself is found.
boolean isSelfMessageFound = false;
String vertexId = key.toString();
String vertexString = "";
TObjectDoubleHashMap neighbors = null;
TObjectDoubleHashMap randWalkProbs = null;
HashMap<String, String> neighScores =
new HashMap<String, String>();
int totalMessagesReceived = 0;
// iterate over all the messages received at the node
while (values.hasNext()) {
++totalMessagesReceived;
String val = values.next().toString();
String[] fields = val.split(_kDelim);
// System.out.println("src: " + fields[0] + " dest: " + vertexId +
// "MESSAGE>>" + val + "<<");
// self-message check
if (vertexId.equals(fields[0])) {
isSelfMessageFound = true;
vertexString = val;
// System.out.println("Reduce: " + vertexId + " " + val + " " + fields.length);
TObjectDoubleHashMap injLabels = CollectionUtil.String2Map(fields[2]);
neighbors = CollectionUtil.String2Map(neighbors, fields[4]);
randWalkProbs = CollectionUtil.String2Map(fields[5]);
if (injLabels.size() > 0) {
// add injected labels to the estimated scores.
ProbUtil.AddScores(newEstimatedScores,
mu1 * randWalkProbs.get(Constants._kInjProb),
injLabels);
}
} else {
// an empty second field represents that the
// neighbor has no valid label assignment yet.
if (fields.length > 1) {
neighScores.put(fields[0], fields[1]);
}
}
}
// terminate if message from self is not received.
if (!isSelfMessageFound) {
throw new RuntimeException("Self message not received for node " + vertexId);
}
// collect neighbors label distributions and create one single
// label distribution
TObjectDoubleHashMap weightedNeigLablDist = new TObjectDoubleHashMap();
Iterator<String> neighIter = neighScores.keySet().iterator();
while (neighIter.hasNext()) {
String neighName = neighIter.next();
ProbUtil.AddScores(weightedNeigLablDist, // newEstimatedScores,
mu2 * randWalkProbs.get(Constants._kContProb) * neighbors.get(neighName),