Created
September 3, 2013 14:37
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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