1- CREATE QUERY tg_pagerank (STRING v_type, STRING e_type, FLOAT max_change=0.001, INT maximum_iteration=25, FLOAT damping=0.85, INT top_k = 100, BOOL print_results = TRUE, STRING result_attribute = "", STRING file_path = "", BOOL display_edges = FALSE) SYNTAX V1 {
1+ CREATE QUERY tg_pagerank (STRING v_type, STRING e_type, FLOAT max_change=0.001, INT maximum_iteration=25, FLOAT damping=0.85, INT top_k = 100, BOOL normalize=TRUE, BOOL print_results = TRUE, STRING result_attribute = "", STRING file_path = "", BOOL display_edges = FALSE) SYNTAX V1 {
22 /*
3- First Author: unk
4- First Commit Date: unk
3+ First Author: < unk>
4+ First Commit Date: < unk>
55
66 Recent Author: Rob Rossmiller
7- Recent Commit Date: Rob Rossmiller
7+ Recent Commit Date: Sept 4, 2024
88
99
1010 Repository:
@@ -41,7 +41,7 @@ CREATE QUERY tg_pagerank (STRING v_type, STRING e_type, FLOAT max_change=0.001,
4141 file_path:
4242 file to write CSV output to
4343 top_k:
44- # top scores to output
44+ // top scores to output
4545 display_edges:
4646 output edges for visualization
4747 max_change:
@@ -52,54 +52,66 @@ CREATE QUERY tg_pagerank (STRING v_type, STRING e_type, FLOAT max_change=0.001,
5252
5353 TYPEDEF TUPLE<VERTEX Vertex_ID, FLOAT score> Vertex_Score;
5454 HeapAccum<Vertex_Score>(top_k, score DESC) @@top_scores_heap;
55- SetAccum<VERTEX> @@top_vertices; # vertices with top score
56- MaxAccum<FLOAT> @@max_diff = 9999; # max score change in an iteration
57- SumAccum<FLOAT> @sum_recvd_score = 0; # sum of scores each vertex receives FROM neighbors
58- SumAccum<FLOAT> @sum_score = 1; # initial score for every vertex is 1.
59- SetAccum<EDGE> @@edge_set; # list of all edges, if display is needed
55+ SetAccum<VERTEX> @@top_vertices; // vertices with top score
56+ MaxAccum<FLOAT> @@max_diff = 9999; // max score change in an iteration
57+ SumAccum<FLOAT> @sum_recvd_score = 0; // sum of scores each vertex receives FROM neighbors
58+ SumAccum<FLOAT> @sum_score = 1; // initial score for every vertex is 1.
59+ SetAccum<EDGE> @@edge_set; // list of all edges, if display is needed
6060 FILE f (file_path);
61+ INT N=1;
62+
63+
64+ // PageRank iterations
65+ Start = {v_type}; // Start with all vertices of specified type(s)
66+ IF normalize THEN
67+ N = Start.size();
68+ tmp = SELECT s FROM Start:s
69+ ACCUM s.@sum_score = 1.0/N;
70+ END;
6171
62- # PageRank iterations
63- Start = {v_type}; # Start with all vertices of specified type(s)
6472 WHILE @@max_diff > max_change LIMIT maximum_iteration DO
6573 @@max_diff = 0;
74+
6675 V = SELECT s FROM Start:s -(e_type:e)- v_type:t
67- ACCUM
68- t.@sum_recvd_score += s.@sum_score/(s.outdegree(e_type))
76+ ACCUM t.@sum_recvd_score += s.@sum_score/(s.outdegree(e_type))
6977 POST-ACCUM
70- s.@sum_score = (1.0 - damping) + damping * s.@sum_recvd_score,
78+ s.@sum_score = (1.0- damping)/N + damping * s.@sum_recvd_score,
7179 s.@sum_recvd_score = 0,
7280 @@max_diff += abs(s.@sum_score - s.@sum_score');
73- END; # END WHILE loop
81+ END;
7482
75- # Output
83+ // Output
7684 IF file_path != "" THEN
7785 f.println("Vertex_ID", "PageRank");
7886 END;
87+
7988 V = SELECT s FROM Start:s
80- POST-ACCUM
89+ POST-ACCUM
8190 IF result_attribute != "" THEN
8291 s.setAttr(result_attribute, s.@sum_score)
8392 END,
93+
8494 IF file_path != "" THEN
8595 f.println(s, s.@sum_score)
8696 END,
87-
97+
8898 IF print_results THEN
8999 @@top_scores_heap += Vertex_Score(s, s.@sum_score)
90100 END;
91101
92102 IF print_results THEN
93103 PRINT @@top_scores_heap;
94104 IF display_edges THEN
105+
95106 FOREACH vert IN @@top_scores_heap DO
96107 @@top_vertices += vert.Vertex_ID;
97108 END;
98109
99110 Top = {@@top_vertices};
100- Top = SELECT s FROM Top:s -(e_type:e)- v_type:t
101- WHERE @@top_vertices.contains(t)
102- ACCUM @@edge_set += e;
111+ Top = SELECT s
112+ FROM Top:s -(e_type:e)- v_type:t
113+ WHERE @@top_vertices.contains(t)
114+ ACCUM @@edge_set += e;
103115
104116 PRINT @@edge_set;
105117 PRINT Top;
0 commit comments