brainconn.modularity.community_louvain

community_louvain(W, gamma=1, ci=None, B='modularity', seed=None)[source]

The optimal community structure is a subdivision of the network into nonoverlapping groups of nodes which maximizes the number of within-group edges and minimizes the number of between-group edges.

This function is a fast an accurate multi-iterative generalization of the louvain community detection algorithm. This function subsumes and improves upon modularity_[louvain,finetune]_[und,dir]() and additionally allows to optimize other objective functions (includes built-in Potts Model i Hamiltonian, allows for custom objective-function matrices).

Parameters:
  • W (NxN np.array) – directed/undirected weighted/binary adjacency matrix
  • gamma (float) – resolution parameter. default value=1. Values 0 <= gamma < 1 detect larger modules while gamma > 1 detects smaller modules. ignored if an objective function matrix is specified.
  • ci (Nx1 np.arraylike) – initial community affiliation vector. default value=None
  • B (str | NxN np.arraylike) –

    string describing objective function type, or provides a custom NxN objective-function matrix. builtin values

    ’modularity’ uses Q-metric as objective function ‘potts’ uses Potts model Hamiltonian. ‘negative_sym’ symmetric treatment of negative weights ‘negative_asym’ asymmetric treatment of negative weights
  • seed (int | None) – random seed. default value=None. if None, seeds from /dev/urandom.
Returns:

  • ci (Nx1 np.array) – final community structure
  • q (float) – optimized q-statistic (modularity only)