Skip to content

Instantly share code, notes, and snippets.

@cgrand
Last active November 7, 2016 19:53
Show Gist options
  • Save cgrand/10a1d9d15c8370eb739a to your computer and use it in GitHub Desktop.
Save cgrand/10a1d9d15c8370eb739a to your computer and use it in GitHub Desktop.
;; 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))
// 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