Skip to content

Commit

Permalink
Merge pull request #142 from tigergraph/GML-1574
Browse files Browse the repository at this point in the history
[GML-1574] fix(files): sync files with algos repository;
  • Loading branch information
parkererickson-tg authored Mar 15, 2024
2 parents 4d91fb1 + 85a7d71 commit 62e455a
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 8 deletions.
1 change: 0 additions & 1 deletion GDBMS_ALGO/centrality/closeness.gsql

This file was deleted.

1 change: 0 additions & 1 deletion GDBMS_ALGO/classification/knn.gsql

This file was deleted.

1 change: 0 additions & 1 deletion GDBMS_ALGO/graphML/weisfeiler_lehman

This file was deleted.

1 change: 0 additions & 1 deletion GDBMS_ALGO/similarity/cosine_nbor_ss.gsql

This file was deleted.

63 changes: 63 additions & 0 deletions GDBMS_ALGO/topological_link_prediction/common_neighbors.gsql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
CREATE TEMPLATE QUERY GDBMS_ALGO.topological_link_prediction.common_neighbors(VERTEX v_source, VERTEX v_target, SET<STRING> e_type_set, BOOL print_results = TRUE) SYNTAX V1 {

/*
First Author: <First Author Name>
First Commit Date: <First Commit Date>

Recent Author: <Recent Commit Author Name>
Recent Commit Date: <Recent Commit Date>


Repository:
https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Topological%20Link%20Prediction

Maturity:
production

Description:
This query calculates the number of common neighbors between two vertices.
The higher the number, the closer two vertices are.

Publications:
NA

TigerGraph Documentation:
https://docs.tigergraph.com/graph-ml/current/link-prediction/common-neighbors

Parameters:
v_source:
Input vertex one
v_target:
Input vertex two
e_type_set:
edge types to traverse. If all edge types are desired, pass in "ALL" to the set.
print_results:
if True, print result (True by default)
*/

avs = {v_source};
bvs = {v_target};

IF "ALL" NOT IN e_type_set THEN # Specific edge types defined
# Get neighbors of source vertices
na = SELECT n
FROM avs -(e_type_set)- :n;

nb = SELECT n
FROM bvs -(e_type_set)- :n;

ELSE # Use any edge types
# Get neighbors of source vertices
na = SELECT n
FROM avs -()- :n;

nb = SELECT n
FROM bvs -()- :n;
END;
# Get neighbors in common
u = na INTERSECT nb;

IF print_results THEN
PRINT u.size() as closeness;
END;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
CREATE TEMPLATE QUERY GDBMS_ALGO.topological_link_prediction.preferential_attachment(VERTEX v_source, VERTEX v_target, SET<STRING> e_type_set, BOOL print_results = TRUE) SYNTAX V1 {

/*
First Author: <First Author Name>
First Commit Date: <First Commit Date>

Recent Author: <Recent Commit Author Name>
Recent Commit Date: <Recent Commit Date>


Repository:
https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Topological%20Link%20Prediction

Maturity:
production

Description:
This query calculates the preferential attachment value between two vertices.
The higher the number, the closer two vertices are.

Preferential attachment is calculated by multiplying the number of each input vertices neighbors together.

Publications:
NA

TigerGraph Documentation:
https://docs.tigergraph.com/graph-ml/current/link-prediction/preferential-attachment

Parameters:
v_source:
Input vertex one
v_target:
Input vertex two
e_type_set:
edge types to traverse. If all edge types are desired, pass in "ALL" to the set.
print_results:
if True, print result (True by default)
*/

avs = {v_source};
bvs = {v_target};

# See if user specified edge types to traverse
IF "ALL" NOT IN e_type_set THEN
na = SELECT n
FROM avs -(e_type_set)- :n; # Get neighbors of vertex A

nb = SELECT n
FROM bvs -(e_type_set)- :n; // Get neighbors of vertex B

ELSE // traverse all edge types
na = SELECT n
FROM avs -()- :n; // Get neighbors of vertex A

nb = SELECT n
FROM bvs -()- :n; // Get neighbors of vertex B
END;

IF print_results THEN
PRINT na.size()*nb.size() as closeness; // calculate and return closeness value
END;
}
1 change: 0 additions & 1 deletion GDBMS_ALGO/topological_link_prediction/same_community.gsql

This file was deleted.

59 changes: 59 additions & 0 deletions GDBMS_ALGO/topological_link_prediction/total_neighbors.gsql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
CREATE TEMPLATE QUERY GDBMS_ALGO.topological_link_prediction.total_neighbors(VERTEX v_source, VERTEX v_target, SET<STRING> e_type_set, BOOL print_results = TRUE) SYNTAX V1 {

/*
First Author: <First Author Name>
First Commit Date: <First Commit Date>

Recent Author: <Recent Commit Author Name>
Recent Commit Date: <Recent Commit Date>


Repository:
https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Topological%20Link%20Prediction

Maturity:
production

Description:
This query calculates the number of total neighbors of two vertices.
The higher the number, the closer two vertices are.

Publications:
NA

TigerGraph Documentation:
https://docs.tigergraph.com/graph-ml/current/link-prediction/total-neighbors

Parameters:
v_source:
Input vertex one
v_target:
Input vertex two
e_type_set:
edge types to traverse. If all edge types are desired, pass in "ALL" to the set.
print_results:
if True, print result (True by default)
*/

avs = {v_source};
bvs = {v_target};

IF "ALL" NOT IN e_type_set THEN # Specific edge types defined as parameters
na = SELECT n
FROM avs -(e_type_set)- :n; # Get vertex A's neighbors

nb = SELECT n
FROM bvs -(e_type_set)- :n; # Get vertex B's neighbors

ELSE # Use all edge types
na = SELECT n
FROM avs -()- :n; # Get vertex A's neighbors

nb = SELECT n
FROM bvs -()- :n; # Get vertex B's neighbors
END;
u = na UNION nb; # Get all neighbors
IF print_results THEN
PRINT u.size() as closeness;
END;
}
2 changes: 1 addition & 1 deletion algorithms/Centrality/betweenness/tg_betweenness_cent.gsql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE QUERY tg_betweenness_cent(SET<STRING> v_type_set, SET<STRING> e_type_set, STRING reverse_e_type,INT max_hops = 10,
CREATE QUERY tg_betweenness_cent(SET<STRING> v_type_set, SET<STRING> e_type_set, SET<STRING> reverse_e_type,INT max_hops = 10,
INT top_k = 100, BOOL print_results = True, STRING result_attribute = "",
STRING file_path = "", BOOL display_edges = FALSE) SYNTAX V1 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE QUERY tg_closeness_cent(SET<STRING> v_type_set, SET<STRING> e_type_set, STRING reverse_e_type,INT max_hops = 10,
CREATE QUERY tg_closeness_cent(SET<STRING> v_type_set, SET<STRING> e_type_set, SET<STRING> reverse_e_type,INT max_hops = 10,
INT top_k = 100, BOOL wf = TRUE, BOOL print_results = True, STRING result_attribute = "",
STRING file_path = "", BOOL display_edges = FALSE) SYNTAX V1 {

Expand Down
2 changes: 1 addition & 1 deletion algorithms/Community/k_means/tg_kmeans_sub.gsql
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CREATE QUERY tg_kmeans_sub(int k, float max_change = 1.0, string v_type, string
IF random == TRUE THEN
FOREACH i IN range[0,k-1] DO
FOREACH j IN range[0,99] DO
@@centroids_array[i][j] = rand_int(-2,5)-0.123*0.4;
@@centroids_array[i][j] = tg_rand_int(-2,5)-0.123*0.4;
END;
END;
END;
Expand Down

0 comments on commit 62e455a

Please sign in to comment.