Created
September 3, 2013 14:34
-
-
Save FrancescaK/6424772 to your computer and use it in GitHub Desktop.
Next, we wrote some JavaScript code to calculate PageRank on the graph stored in the database. The goal was to create a new collection `fpg_i` for every *i*th iteration of PageRank. Every iteration is a call on oneiteration() in [iteration.js](https://github.com/10gen-interns/big-data-exploration/blob/master/PageRank-Flights/src/iteration.js) co…
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 map = function() { | |
// For each node that is reachable from this node, give it the | |
// appropriate portion of my pagerank | |
for (var toNode in this["value"]["prs"]) { | |
emit(toNode, {totalNodes : 0.0 | |
, pg : this["value"]["prs"][toNode] * this["value"]["pg"] | |
, prs : {} | |
, diff : 0.0 | |
, prevpg : 0.0}); | |
} | |
// Pass the previous pagerank and the probability matrix to myself | |
emit(this["_id"], {totalNodes: this["value"]["totalNodes"] | |
, pg: 0.0 | |
, prs: this["value"]["prs"] | |
, diff: 0.0 | |
, prevpg: this["value"]["pg"]}); | |
// Reduce won't be called on a key unless there's more than one value for that key | |
// So this is just an extra emit to make sure that reduce is called | |
emit(this["_id"], {totalNodes: 0.0 | |
, pg : 0.0 | |
, prs : {} | |
, diff : 0.0 | |
, prevpg : 0.0}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment