graphragzen.clustering.leiden

graphragzen.clustering.leiden(graph, max_comm_size=0, min_comm_size=0, levels=2)[source]

Graph clustering using the Leiden algorithm (see: https://arxiv.org/abs/1810.08473)

note: Clusters have levels, i.e. cluster 1 can be subdevided into multiple clusters.

This is represented by a comma separated string, where each index is a level. e.g. cluster “2, 11” is the 11th subcluster of the 2nd cluster, while cluster “4, 11” is associated with main cluster “4” and has no relation with cluster “2, 11”.

Parameters:
  • graph (nx.Graph)

  • max_comm_size (int, optional) – Maximum number of nodes in one cluster. Defaults to 0 (no contraint).

  • min_comm_size (int, optional) – Minimum number of nodes in one cluster. Defaults to 0 (no contraint).

  • levels (int, optional) – Clusters can be split into clusters, how many levels should there be? Defaults to 2.

Returns:

nx.Graph has the feature ‘cluster’ added to the entities.

cluster_map maps for each cluster the nodes that belong to it.

Return type:

tuple(nx.Graph, cluster_map)