This package facilitates the computation of a wide range of overlapping community detection algorithms (OCDAs), and visualization of the results.
For the implementation used in our preprint 'Benchmarking overlapping community detection methods for applications in human connectomics', please refer to the designated repository: https://github.com/DynamicsAndNeuralSystems/OverlappingCommunityDetection_HCP.
Run startup (from any directory) to add the toolbox to the MATLAB path.
Methods implemented in MATLAB (SLPA, Clique, NNMF, WSBM) need nothing else. The other methods call external programs, which are not included as binaries and must be compiled for your system:
- OSLOM: in a terminal, navigate to
SourceCode/OSLOMand run./compile_all.sh. Onlyoslom_undiris needed; errors compiling the other programs (pajek, louvain, infomap) can be ignored. See the OSLOM website for more information. - Infomap: navigate to
SourceCode/Infomapand runmake cleanand thenmake. - SVINET (Gopalan): requires the GSL library.
Navigate to
SourceCode/Gopalanand run./configureand thenmake(seeSourceCode/Gopalan/README.mdfor setting library paths on macOS). - Link communities: requires Python 3.
MATLAB calls
python3by default; to use a different interpreter, set the environment variableOCDA_PYTHON(e.g.,setenv('OCDA_PYTHON','/opt/homebrew/anaconda3/bin/python3')). - WSBM (optional speed-up): run
InstallMEXFilesinSourceCode/Clausetto compile its MEX files.
[Final,computationTimes] = OLCD_Compute(networkAdj,methodList,isBenchmark,benchmarkFileName,sourceCodePath,outputPath);Inputs (all but the first are optional):
networkAdj: an adjacency matrix, or an edge list as a 3-column matrix[node1, node2, weight]with positive-integer node ids. An edge list is treated as undirected ifnode1 <= node2in every row, and as directed otherwise. A 3x3 input is ambiguous and is treated as an adjacency matrix (with a warning).methodList: cell array of method names (see below).isBenchmark:trueif the network has known (benchmark) communities (defaultfalse).benchmarkFileName: text file defining the benchmark communities, one line per node:node comm1 comm2 ...(as produced by the LFR benchmark generator).sourceCodePath: path to theSourceCodedirectory (default:SourceCodein this toolbox).outputPath: directory in which results are saved (default: the current directory).
Outputs:
Final(structure) contains the network, the benchmark communities (if provided), and one field per method output. Each method output is a structure with the method'sName, its parameters, and itsResult.computationTimes(structure) gives the computation time (in seconds) of each method output.- Results are also saved to
Computation_Result.matinoutputPath, which can be visualized using code inVisualization.
Name in methodList (alias) |
Method | Parameters swept by OLCD_Compute |
Output field names |
|---|---|---|---|
'Infomap' |
Infomap (with --overlapping) |
– | Infomap |
'OSLOM' |
Order Statistics Local Optimization Method | p-value tolerance 0.1, 0.2, …, 0.9 | OSLOM_10, …, OSLOM_90 |
'NNMF' |
Non-negative matrix factorization | membership threshold 0.1–0.4 | NNMF_10, …, NNMF_40 |
'SLPA' ('Jerry') |
Speaker–listener label propagation | – | Jerry |
'Clique' ('Shen') |
Clique-based method of Shen et al. (2009) | clique size 3, 4, 5, 6, 7, 9 | Clique_3, …, Clique_9 |
'Link' |
Link communities (Ahn et al., 2010) | proportion of weakest links removed: 0, 0.01, 0.1 | Link_prec_0, … |
'SVINET' ('Gopalan') |
Stochastic variational inference for the MMSB (Gopalan & Blei, 2013) | proportion of weakest links removed: 0, 0.1, 0.2, 0.3 | Gopalan_prec_0, … |
'WSBM' ('Clauset') |
Weighted stochastic block model (Aicher et al., 2014), number of blocks chosen by maximum log-evidence over k = 2–8. Gives a non-overlapping partition. | – | Clauset |
Each method's Result is a matrix in which each row is a node and each column is a community.
Each node's memberships sum to 1, split equally across the communities it belongs to (or 0 if the method left the node unassigned).
Empty communities are removed.
Each community detection method has its own directory in Computation, which contains three files:
call_[MethodName]: called byOLCD_Compute; it runs the method and processes its output in one line.run_[MethodName]: runs the algorithm (for external programs, input and output files are written to a temporary directory).process_[MethodName]: converts the algorithm's output into the standard matrix format described above.
In addition:
- Source code for each algorithm is in a directory in
SourceCode. - Functions for converting between adjacency matrices and edge lists are in
Computation/Conversions. - Shared utilities (temporary directories, running external commands, reading community files, tidying the output matrix) are in
Computation/Helpers.
- Place the source code of the algorithm in its own directory inside
SourceCode. - Write
run_[Method]: this should take the network (in whatever format is needed) and parameters, and output a community result (in any format). - Write
process_[Method]: this takes the output of the previous step and converts it to the standard matrix format (the helpersreadCommunityLines,communitiesToMatrix, andtidyCommunitiesmay be useful). - Write
call_[Method]: this calls the previous two functions, so the method can be run in one line. - Add a case for the method in the
switchstatement ofOLCD_Compute(looping over parameter values if needed), and add its name to the list of valid method names.
OLCD_Visualization(Methods,resultsFile,cmap)Methods: cell array of methods to plot, matched either by method name (e.g.,'NNMF'plots all NNMF thresholds) or by output field name (e.g.,'NNMF_20'). Include'Benchmark'to plot the benchmark communities. Default: all outputs in the results file.resultsFile: results file produced byOLCD_Compute(default'Computation_Result.mat').cmap: colormap name, function handle, or matrix (default'parula').
Nodes are ordered by the benchmark communities (if present), and otherwise by the first method plotted.
OLCD_Visualization: plots the network adjacency matrix alongside the communities of each method, for comparison.Node_Reorder: orders each method's communities from largest to smallest (colors depend on the community labels).Node_Sorter: orders the nodes according to the benchmark communities, so that communities are easier to see.
ENMI_calc: the extended normalized mutual information for overlapping communities (Lancichinetti, Fortunato & Kertész, 2009), between two community matrices (usesextendNMI_calcs).NMI_calc: normalized mutual information between two non-overlapping community matrices (errors on overlapping input).NMI_calc_vecs: normalized mutual information between two vectors of community labels.F1_overlapcalc: extracts the set of overlapping nodes from two community matrices and computes the F1 score for recovering them (usingF1_calc).