Community Functions#
2025-05-20
9 min read time
Triangle Counting#
- hipgraph_error_code_t hipgraph_triangle_count(
- const hipgraph_resource_handle_t *handle,
- hipgraph_graph_t *graph,
- const hipgraph_type_erased_device_array_view_t *start,
- hipgraph_bool_t do_expensive_check,
- hipgraph_triangle_count_result_t **result,
- hipgraph_error_t **error,
Triangle Counting.
- Parameters:
handle – [in] Handle for accessing resources
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
start – [in] Device array of vertices we want to count triangles for. If NULL the entire set of vertices in the graph is processed
do_expensive_check – [in] A flag to run expensive checks for input arguments (if set to true)
result – [out] Output from the triangle_count call
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
Louvain#
- hipgraph_error_code_t hipgraph_louvain(
- const hipgraph_resource_handle_t *handle,
- hipgraph_graph_t *graph,
- size_t max_level,
- double threshold,
- double resolution,
- hipgraph_bool_t do_expensive_check,
- hipgraph_hierarchical_clustering_result_t **result,
- hipgraph_error_t **error,
Compute Louvain.
- Parameters:
handle – [in] Handle for accessing resources
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
max_level – [in] Maximum level in hierarchy
threshold – [in] Threshold parameter, defines convergence at each level of hierarchy
resolution – [in] Resolution parameter (gamma) in modularity formula. This changes the size of the communities. Higher resolutions lead to more smaller communities, lower resolutions lead to fewer larger communities.
do_expensive_check – [in] A flag to run expensive checks for input arguments (if set to true)
result – [out] Output from the Louvain call
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
Leiden#
- hipgraph_error_code_t hipgraph_leiden(
- const hipgraph_resource_handle_t *handle,
- hipgraph_rng_state_t *rng_state,
- hipgraph_graph_t *graph,
- size_t max_level,
- double resolution,
- double theta,
- hipgraph_bool_t do_expensive_check,
- hipgraph_hierarchical_clustering_result_t **result,
- hipgraph_error_t **error,
Compute Leiden.
- Parameters:
handle – [in] Handle for accessing resources
rng_state – [inout] State of the random number generator, updated with each call
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
max_level – [in] Maximum level in hierarchy
resolution – [in] Resolution parameter (gamma) in modularity formula. This changes the size of the communities. Higher resolutions lead to more smaller communities, lower resolutions lead to fewer larger communities.
theta – [in] (optional) The value of the parameter to scale modularity gain in Leiden refinement phase. It is used to compute the probability of joining a random leiden community. Called theta in the Leiden algorithm.
do_expensive_check – [in] A flag to run expensive checks for input arguments (if set to true)
result – [out] Output from the Leiden call
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
ECG#
- hipgraph_error_code_t hipgraph_ecg(
- const hipgraph_resource_handle_t *handle,
- hipgraph_rng_state_t *rng_state,
- hipgraph_graph_t *graph,
- double min_weight,
- size_t ensemble_size,
- size_t max_level,
- double threshold,
- double resolution,
- hipgraph_bool_t do_expensive_check,
- hipgraph_hierarchical_clustering_result_t **result,
- hipgraph_error_t **error,
Compute ECG clustering of the given graph.
ECG runs truncated Louvain on an ensemble of permutations of the input graph, then uses the ensemble partitions to determine weights for the input graph. The final result is found by running full Louvain on the input graph using the determined weights. See https://arxiv.org/abs/1809.05578 for further information.
- Parameters:
handle – [in] Handle for accessing resources
rng_state – [inout] State of the random number generator, updated with each call
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
min_weight – [in] Minimum edge weight in final graph
ensemble_size – [in] The number of Louvain iterations to run
max_level – [in] Maximum level in hierarchy for final Louvain
threshold – [in] Threshold parameter, defines convergence at each level of hierarchy for final Louvain
resolution – [in] Resolution parameter (gamma) in modularity formula. This changes the size of the communities. Higher resolutions lead to more smaller communities, lower resolutions lead to fewer larger communities.
do_expensive_check – [in] A flag to run expensive checks for input arguments (if set to true)
result – [out] Output from the Louvain call
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
Extract Egonet#
- hipgraph_error_code_t hipgraph_extract_ego(
- const hipgraph_resource_handle_t *handle,
- hipgraph_graph_t *graph,
- const hipgraph_type_erased_device_array_view_t *source_vertices,
- size_t radius,
- hipgraph_bool_t do_expensive_check,
- hipgraph_induced_subgraph_result_t **result,
- hipgraph_error_t **error,
Extract ego graphs.
- Parameters:
handle – [in] Handle for accessing resources
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
source_vertices – [in] Device array of vertices we want to extract egonets for.
radius – [in] The number of hops to go out from each source vertex
do_expensive_check – [in] A flag to run expensive checks for input arguments (if set to true)
result – [out] Opaque object containing the extracted subgraph
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
Balanced Cut#
- hipgraph_error_code_t hipgraph_balanced_cut_clustering(
- const hipgraph_resource_handle_t *handle,
- hipgraph_graph_t *graph,
- size_t n_clusters,
- size_t n_eigenvectors,
- double evs_tolerance,
- int evs_max_iterations,
- double k_means_tolerance,
- int k_means_max_iterations,
- hipgraph_bool_t do_expensive_check,
- hipgraph_clustering_result_t **result,
- hipgraph_error_t **error,
Balanced cut clustering.
NOTE: This currently wraps the legacy balanced cut clustering implementation and is only available in Single GPU implementation.
- Parameters:
handle – [in] Handle for accessing resources
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
n_clusters – [in] The desired number of clusters
n_eigenvectors – [in] The number of eigenvectors to use
evs_tolerance – [in] The tolerance to use for the eigenvalue solver
evs_max_iterations – [in] The maximum number of iterations of the eigenvalue solver
k_means_tolerance – [in] The tolerance to use for the k-means solver
k_means_max_iterations – [in] The maximum number of iterations of the k-means solver
do_expensive_check – [in] A flag to run expensive checks for input arguments (if set to true)
result – [out] Opaque object containing the clustering result
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
Spectral Clustering - Modularity Maximization#
- hipgraph_error_code_t hipgraph_spectral_modularity_maximization(
- const hipgraph_resource_handle_t *handle,
- hipgraph_graph_t *graph,
- size_t n_clusters,
- size_t n_eigenvectors,
- double evs_tolerance,
- int evs_max_iterations,
- double k_means_tolerance,
- int k_means_max_iterations,
- hipgraph_bool_t do_expensive_check,
- hipgraph_clustering_result_t **result,
- hipgraph_error_t **error,
Spectral clustering.
NOTE: This currently wraps the legacy spectral clustering implementation and is only available in Single GPU implementation.
- Parameters:
handle – [in] Handle for accessing resources
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
n_clusters – [in] The desired number of clusters
n_eigenvectors – [in] The number of eigenvectors to use
evs_tolerance – [in] The tolerance to use for the eigenvalue solver
evs_max_iterations – [in] The maximum number of iterations of the eigenvalue solver
k_means_tolerance – [in] The tolerance to use for the k-means solver
k_means_max_iterations – [in] The maximum number of iterations of the k-means solver
do_expensive_check – [in] A flag to run expensive checks for input arguments (if set to true)
result – [out] Opaque object containing the clustering result
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
- hipgraph_error_code_t hipgraph_analyze_clustering_modularity(
- const hipgraph_resource_handle_t *handle,
- hipgraph_graph_t *graph,
- size_t n_clusters,
- const hipgraph_type_erased_device_array_view_t *vertices,
- const hipgraph_type_erased_device_array_view_t *clusters,
- double *score,
- hipgraph_error_t **error,
Compute modularity of the specified clustering.
NOTE: This currently wraps the legacy spectral modularity implementation and is only available in Single GPU implementation.
- Parameters:
handle – [in] Handle for accessing resources
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
n_clusters – [in] The desired number of clusters
vertices – [in] Vertex ids from the clustering result
clusters – [in] Cluster ids from the clustering result
score – [out] The modularity score for this clustering
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
Spectral Clustering - Edge Cut#
- hipgraph_error_code_t hipgraph_analyze_clustering_edge_cut(
- const hipgraph_resource_handle_t *handle,
- hipgraph_graph_t *graph,
- size_t n_clusters,
- const hipgraph_type_erased_device_array_view_t *vertices,
- const hipgraph_type_erased_device_array_view_t *clusters,
- double *score,
- hipgraph_error_t **error,
Compute edge cut of the specified clustering.
NOTE: This currently wraps the legacy spectral edge cut implementation and is only available in Single GPU implementation.
- Parameters:
handle – [in] Handle for accessing resources
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
n_clusters – [in] The desired number of clusters
vertices – [in] Vertex ids from the clustering result
clusters – [in] Cluster ids from the clustering result
score – [out] The edge cut score for this clustering
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
- hipgraph_error_code_t hipgraph_analyze_clustering_ratio_cut(
- const hipgraph_resource_handle_t *handle,
- hipgraph_graph_t *graph,
- size_t n_clusters,
- const hipgraph_type_erased_device_array_view_t *vertices,
- const hipgraph_type_erased_device_array_view_t *clusters,
- double *score,
- hipgraph_error_t **error,
Compute ratio cut of the specified clustering.
NOTE: This currently wraps the legacy spectral ratio cut implementation and is only available in Single GPU implementation.
- Parameters:
handle – [in] Handle for accessing resources
graph – [in] Pointer to graph. NOTE: Graph might be modified if the storage needs to be transposed
n_clusters – [in] The desired number of clusters
vertices – [in] Vertex ids from the clustering result
clusters – [in] Cluster ids from the clustering result
score – [out] The ratio cut score for this clustering
error – [out] Pointer to an error object storing details of any error. Will be populated if error code is not HIPGRAPH_SUCCESS
- Returns:
error code
Community Support Functions#
- hipgraph_type_erased_device_array_view_t *hipgraph_triangle_count_result_get_vertices(
)#
- hipgraph_triangle_count_result_t *result,
Get triangle counting vertices.
- hipgraph_type_erased_device_array_view_t *hipgraph_triangle_count_result_get_counts(
)#
- hipgraph_triangle_count_result_t *result,
Get triangle counting counts.
- void hipgraph_triangle_count_result_free(
)#
- hipgraph_triangle_count_result_t *result,
Free a triangle count result.
- Parameters:
result – [in] The result from a sampling algorithm
- hipgraph_type_erased_device_array_view_t *hipgraph_hierarchical_clustering_result_get_vertices(
)#
- hipgraph_hierarchical_clustering_result_t *result,
Get hierarchical clustering vertices.
- hipgraph_type_erased_device_array_view_t *hipgraph_hierarchical_clustering_result_get_clusters(
)#
- hipgraph_hierarchical_clustering_result_t *result,
Get hierarchical clustering clusters.
- double hipgraph_hierarchical_clustering_result_get_modularity(
)#
- hipgraph_hierarchical_clustering_result_t *result,
Get modularity.
- void hipgraph_hierarchical_clustering_result_free(
)#
- hipgraph_hierarchical_clustering_result_t *result,
Free a hierarchical clustering result.
- Parameters:
result – [in] The result from a sampling algorithm