Last active
November 7, 2016 19:53
-
-
Save cgrand/10a1d9d15c8370eb739a to your computer and use it in GitHub Desktop.
This file contains 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
;; pagerank in podwerkeg | |
(reduce (fn [ranks _] | |
(keg/rdd (keg/join links ranks) | |
(x/for [[page-id [page-links rank]] % | |
dest page-links] | |
[dest (/ rank (count page-links))]) | |
(keg/by-key (x/reduce +) (map #(+ 0.15 (* 0.85 %)))))) | |
(keg/rdd links (keg/by-key (map (constantly 1)))) (range 10)) |
This file contains 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
// pagerank in scala | |
var ranks = links.mapValues(v => 1.0) | |
for (i <- 0 until 10) { | |
val contributions = links.join(ranks).flatMap { | |
case (pageId, (pageLinks, rank)) => | |
pageLinks.map(dest => (dest, rank / pageLinks.size)) | |
} | |
ranks = contributions.reduceByKey((x, y) => x + y).mapValues(v => 0.15 + 0.85*v) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment