From 80ffe0fac91726006d16b48d1678f622c9e8a802 Mon Sep 17 00:00:00 2001 From: Rob Rossmiller Date: Fri, 30 Aug 2024 10:34:02 -0400 Subject: [PATCH] fmt --- .../global/unweighted/tg_pagerank.gsql | 104 +++++++++--------- .../baseline/centrality/pagerank/Tree.json | 2 +- tests/test/test_centrality.py | 1 + 3 files changed, 51 insertions(+), 56 deletions(-) diff --git a/algorithms/Centrality/pagerank/global/unweighted/tg_pagerank.gsql b/algorithms/Centrality/pagerank/global/unweighted/tg_pagerank.gsql index d4a29f96..88a4df6b 100644 --- a/algorithms/Centrality/pagerank/global/unweighted/tg_pagerank.gsql +++ b/algorithms/Centrality/pagerank/global/unweighted/tg_pagerank.gsql @@ -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_Score; -HeapAccum(top_k, score DESC) @@top_scores_heap; -SetAccum @@top_vertices; # vertices with top score -MaxAccum @@max_diff = 9999; # max score change in an iteration -SumAccum @sum_recvd_score = 0; # sum of scores each vertex receives FROM neighbors -SumAccum @sum_score = 1; # initial score for every vertex is 1. -SetAccum @@edge_set; # list of all edges, if display is needed -FILE f (file_path); + TYPEDEF TUPLE Vertex_Score; + HeapAccum(top_k, score DESC) @@top_scores_heap; + SetAccum @@top_vertices; # vertices with top score + MaxAccum @@max_diff = 9999; # max score change in an iteration + SumAccum @sum_recvd_score = 0; # sum of scores each vertex receives FROM neighbors + SumAccum @sum_score = 1; # initial score for every vertex is 1. + SetAccum @@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; } diff --git a/tests/data/baseline/centrality/pagerank/Tree.json b/tests/data/baseline/centrality/pagerank/Tree.json index b49c40c9..39d09eec 100644 --- a/tests/data/baseline/centrality/pagerank/Tree.json +++ b/tests/data/baseline/centrality/pagerank/Tree.json @@ -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}]}] \ No newline at end of file +[{"@@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}]}] \ No newline at end of file diff --git a/tests/test/test_centrality.py b/tests/test/test_centrality.py index d77179cd..ed6159f8 100644 --- a/tests/test/test_centrality.py +++ b/tests/test/test_centrality.py @@ -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