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 {
2
2
/*
3
- First Author: unk
4
- First Commit Date: unk
3
+ First Author: < unk>
4
+ First Commit Date: < unk>
5
5
6
6
Recent Author: Rob Rossmiller
7
- Recent Commit Date: Rob Rossmiller
7
+ Recent Commit Date: Sept 4, 2024
8
8
9
9
10
10
Repository:
@@ -41,7 +41,7 @@ CREATE QUERY tg_pagerank (STRING v_type, STRING e_type, FLOAT max_change=0.001,
41
41
file_path:
42
42
file to write CSV output to
43
43
top_k:
44
- # top scores to output
44
+ // top scores to output
45
45
display_edges:
46
46
output edges for visualization
47
47
max_change:
@@ -52,54 +52,66 @@ CREATE QUERY tg_pagerank (STRING v_type, STRING e_type, FLOAT max_change=0.001,
52
52
53
53
TYPEDEF TUPLE<VERTEX Vertex_ID, FLOAT score> Vertex_Score;
54
54
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
60
60
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;
61
71
62
- # PageRank iterations
63
- Start = {v_type}; # Start with all vertices of specified type(s)
64
72
WHILE @@max_diff > max_change LIMIT maximum_iteration DO
65
73
@@max_diff = 0;
74
+
66
75
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))
69
77
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,
71
79
s.@sum_recvd_score = 0,
72
80
@@max_diff += abs(s.@sum_score - s.@sum_score');
73
- END; # END WHILE loop
81
+ END;
74
82
75
- # Output
83
+ // Output
76
84
IF file_path != "" THEN
77
85
f.println("Vertex_ID", "PageRank");
78
86
END;
87
+
79
88
V = SELECT s FROM Start:s
80
- POST-ACCUM
89
+ POST-ACCUM
81
90
IF result_attribute != "" THEN
82
91
s.setAttr(result_attribute, s.@sum_score)
83
92
END,
93
+
84
94
IF file_path != "" THEN
85
95
f.println(s, s.@sum_score)
86
96
END,
87
-
97
+
88
98
IF print_results THEN
89
99
@@top_scores_heap += Vertex_Score(s, s.@sum_score)
90
100
END;
91
101
92
102
IF print_results THEN
93
103
PRINT @@top_scores_heap;
94
104
IF display_edges THEN
105
+
95
106
FOREACH vert IN @@top_scores_heap DO
96
107
@@top_vertices += vert.Vertex_ID;
97
108
END;
98
109
99
110
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;
103
115
104
116
PRINT @@edge_set;
105
117
PRINT Top;
0 commit comments