pylibhipgraph.analyze_clustering_modularity

pylibhipgraph.analyze_clustering_modularity#

2025-05-20

2 min read time

Applies to Linux

analyze_clustering_modularity (ResourceHandle resource_handle, _GPUGraph graph, size_t num_clusters, vertex, cluster)

Compute modularity score of the specified clustering.

Parameters#

resource_handleResourceHandle

Handle to the underlying device resources needed for referencing data and running algorithms.

graphSGGraph

The input graph.

num_clusterssize_t

Specifies the number of clusters to find, must be greater than 1.

vertexdevice array type

Vertex ids from the clustering to analyze.

clusterdevice array type

Cluster ids from the clustering to analyze.

Returns#

The modularity score of the specified clustering.

Examples#

>>> import pylibhipgraph, cupy, numpy
>>> srcs = cupy.asarray([0, 1, 2], dtype=numpy.int32)
>>> dsts = cupy.asarray([1, 2, 0], dtype=numpy.int32)
>>> weights = cupy.asarray([1.0, 1.0, 1.0], dtype=numpy.float32)
>>> resource_handle = pylibhipgraph.ResourceHandle()
>>> graph_props = pylibhipgraph.GraphProperties(
...     is_symmetric=True, is_multigraph=False)
>>> G = pylibhipgraph.SGGraph(
...     resource_handle, graph_props, srcs, dsts, weight_array=weights,
...     store_transposed=True, renumber=False, do_expensive_check=False)
>>> (vertex, cluster) = pylibhipgraph.spectral_modularity_maximization(
...     resource_handle, G, num_clusters=5, num_eigen_vects=2, evs_tolerance=0.00001
...     evs_max_iter=100, kmean_tolerance=0.00001, kmean_max_iter=100)
    # FIXME: Fix docstring result.
>>> vertices
############
>>> clusters
############
>>> score = pylibhipgraph.analyze_clustering_modularity(
...     resource_handle, G, num_clusters=5, vertex=vertex, cluster=cluster)
>>> score
############