Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rrossmiller committed Aug 30, 2024
1 parent 15cf6dc commit 80ffe0f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 56 deletions.
104 changes: 49 additions & 55 deletions algorithms/Centrality/pagerank/global/unweighted/tg_pagerank.gsql
Original file line number Diff line number Diff line change
Expand Up @@ -50,65 +50,59 @@ CREATE QUERY tg_pagerank (STRING v_type, STRING e_type, FLOAT max_change=0.001,
importance of traversal vs. random teleport
*/

TYPEDEF TUPLE<VERTEX Vertex_ID, FLOAT score> Vertex_Score;
HeapAccum<Vertex_Score>(top_k, score DESC) @@top_scores_heap;
SetAccum<VERTEX> @@top_vertices; # vertices with top score
MaxAccum<FLOAT> @@max_diff = 9999; # max score change in an iteration
SumAccum<FLOAT> @sum_recvd_score = 0; # sum of scores each vertex receives FROM neighbors
SumAccum<FLOAT> @sum_score = 1; # initial score for every vertex is 1.
SetAccum<EDGE> @@edge_set; # list of all edges, if display is needed
FILE f (file_path);
TYPEDEF TUPLE<VERTEX Vertex_ID, FLOAT score> Vertex_Score;
HeapAccum<Vertex_Score>(top_k, score DESC) @@top_scores_heap;
SetAccum<VERTEX> @@top_vertices; # vertices with top score
MaxAccum<FLOAT> @@max_diff = 9999; # max score change in an iteration
SumAccum<FLOAT> @sum_recvd_score = 0; # sum of scores each vertex receives FROM neighbors
SumAccum<FLOAT> @sum_score = 1; # initial score for every vertex is 1.
SetAccum<EDGE> @@edge_set; # list of all edges, if display is needed
FILE f (file_path);

# PageRank iterations
Start = {v_type}; # Start with all vertices of specified type(s)
WHILE @@max_diff > max_change
LIMIT maximum_iteration DO
# PageRank iterations
Start = {v_type}; # Start with all vertices of specified type(s)
WHILE @@max_diff > max_change LIMIT maximum_iteration DO
@@max_diff = 0;
V = SELECT s
FROM Start:s -(e_type:e)- v_type:t
ACCUM
t.@sum_recvd_score += s.@sum_score/(s.outdegree(e_type))
POST-ACCUM
s.@sum_score = (1.0-damping) + damping * s.@sum_recvd_score,
s.@sum_recvd_score = 0,
@@max_diff += abs(s.@sum_score - s.@sum_score');
END; # END WHILE loop
V = SELECT s FROM Start:s -(e_type:e)- v_type:t
ACCUM
t.@sum_recvd_score += s.@sum_score/(s.outdegree(e_type))
POST-ACCUM
s.@sum_score = (1.0 - damping) + damping * s.@sum_recvd_score,
s.@sum_recvd_score = 0,
@@max_diff += abs(s.@sum_score - s.@sum_score');
END; # END WHILE loop

# Output
IF file_path != "" THEN
f.println("Vertex_ID", "PageRank");
END;
V = SELECT s
FROM Start:s
POST-ACCUM
IF result_attribute != "" THEN
s.setAttr(result_attribute, s.@sum_score)
END,

IF file_path != "" THEN
f.println(s, s.@sum_score)
END,

IF print_results THEN
@@top_scores_heap += Vertex_Score(s, s.@sum_score)
END;
# Output
IF file_path != "" THEN
f.println("Vertex_ID", "PageRank");
END;
V = SELECT s FROM Start:s
POST-ACCUM
IF result_attribute != "" THEN
s.setAttr(result_attribute, s.@sum_score)
END,
IF file_path != "" THEN
f.println(s, s.@sum_score)
END,

IF print_results THEN
@@top_scores_heap += Vertex_Score(s, s.@sum_score)
END;

IF print_results THEN
PRINT @@top_scores_heap;
IF display_edges THEN

FOREACH vert IN @@top_scores_heap DO
@@top_vertices += vert.Vertex_ID;
IF print_results THEN
PRINT @@top_scores_heap;
IF display_edges THEN
FOREACH vert IN @@top_scores_heap DO
@@top_vertices += vert.Vertex_ID;
END;

Top = {@@top_vertices};
Top = SELECT s FROM Top:s -(e_type:e)- v_type:t
WHERE @@top_vertices.contains(t)
ACCUM @@edge_set += e;

PRINT @@edge_set;
PRINT Top;
END;

Top = {@@top_vertices};
Top = SELECT s
FROM Top:s -(e_type:e)- v_type:t
WHERE @@top_vertices.contains(t)
ACCUM @@edge_set += e;

PRINT @@edge_set;
PRINT Top;
END;
END;
}
2 changes: 1 addition & 1 deletion tests/data/baseline/centrality/pagerank/Tree.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"@@top_scores_heap": [{"Vertex_ID": "A", "score": 0.04753738488500107}, {"Vertex_ID": "B", "score": 0.06909959193353465}, {"Vertex_ID": "C", "score": 0.07220759154455525}, {"Vertex_ID": "D", "score": 0.07130204500748626}, {"Vertex_ID": "E", "score": 0.07480080379154676}, {"Vertex_ID": "F", "score": 0.0785393029006319}, {"Vertex_ID": "G", "score": 0.0785393029006319}, {"Vertex_ID": "H", "score": 0.07804404762676867}, {"Vertex_ID": "I", "score": 0.07804404762676867}, {"Vertex_ID": "J", "score": 0.054902205374844214}, {"Vertex_ID": "K", "score": 0.02869374578323252}, {"Vertex_ID": "L", "score": 0.02975219252757403}, {"Vertex_ID": "M", "score": 0.02975219252757403}, {"Vertex_ID": "N", "score": 0.02975219252757403}, {"Vertex_ID": "O", "score": 0.02975219252757403}, {"Vertex_ID": "P", "score": 0.02961198234571507}, {"Vertex_ID": "Q", "score": 0.02961198234571507}, {"Vertex_ID": "R", "score": 0.02961198234571507}, {"Vertex_ID": "S", "score": 0.02961198234571507}, {"Vertex_ID": "T", "score": 0.030833231131841908}]}]
[{"@@top_scores_heap": [{"Vertex_ID": "A", "score": 0.04753738488500107}, {"Vertex_ID": "B", "score": 0.06909959193353464}, {"Vertex_ID": "C", "score": 0.07220759154455524}, {"Vertex_ID": "D", "score": 0.07130204500748627}, {"Vertex_ID": "E", "score": 0.07480080379154676}, {"Vertex_ID": "F", "score": 0.0785393029006319}, {"Vertex_ID": "G", "score": 0.0785393029006319}, {"Vertex_ID": "H", "score": 0.07804404762676867}, {"Vertex_ID": "I", "score": 0.07804404762676867}, {"Vertex_ID": "J", "score": 0.054902205374844214}, {"Vertex_ID": "K", "score": 0.02869374578323252}, {"Vertex_ID": "L", "score": 0.02975219252757403}, {"Vertex_ID": "M", "score": 0.02975219252757403}, {"Vertex_ID": "N", "score": 0.02975219252757403}, {"Vertex_ID": "O", "score": 0.02975219252757403}, {"Vertex_ID": "P", "score": 0.029611982345715077}, {"Vertex_ID": "Q", "score": 0.029611982345715077}, {"Vertex_ID": "R", "score": 0.029611982345715077}, {"Vertex_ID": "S", "score": 0.029611982345715077}, {"Vertex_ID": "T", "score": 0.030833231131841908}]}]
1 change: 1 addition & 0 deletions tests/test/test_centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,4 @@ def test_pagerank(self, test_name):
"tg_pagerank", params=params, templateQuery=template_flag
)
self.check_result(baseline, result, template_flag, key="@@top_scores_heap")
break

0 comments on commit 80ffe0f

Please sign in to comment.