Skip to main content

Run modularity density-based clustering

Project description

Build Status Python badge

Community detection by fine-tuned optimization of modularity and modularity density


Python >= 3.5.0
NetworkX >= 2.2s
NumPy >= 1.15.1
SciPy >= 1.1.0


pip install modularitydensity

Quick Start

import networkx as nx
import numpy as np
from modularitydensity.metrics import modularity_density
from modularitydensity.fine_tuned_modularity_density import fine_tuned_clustering_qds

G = nx.karate_club_graph() #sample dataset
adj = nx.to_scipy_sparse_matrix(G) #convert to sparse matrix

community_array = fine_tuned_clustering_qds(G)
>> [2 2 2 2 4 4 4 2 3 3 4 2 2 2 3 3 4 2 3 2 3 2 3 3 1 1 3 3 3 3 3 1 3 3]

computed_metric = modularity_density(adj, community_array, np.unique(community_array))
>> 0.2312650016945721    


This package comprises two community detection algorithms which perform fine-tuned optimization of modularity and modularity density, respectively, of a community network structure. The fine-tuned algorithm iteratively carries out splitting and merging stages, alternatively, until neither splitting nor merging of the community structure improves the desired metric.

Also included are extensions of the fine_tuned optimizations of both modules. These extended versions account for any constraint on the maximum community size, while optimizing the desired metric.

Source code can be found at:


[1] CHEN M, KUZMIN K, SZYMANSKI BK. Community detection via maximization of modularity and its variants. IEEE Transactions on Computational Social Systems. 1(1), 46–65, 2014

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for modularitydensity, version 0.0.6
Filename, size File type Python version Upload date Hashes
Filename, size modularitydensity-0.0.6-py2.py3-none-any.whl (28.8 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size modularitydensity-0.0.6.tar.gz (127.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page