diff --git a/GDBMS_ALGO/centrality/closeness.gsql b/GDBMS_ALGO/centrality/closeness.gsql deleted file mode 100644 index 8b137891..00000000 --- a/GDBMS_ALGO/centrality/closeness.gsql +++ /dev/null @@ -1 +0,0 @@ - diff --git a/GDBMS_ALGO/classification/knn.gsql b/GDBMS_ALGO/classification/knn.gsql deleted file mode 100644 index 8b137891..00000000 --- a/GDBMS_ALGO/classification/knn.gsql +++ /dev/null @@ -1 +0,0 @@ - diff --git a/GDBMS_ALGO/graphML/weisfeiler_lehman b/GDBMS_ALGO/graphML/weisfeiler_lehman deleted file mode 100644 index 8b137891..00000000 --- a/GDBMS_ALGO/graphML/weisfeiler_lehman +++ /dev/null @@ -1 +0,0 @@ - diff --git a/GDBMS_ALGO/similarity/cosine_nbor_ss.gsql b/GDBMS_ALGO/similarity/cosine_nbor_ss.gsql deleted file mode 100644 index 8b137891..00000000 --- a/GDBMS_ALGO/similarity/cosine_nbor_ss.gsql +++ /dev/null @@ -1 +0,0 @@ - diff --git a/GDBMS_ALGO/topological_link_prediction/adamic_adar b/GDBMS_ALGO/topological_link_prediction/adamic_adar.gsql similarity index 100% rename from GDBMS_ALGO/topological_link_prediction/adamic_adar rename to GDBMS_ALGO/topological_link_prediction/adamic_adar.gsql diff --git a/GDBMS_ALGO/topological_link_prediction/common_neighbors.gsql b/GDBMS_ALGO/topological_link_prediction/common_neighbors.gsql new file mode 100644 index 00000000..050bf353 --- /dev/null +++ b/GDBMS_ALGO/topological_link_prediction/common_neighbors.gsql @@ -0,0 +1,63 @@ +CREATE TEMPLATE QUERY GDBMS_ALGO.topological_link_prediction.common_neighbors(VERTEX v_source, VERTEX v_target, SET e_type_set, BOOL print_results = TRUE) SYNTAX V1 { + + /* + First Author: + First Commit Date: + + Recent Author: + 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; +} diff --git a/GDBMS_ALGO/topological_link_prediction/preferential_attachment.gsql b/GDBMS_ALGO/topological_link_prediction/preferential_attachment.gsql new file mode 100644 index 00000000..adefb97b --- /dev/null +++ b/GDBMS_ALGO/topological_link_prediction/preferential_attachment.gsql @@ -0,0 +1,62 @@ +CREATE TEMPLATE QUERY GDBMS_ALGO.topological_link_prediction.preferential_attachment(VERTEX v_source, VERTEX v_target, SET e_type_set, BOOL print_results = TRUE) SYNTAX V1 { + + /* + First Author: + First Commit Date: + + Recent Author: + 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; +} diff --git a/GDBMS_ALGO/topological_link_prediction/resource_allocation b/GDBMS_ALGO/topological_link_prediction/resource_allocation.gsql similarity index 100% rename from GDBMS_ALGO/topological_link_prediction/resource_allocation rename to GDBMS_ALGO/topological_link_prediction/resource_allocation.gsql diff --git a/GDBMS_ALGO/topological_link_prediction/same_community.gsql b/GDBMS_ALGO/topological_link_prediction/same_community.gsql deleted file mode 100644 index 8b137891..00000000 --- a/GDBMS_ALGO/topological_link_prediction/same_community.gsql +++ /dev/null @@ -1 +0,0 @@ - diff --git a/GDBMS_ALGO/topological_link_prediction/total_neighbors.gsql b/GDBMS_ALGO/topological_link_prediction/total_neighbors.gsql new file mode 100644 index 00000000..79904b7c --- /dev/null +++ b/GDBMS_ALGO/topological_link_prediction/total_neighbors.gsql @@ -0,0 +1,59 @@ +CREATE TEMPLATE QUERY GDBMS_ALGO.topological_link_prediction.total_neighbors(VERTEX v_source, VERTEX v_target, SET e_type_set, BOOL print_results = TRUE) SYNTAX V1 { + + /* + First Author: + First Commit Date: + + Recent Author: + 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; +} diff --git a/algorithms/Centrality/betweenness/tg_betweenness_cent.gsql b/algorithms/Centrality/betweenness/tg_betweenness_cent.gsql index 12b2722d..4de5cfbf 100644 --- a/algorithms/Centrality/betweenness/tg_betweenness_cent.gsql +++ b/algorithms/Centrality/betweenness/tg_betweenness_cent.gsql @@ -1,4 +1,4 @@ -CREATE QUERY tg_betweenness_cent(SET v_type_set, SET e_type_set, STRING reverse_e_type,INT max_hops = 10, +CREATE QUERY tg_betweenness_cent(SET v_type_set, SET e_type_set, SET 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 { diff --git a/algorithms/Centrality/closeness/exact/tg_closeness_cent.gsql b/algorithms/Centrality/closeness/exact/tg_closeness_cent.gsql index 2255351b..d1c2ad47 100644 --- a/algorithms/Centrality/closeness/exact/tg_closeness_cent.gsql +++ b/algorithms/Centrality/closeness/exact/tg_closeness_cent.gsql @@ -1,4 +1,4 @@ -CREATE QUERY tg_closeness_cent(SET v_type_set, SET e_type_set, STRING reverse_e_type,INT max_hops = 10, +CREATE QUERY tg_closeness_cent(SET v_type_set, SET e_type_set, SET 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 { diff --git a/algorithms/Community/k_means/tg_kmeans_sub.gsql b/algorithms/Community/k_means/tg_kmeans_sub.gsql index a5e3949c..1ee9a52b 100644 --- a/algorithms/Community/k_means/tg_kmeans_sub.gsql +++ b/algorithms/Community/k_means/tg_kmeans_sub.gsql @@ -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;