Skip to content

Commit 356c36f

Browse files
Merge pull request #149 from tigergraph/degree-cent
Degree cent
2 parents ce724c0 + 090362c commit 356c36f

File tree

187 files changed

+428
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+428
-190
lines changed

GDBMS_ALGO/centrality/degree_cent.gsql

+50-48
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,72 @@
11
CREATE TEMPLATE QUERY GDBMS_ALGO.centrality.degree_cent(SET<STRING> v_type_set, SET<STRING> e_type_set, SET<STRING> reverse_e_type_set, BOOL in_degree = TRUE, BOOL out_degree = TRUE,
2-
INT top_k=100, BOOL print_results = TRUE, STRING result_attribute = "",STRING file_path = "") SYNTAX V1 {
3-
2+
INT top_k=100, BOOL print_results = TRUE, STRING result_attribute = "",STRING file_path = "", BOOL normalize = TRUE) SYNTAX V1 {
43
/*
5-
First Author: <First Author Name>
6-
First Commit Date: <First Commit Date>
7-
8-
Recent Author: <Recent Commit Author Name>
9-
Recent Commit Date: <Recent Commit Date>
4+
First Author: <First Author Name>
5+
First Commit Date: <First Commit Date>
106

7+
Recent Author: Rob Rossmiller
8+
Recent Commit Date: 05/2024
119

12-
Repository:
13-
https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Centrality
1410

15-
Maturity:
16-
Production
11+
Repository:
12+
https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Centrality
1713

18-
Description:
19-
Compute degree Centrality for each VERTEX.
20-
for undirected graph, you only need to set e_type_set and indegree
14+
Maturity:
15+
Production
2116

22-
Publications:
23-
NA
17+
Description:
18+
Compute degree Centrality for each VERTEX.
19+
for undirected graph, you only need to set e_type_set and indegree
2420

25-
TigerGraph Documentation:
26-
https://docs.tigergraph.com/graph-ml/current/centrality-algorithms/degree-centrality
21+
Publications:
22+
NA
2723

28-
Parameters:
29-
v_type_set:
30-
vertex types to traverse
31-
e_type_set:
32-
edge types to traverse
33-
reverse_e_type_set:
34-
for indegree use
35-
in_degree:
36-
If True, count incoming relationships
37-
out_degree:
38-
If True, count outcoming relationships
39-
top_k:
40-
report only this many top scores
41-
print_results:
42-
If True, print the result
43-
result_attribute:
44-
attribute to write result to
45-
file_path:
46-
file to write CSV output to
24+
TigerGraph Documentation:
25+
https://docs.tigergraph.com/graph-ml/current/centrality-algorithms/degree-centrality
4726

27+
Parameters:
28+
v_type_set:
29+
vertex types to traverse
30+
e_type_set:
31+
edge types to traverse
32+
reverse_e_type_set:
33+
for indegree use
34+
in_degree:
35+
If True, count incoming relationships
36+
out_degree:
37+
If True, count outcoming relationships
38+
top_k:
39+
report only this many top scores
40+
print_results:
41+
If True, print the result
42+
result_attribute:
43+
attribute to write result to
44+
file_path:
45+
file to write CSV output to
46+
normailize:
47+
If True, return the normalized centrality. Default: True
4848
*/
4949

5050
TYPEDEF TUPLE<VERTEX Vertex_ID, FLOAT score> Vertex_Score;
5151
HeapAccum<Vertex_Score>(top_k, score DESC) @@top_scores_heap;
52-
SumAccum<INT> @sum_degree_score;
52+
SumAccum<DOUBLE> @sum_degree_score;
5353
FILE f (file_path);
5454

5555
all = {v_type_set};
5656
sll = SELECT s
5757
FROM all:s
58-
ACCUM IF in_degree THEN
59-
FOREACH edge_type in reverse_e_type_set DO
60-
s.@sum_degree_score+=s.outdegree(edge_type)
61-
END
62-
END,
63-
IF out_degree THEN
64-
FOREACH edge_type in e_type_set DO
65-
s.@sum_degree_score+=s.outdegree(edge_type)
66-
END
67-
END;
58+
ACCUM
59+
IF in_degree THEN
60+
s.@sum_degree_score += s.outdegree(reverse_e_type_set)
61+
END,
62+
IF out_degree THEN
63+
s.@sum_degree_score += s.outdegree(e_type_set)
64+
END
65+
POST-ACCUM
66+
IF normalize THEN
67+
s.@sum_degree_score = s.@sum_degree_score / (all.size() - 1)
68+
END;
69+
6870
#Output
6971
IF file_path != "" THEN
7072
f.println("Vertex_ID", "Degree");

algorithms/Centrality/degree/unweighted/tg_degree_cent.gsql

+50-49
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,71 @@
1-
CREATE QUERY tg_degree_cent(SET<STRING> v_type_set, SET<STRING> e_type_set, SET<STRING> reverse_e_type_set, BOOL in_degree = TRUE, BOOL out_degree = TRUE,
2-
INT top_k=100, BOOL print_results = TRUE, STRING result_attribute = "",STRING file_path = "") SYNTAX V1 {
3-
1+
CREATE QUERY tg_degree_cent(SET<STRING> v_type_set, SET<STRING> e_type_set, SET<STRING> reverse_e_type_set, BOOL in_degree = TRUE, BOOL out_degree = TRUE, INT top_k=100, BOOL print_results = TRUE, STRING result_attribute = "",STRING file_path = "", BOOL normalize = TRUE) SYNTAX V1 {
42
/*
5-
First Author: <First Author Name>
6-
First Commit Date: <First Commit Date>
7-
8-
Recent Author: <Recent Commit Author Name>
9-
Recent Commit Date: <Recent Commit Date>
3+
First Author: <First Author Name>
4+
First Commit Date: <First Commit Date>
105

6+
Recent Author: Rob Rossmiller
7+
Recent Commit Date: 05/2024
118

12-
Repository:
13-
https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Centrality
149

15-
Maturity:
16-
Production
10+
Repository:
11+
https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Centrality
1712

18-
Description:
19-
Compute degree Centrality for each VERTEX.
20-
for undirected graph, you only need to set e_type_set and indegree
13+
Maturity:
14+
Production
2115

22-
Publications:
23-
NA
16+
Description:
17+
Compute degree Centrality for each VERTEX.
18+
for undirected graph, you only need to set e_type_set and indegree
2419

25-
TigerGraph Documentation:
26-
https://docs.tigergraph.com/graph-ml/current/centrality-algorithms/degree-centrality
20+
Publications:
21+
NA
2722

28-
Parameters:
29-
v_type_set:
30-
vertex types to traverse
31-
e_type_set:
32-
edge types to traverse
33-
reverse_e_type_set:
34-
for indegree use
35-
in_degree:
36-
If True, count incoming relationships
37-
out_degree:
38-
If True, count outcoming relationships
39-
top_k:
40-
report only this many top scores
41-
print_results:
42-
If True, print the result
43-
result_attribute:
44-
attribute to write result to
45-
file_path:
46-
file to write CSV output to
23+
TigerGraph Documentation:
24+
https://docs.tigergraph.com/graph-ml/current/centrality-algorithms/degree-centrality
4725

26+
Parameters:
27+
v_type_set:
28+
vertex types to traverse
29+
e_type_set:
30+
edge types to traverse
31+
reverse_e_type_set:
32+
for indegree use
33+
in_degree:
34+
If True, count incoming relationships
35+
out_degree:
36+
If True, count outcoming relationships
37+
top_k:
38+
report only this many top scores
39+
print_results:
40+
If True, print the result
41+
result_attribute:
42+
attribute to write result to
43+
file_path:
44+
file to write CSV output to
45+
normailize:
46+
If True, return the normalized centrality. Default: True
4847
*/
4948

5049
TYPEDEF TUPLE<VERTEX Vertex_ID, FLOAT score> Vertex_Score;
5150
HeapAccum<Vertex_Score>(top_k, score DESC) @@top_scores_heap;
52-
SumAccum<INT> @sum_degree_score;
51+
SumAccum<DOUBLE> @sum_degree_score;
5352
FILE f (file_path);
5453

5554
all = {v_type_set};
5655
sll = SELECT s
5756
FROM all:s
58-
ACCUM IF in_degree THEN
59-
FOREACH edge_type in reverse_e_type_set DO
60-
s.@sum_degree_score+=s.outdegree(edge_type)
61-
END
62-
END,
63-
IF out_degree THEN
64-
FOREACH edge_type in e_type_set DO
65-
s.@sum_degree_score+=s.outdegree(edge_type)
66-
END
67-
END;
57+
ACCUM
58+
IF in_degree THEN
59+
s.@sum_degree_score += s.outdegree(reverse_e_type_set)
60+
END,
61+
IF out_degree THEN
62+
s.@sum_degree_score += s.outdegree(e_type_set)
63+
END
64+
POST-ACCUM
65+
IF normalize THEN
66+
s.@sum_degree_score = s.@sum_degree_score / (all.size() - 1)
67+
END;
68+
6869
#Output
6970
IF file_path != "" THEN
7071
f.println("Vertex_ID", "Degree");

tests/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Algorithm Testing
2+
3+
[networkX](https://networkx.org/documentation/stable/reference/index.html) is used as
4+
the baseline for our tests where we can.
5+
6+
A peculiarity to note about nx is that it counts self edges in undirected graphs as two separate edges. So, you'll see that some baselines use a modified version of the code that is found within nx. Take `run_degree_baseline_complete`, which generates the baseline for degree centrality on complete graphs. It uses the same code that can be found in `nx.centrality.degree_centrality` with the exception of subtracting a node's degree by one.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 1.1428571428571428}, {"Vertex_ID": "B", "score": 1.1428571428571428}, {"Vertex_ID": "C", "score": 1.1428571428571428}, {"Vertex_ID": "D", "score": 1.1428571428571428}, {"Vertex_ID": "E", "score": 1.1428571428571428}, {"Vertex_ID": "F", "score": 1.1428571428571428}, {"Vertex_ID": "G", "score": 1.1428571428571428}, {"Vertex_ID": "H", "score": 1.1428571428571428}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 1.0}, {"Vertex_ID": "B", "score": 0.05263157894736842}, {"Vertex_ID": "C", "score": 0.05263157894736842}, {"Vertex_ID": "D", "score": 0.05263157894736842}, {"Vertex_ID": "E", "score": 0.05263157894736842}, {"Vertex_ID": "F", "score": 0.05263157894736842}, {"Vertex_ID": "G", "score": 0.05263157894736842}, {"Vertex_ID": "H", "score": 0.05263157894736842}, {"Vertex_ID": "I", "score": 0.05263157894736842}, {"Vertex_ID": "J", "score": 0.05263157894736842}, {"Vertex_ID": "K", "score": 0.05263157894736842}, {"Vertex_ID": "L", "score": 0.05263157894736842}, {"Vertex_ID": "M", "score": 0.05263157894736842}, {"Vertex_ID": "N", "score": 0.05263157894736842}, {"Vertex_ID": "O", "score": 0.05263157894736842}, {"Vertex_ID": "P", "score": 0.05263157894736842}, {"Vertex_ID": "Q", "score": 0.05263157894736842}, {"Vertex_ID": "R", "score": 0.05263157894736842}, {"Vertex_ID": "S", "score": 0.05263157894736842}, {"Vertex_ID": "T", "score": 0.05263157894736842}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 0.05263157894736842}, {"Vertex_ID": "B", "score": 0.10526315789473684}, {"Vertex_ID": "C", "score": 0.10526315789473684}, {"Vertex_ID": "D", "score": 0.10526315789473684}, {"Vertex_ID": "E", "score": 0.10526315789473684}, {"Vertex_ID": "F", "score": 0.10526315789473684}, {"Vertex_ID": "G", "score": 0.10526315789473684}, {"Vertex_ID": "H", "score": 0.10526315789473684}, {"Vertex_ID": "I", "score": 0.10526315789473684}, {"Vertex_ID": "J", "score": 0.10526315789473684}, {"Vertex_ID": "K", "score": 0.10526315789473684}, {"Vertex_ID": "L", "score": 0.10526315789473684}, {"Vertex_ID": "M", "score": 0.10526315789473684}, {"Vertex_ID": "N", "score": 0.10526315789473684}, {"Vertex_ID": "O", "score": 0.10526315789473684}, {"Vertex_ID": "P", "score": 0.10526315789473684}, {"Vertex_ID": "Q", "score": 0.10526315789473684}, {"Vertex_ID": "R", "score": 0.10526315789473684}, {"Vertex_ID": "S", "score": 0.10526315789473684}, {"Vertex_ID": "T", "score": 0.05263157894736842}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 0.10526315789473684}, {"Vertex_ID": "B", "score": 0.10526315789473684}, {"Vertex_ID": "C", "score": 0.10526315789473684}, {"Vertex_ID": "D", "score": 0.10526315789473684}, {"Vertex_ID": "E", "score": 0.10526315789473684}, {"Vertex_ID": "F", "score": 0.10526315789473684}, {"Vertex_ID": "G", "score": 0.10526315789473684}, {"Vertex_ID": "H", "score": 0.10526315789473684}, {"Vertex_ID": "I", "score": 0.10526315789473684}, {"Vertex_ID": "J", "score": 0.10526315789473684}, {"Vertex_ID": "K", "score": 0.10526315789473684}, {"Vertex_ID": "L", "score": 0.10526315789473684}, {"Vertex_ID": "M", "score": 0.10526315789473684}, {"Vertex_ID": "N", "score": 0.10526315789473684}, {"Vertex_ID": "O", "score": 0.10526315789473684}, {"Vertex_ID": "P", "score": 0.10526315789473684}, {"Vertex_ID": "Q", "score": 0.10526315789473684}, {"Vertex_ID": "R", "score": 0.10526315789473684}, {"Vertex_ID": "S", "score": 0.10526315789473684}, {"Vertex_ID": "T", "score": 0.10526315789473684}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 0.10526315789473684}, {"Vertex_ID": "B", "score": 0.15789473684210525}, {"Vertex_ID": "C", "score": 0.15789473684210525}, {"Vertex_ID": "D", "score": 0.15789473684210525}, {"Vertex_ID": "E", "score": 0.15789473684210525}, {"Vertex_ID": "F", "score": 0.15789473684210525}, {"Vertex_ID": "G", "score": 0.15789473684210525}, {"Vertex_ID": "H", "score": 0.15789473684210525}, {"Vertex_ID": "I", "score": 0.15789473684210525}, {"Vertex_ID": "J", "score": 0.10526315789473684}, {"Vertex_ID": "K", "score": 0.05263157894736842}, {"Vertex_ID": "L", "score": 0.05263157894736842}, {"Vertex_ID": "M", "score": 0.05263157894736842}, {"Vertex_ID": "N", "score": 0.05263157894736842}, {"Vertex_ID": "O", "score": 0.05263157894736842}, {"Vertex_ID": "P", "score": 0.05263157894736842}, {"Vertex_ID": "Q", "score": 0.05263157894736842}, {"Vertex_ID": "R", "score": 0.05263157894736842}, {"Vertex_ID": "S", "score": 0.05263157894736842}, {"Vertex_ID": "T", "score": 0.05263157894736842}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 0.0}, {"Vertex_ID": "B", "score": 0.05263157894736842}, {"Vertex_ID": "C", "score": 0.05263157894736842}, {"Vertex_ID": "D", "score": 0.05263157894736842}, {"Vertex_ID": "E", "score": 0.05263157894736842}, {"Vertex_ID": "F", "score": 0.05263157894736842}, {"Vertex_ID": "G", "score": 0.05263157894736842}, {"Vertex_ID": "H", "score": 0.05263157894736842}, {"Vertex_ID": "I", "score": 0.05263157894736842}, {"Vertex_ID": "J", "score": 0.05263157894736842}, {"Vertex_ID": "K", "score": 0.05263157894736842}, {"Vertex_ID": "L", "score": 0.05263157894736842}, {"Vertex_ID": "M", "score": 0.05263157894736842}, {"Vertex_ID": "N", "score": 0.05263157894736842}, {"Vertex_ID": "O", "score": 0.05263157894736842}, {"Vertex_ID": "P", "score": 0.05263157894736842}, {"Vertex_ID": "Q", "score": 0.05263157894736842}, {"Vertex_ID": "R", "score": 0.05263157894736842}, {"Vertex_ID": "S", "score": 0.05263157894736842}, {"Vertex_ID": "T", "score": 0.05263157894736842}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 0.0}, {"Vertex_ID": "B", "score": 0.05263157894736842}, {"Vertex_ID": "C", "score": 0.05263157894736842}, {"Vertex_ID": "D", "score": 0.05263157894736842}, {"Vertex_ID": "E", "score": 0.05263157894736842}, {"Vertex_ID": "F", "score": 0.05263157894736842}, {"Vertex_ID": "G", "score": 0.05263157894736842}, {"Vertex_ID": "H", "score": 0.05263157894736842}, {"Vertex_ID": "I", "score": 0.05263157894736842}, {"Vertex_ID": "J", "score": 0.05263157894736842}, {"Vertex_ID": "K", "score": 0.05263157894736842}, {"Vertex_ID": "L", "score": 0.05263157894736842}, {"Vertex_ID": "M", "score": 0.05263157894736842}, {"Vertex_ID": "N", "score": 0.05263157894736842}, {"Vertex_ID": "O", "score": 0.05263157894736842}, {"Vertex_ID": "P", "score": 0.05263157894736842}, {"Vertex_ID": "Q", "score": 0.05263157894736842}, {"Vertex_ID": "R", "score": 0.05263157894736842}, {"Vertex_ID": "S", "score": 0.05263157894736842}, {"Vertex_ID": "T", "score": 0.05263157894736842}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 0.05263157894736842}, {"Vertex_ID": "B", "score": 0.05263157894736842}, {"Vertex_ID": "C", "score": 0.05263157894736842}, {"Vertex_ID": "D", "score": 0.05263157894736842}, {"Vertex_ID": "E", "score": 0.05263157894736842}, {"Vertex_ID": "F", "score": 0.05263157894736842}, {"Vertex_ID": "G", "score": 0.05263157894736842}, {"Vertex_ID": "H", "score": 0.05263157894736842}, {"Vertex_ID": "I", "score": 0.05263157894736842}, {"Vertex_ID": "J", "score": 0.05263157894736842}, {"Vertex_ID": "K", "score": 0.05263157894736842}, {"Vertex_ID": "L", "score": 0.05263157894736842}, {"Vertex_ID": "M", "score": 0.05263157894736842}, {"Vertex_ID": "N", "score": 0.05263157894736842}, {"Vertex_ID": "O", "score": 0.05263157894736842}, {"Vertex_ID": "P", "score": 0.05263157894736842}, {"Vertex_ID": "Q", "score": 0.05263157894736842}, {"Vertex_ID": "R", "score": 0.05263157894736842}, {"Vertex_ID": "S", "score": 0.05263157894736842}, {"Vertex_ID": "T", "score": 0.05263157894736842}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 0.0}, {"Vertex_ID": "B", "score": 0.05263157894736842}, {"Vertex_ID": "C", "score": 0.05263157894736842}, {"Vertex_ID": "D", "score": 0.05263157894736842}, {"Vertex_ID": "E", "score": 0.05263157894736842}, {"Vertex_ID": "F", "score": 0.05263157894736842}, {"Vertex_ID": "G", "score": 0.05263157894736842}, {"Vertex_ID": "H", "score": 0.05263157894736842}, {"Vertex_ID": "I", "score": 0.05263157894736842}, {"Vertex_ID": "J", "score": 0.05263157894736842}, {"Vertex_ID": "K", "score": 0.05263157894736842}, {"Vertex_ID": "L", "score": 0.05263157894736842}, {"Vertex_ID": "M", "score": 0.05263157894736842}, {"Vertex_ID": "N", "score": 0.05263157894736842}, {"Vertex_ID": "O", "score": 0.05263157894736842}, {"Vertex_ID": "P", "score": 0.05263157894736842}, {"Vertex_ID": "Q", "score": 0.05263157894736842}, {"Vertex_ID": "R", "score": 0.05263157894736842}, {"Vertex_ID": "S", "score": 0.05263157894736842}, {"Vertex_ID": "T", "score": 0.05263157894736842}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 1.0}, {"Vertex_ID": "B", "score": 0.0}, {"Vertex_ID": "C", "score": 0.0}, {"Vertex_ID": "D", "score": 0.0}, {"Vertex_ID": "E", "score": 0.0}, {"Vertex_ID": "F", "score": 0.0}, {"Vertex_ID": "G", "score": 0.0}, {"Vertex_ID": "H", "score": 0.0}, {"Vertex_ID": "I", "score": 0.0}, {"Vertex_ID": "J", "score": 0.0}, {"Vertex_ID": "K", "score": 0.0}, {"Vertex_ID": "L", "score": 0.0}, {"Vertex_ID": "M", "score": 0.0}, {"Vertex_ID": "N", "score": 0.0}, {"Vertex_ID": "O", "score": 0.0}, {"Vertex_ID": "P", "score": 0.0}, {"Vertex_ID": "Q", "score": 0.0}, {"Vertex_ID": "R", "score": 0.0}, {"Vertex_ID": "S", "score": 0.0}, {"Vertex_ID": "T", "score": 0.0}]}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"top_scores": [{"Vertex_ID": "A", "score": 0.05263157894736842}, {"Vertex_ID": "B", "score": 0.05263157894736842}, {"Vertex_ID": "C", "score": 0.05263157894736842}, {"Vertex_ID": "D", "score": 0.05263157894736842}, {"Vertex_ID": "E", "score": 0.05263157894736842}, {"Vertex_ID": "F", "score": 0.05263157894736842}, {"Vertex_ID": "G", "score": 0.05263157894736842}, {"Vertex_ID": "H", "score": 0.05263157894736842}, {"Vertex_ID": "I", "score": 0.05263157894736842}, {"Vertex_ID": "J", "score": 0.05263157894736842}, {"Vertex_ID": "K", "score": 0.05263157894736842}, {"Vertex_ID": "L", "score": 0.05263157894736842}, {"Vertex_ID": "M", "score": 0.05263157894736842}, {"Vertex_ID": "N", "score": 0.05263157894736842}, {"Vertex_ID": "O", "score": 0.05263157894736842}, {"Vertex_ID": "P", "score": 0.05263157894736842}, {"Vertex_ID": "Q", "score": 0.05263157894736842}, {"Vertex_ID": "R", "score": 0.05263157894736842}, {"Vertex_ID": "S", "score": 0.05263157894736842}, {"Vertex_ID": "T", "score": 0.0}]}]

0 commit comments

Comments
 (0)