brainconn.modularity.modularity_louvain_und_sign

modularity_louvain_und_sign(W, gamma=1, qtype='sta', 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 (at the time of writing).

Use this function as opposed to modularity_louvain_und() only if the network contains a mix of positive and negative weights. If the network contains all positive weights, the output will be equivalent to that of modularity_louvain_und().

Parameters:
  • W (NxN numpy.ndarray) – undirected weighted/binary connection matrix with positive and negative weights
  • qtype (str) – modularity type. Can be ‘sta’ (default), ‘pos’, ‘smp’, ‘gja’, ‘neg’. See Rubinov and Sporns (2011) for a description.
  • gamma (float) – resolution parameter. default value=1. Values 0 <= gamma < 1 detect larger modules while gamma > 1 detects smaller modules.
  • seed (int | None) – random seed. default value=None. if None, seeds from /dev/urandom.
Returns:

  • ci (Nx1 numpy.ndarray) – refined community affiliation vector
  • Q (float) – optimized modularity metric

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.