Skip to content

Instantly share code, notes, and snippets.

@FrancescaK
Created September 3, 2013 14:37
Show Gist options
  • Save FrancescaK/6424823 to your computer and use it in GitHub Desktop.
Save FrancescaK/6424823 to your computer and use it in GitHub Desktop.
The reduce function looks like this: The reduce function has two duties: 1. Collect the `prs` and `prevpg` information for each node; 2. Accumulate the total PageRank score sent to each node.
var reduce = function(airportId, values) {
var pg = 0
, diff = 0
, prs = {}
, prevpg = 0
, beta = 0.9
, totalNodes = 0;
for (var i in values) {
// Retrieve the previous pagerank and the probability matrix
prevPRS = values[i]["prs"]
for (var key in prevPRS) {
prs[key] = prevPRS[key];
}
prevpg += values[i]["prevpg"];
// Summation of the pagerank
pg += values[i]["pg"];
totalNodes += values[i]["totalNodes"];
}
diff = Math.abs(prevpg - pg) / prevpg;
return {"totalNodes" : totalNodes
, "pg" : pg
, "prs" : prs
, "diff" : diff
, "prevpg" : prevpg};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment