bioneuralnet.clustering.louvain

Standard Louvain Method for Community Detection - NumPy Implementation.

References

Blondel et al. (2008), “Fast unfolding of communities in large networks.”

Classes

Louvain(G[, weight, max_passes, min_delta, seed])

Standard Louvain community detection.

class bioneuralnet.clustering.louvain.Louvain(G: Graph, weight: str = 'weight', max_passes: int = 100, min_delta: float = 1e-10, seed: int | None = None)[source]

Bases: object

Standard Louvain community detection.

This class encapsulates the multi-phase optimization algorithm for detecting communities in weighted graphs.

property communities: Dict[int, List[Any]]

Retrieves the communities grouped by community ID.

Convenient for iterating over sets of nodes belonging to the same community.

Returns:

A dictionary mapping community IDs to lists of nodes.

Return type:

Dict[int, List[Any]]

property history: List[Dict[str, Any]]

Retrieves the history of the algorithm’s execution levels.

Provides insight into the convergence process and reduction of graph size.

Returns:

A list of dictionaries containing stats for each level.

Return type:

List[Dict[str, Any]]

property modularity: float

Retrieves the final modularity score of the computed partition.

Requires that the run() method has been executed previously.

Returns:

The modularity score.

Return type:

float

property partition: Dict[Any, int]

Retrieves the final partition of the graph.

Requires that the run() method has been executed previously.

Returns:

A dictionary mapping nodes to community IDs.

Return type:

Dict[Any, int]

run() Dict[Any, int][source]

Executes the full Louvain algorithm by alternating between local optimization and graph aggregation.

Loops until the modularity converges or the graph cannot be aggregated further.

Returns:

A dictionary mapping original node identifiers to their final community IDs.

Return type:

Dict[Any, int]