Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create PageRank #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions PageRank
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import networkx as nx
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import operator
import random as rd
graph=nx.gnp_random_graph(25,0.6,directed= True)
nx.draw(graph,with_labels=True,font_color='red',font_size=10,node_color='yellow')
plt.show()
count=graph.number_of_nodes()
print(list(graph.neighbors(1)))

rank_dict={}
x = rd.randint(0,25)
for j in range(0,25):
rank_dict[j] = 0
rank_dict[x]=rank_dict[x]+1
for i in range(600000):
list_n=list(graph.neighbors(x))
if(len(list_n)==0):
x=rd.randint(0,25)
rank_dict[x]=rank_dict[x]+1
else:
x=rd.choice(list_n)
rank_dict[x]=rank_dict[x]+1

print("Random Walk Score Updated")
for j in range(0,25):
rank_dict[j]=rank_dict[j]/600000
pagerank = nx.pagerank(graph)

pagerank_sorted = sorted(pagerank.items(),key = lambda v: (v[1], v[0]), reverse = True)
pagerank_sorted

rank_dict_sorted = sorted(rank_dict.items(), key = lambda v: (v[1], v[0]), reverse = True)
rank_dict_sorted

print("The order generated by our implementation algorithm is\n")
for i in rank_dict_sorted:
print(i[0],end=" ")
print("\n\nThe order generated by networkx library is\n")
for i in pagerank_sorted:
print(i[0],end=" ")