PygenStabilityOne is a community detection algorithm that leverages Markov stability (through the PyGenStability algorithm) as well as machine learning to return a single robust partition at a suitable scale that is consistent with the structure of the network, without requiring any information/assumption about the partition (number of communities, scale, resolution) from the user.
First, clone the repository with the following command:
git clone https://github.com/saref/PyGenStabilityOne.git
Then, either manually install all of the dependencies listed in requirements.txt, or install them all at once with:
pip install -r requirements.txt
Note: It is recommended to use this library with Python 3.11 in order to avoid dependency issues.
To use PyGenStabilityOne, simply:
- Import the
pygenstability_onefunction from thepygenstability_onelibrary. - Call
pygenstability_onewith annx.Graphnetwork as input.
Then, PygenStabilityOne will return a list of the communities detected in the network (where each community is represented by a list of node labels).
from pygenstability_one import pygenstability_one
graph = nx.read_gml("ABCD_0.gml", destringizer=int) # The graph should be an nx.Graph graph
coms = pygenstability_one(graph) # The returned value is a list of detected communitiesSee example.ipynb for example code that can be run locally.