brainconn.modularity.modularity_louvain_dir

modularity_louvain_dir(W, gamma=1, hierarchy=False, seed=None)[source]

The optimal community structure is a subdivision of the network into nonoverlapping groups of nodes in a way that maximizes the number of within-group edges, and minimizes the number of between-group edges. The modularity is a statistic that quantifies the degree to which the network may be subdivided into such clearly delineated groups.

The Louvain algorithm is a fast and accurate community detection algorithm (as of writing). The algorithm may also be used to detect hierarchical community structure.

Parameters:
  • W (NxN numpy.ndarray) – directed weighted/binary connection matrix
  • gamma (float) – resolution parameter. default value=1. Values 0 <= gamma < 1 detect larger modules while gamma > 1 detects smaller modules.
  • hierarchy (bool) – Enables hierarchical output. Defalut value=False
  • seed (int | None) – random seed. default value=None. if None, seeds from /dev/urandom.
Returns:

  • ci (Nx1 numpy.ndarray) – refined community affiliation vector. If hierarchical output enabled, it is an NxH numpy.ndarray instead with multiple iterations
  • Q (float) – optimized modularity metric. If hierarchical output enabled, becomes an Hx1 array of floats instead.

Notes

Ci and Q may vary from run to run, due to heuristics in the algorithm. Consequently, it may be worth to compare multiple runs.