-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.py
57 lines (40 loc) · 1.37 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from graphs import getGraph
from PageRank import PageRank
from TrustRank import TrustRank
def run(edge_file, node_num, beta=0.85, epsilon=1e-6, max_iterations=20):
"""Calls various ranking functions and print the rank_vectors.
Parameters
----------
edge_file : string
Path to the file where edges of web-graph are stored.
node_num : int
Number of nodes in the web-graph.
beta : float, optional
Probability with which teleports will occur.
Default value : 0.85
epsilon : float, optional
A small value and total error in ranks should be less than epsilon.
Default value : 1e-6
max_iterations : int, optional
Maximum number of times to apply power iteration.
Default value : 20
Returns
-------
None
"""
gg = getGraph(edge_file)
edges = gg.get_connections()
print("got edges...")
pr = PageRank(beta, edges, epsilon, max_iterations, node_num)
PageRank_vector = pr.pageRank()
print(PageRank_vector, sum(PageRank_vector))
tr = TrustRank(beta, edges, epsilon, max_iterations, node_num,
PageRank_vector)
TrustRank_vector = tr.trustRank()
print(TrustRank_vector, sum(TrustRank_vector))
if __name__ == '__main__':
location_of_the_edge_file = "./data/test"
number_of_nodes_in_web_graph = 9
# location_of_the_edge_file = "./data/WikiTalk.data"
# number_of_nodes_in_web_graph = 2394385
run(location_of_the_edge_file, number_of_nodes_in_web_graph)