Skip to content

Commit

Permalink
fixed the bug of pagerank example
Browse files Browse the repository at this point in the history
  • Loading branch information
f422661 committed May 15, 2019
1 parent 177b40f commit 0651306
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/src/main/python/pagerank.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ def parseNeighbors(urls):

# Count the number of all URLs
num_vals = ranks.count()

# Calculates and updates URL ranks continuously using PageRank algorithm.
for iteration in range(int(sys.argv[2])):
# Calculates URL contributions to the rank of other URLs.
contribs = links.join(ranks).flatMap(
lambda url_urls_rank: computeContribs(url_urls_rank[1][0], url_urls_rank[1][1]))

# Re-calculates URL ranks based on neighbor contributions.
ranks = contribs.reduceByKey(add).mapValues(lambda rank: rank * 0.85 + (1 / num_vals) * 0.15)
ranks = contribs.reduceByKey(add).mapValues(
lambda rank: rank * 0.85 + (1 / num_vals) * 0.15)

# Collects all URL ranks and dump them to console.
for (link, rank) in ranks.collect():
Expand Down

0 comments on commit 0651306

Please sign in to comment.