Skip to main content

ModularityPruning

ModularityPruning visualization

ModularityPruning is a pruning tool to identify small subsets of network partitions that are significant from the perspective of stochastic block model inference. It:

  • Works for single-layer and multi-layer networks
  • Supports both directed and undirected networks
  • Supports weighted networks via the weight edge attribute
  • Restricts focus to a fixed number of communities when desired
  • Contains a faster and more robust implementation of the CHAMP (Convex Hull of Admissible Modularity Partitions) algorithm (see CHAMP_2D and CHAMP_3D)

See the documentation or the journal article at https://doi.org/10.1038/s41598-022-20142-6 for more information.

Significantly more details can be found in the article's Supplementary Information.

Note: support for weighted and directed networks is an extension beyond the original publication.

Installation

This project is on PyPI and can be installed with

pip install modularitypruning
# OR
pip3 install modularitypruning

Alternatively, you can install it from this repository directly:

git clone https://github.com/ragibson/ModularityPruning
cd ModularityPruning
pip install .

For modularitypruning development, it is best to use a strict editable install so that pytest and mypy can pick up changes immediately.

pip install --editable . --config-settings editable_mode=strict

Basic Usage

This package interfaces directly with python-igraph. A simple example of its usage is

import igraph as ig
from modularitypruning import prune_to_stable_partitions
from modularitypruning.leiden_utilities import repeated_leiden_from_gammas
import numpy as np

# get Karate Club graph in igraph
G = ig.Graph.Famous("Zachary")

# run leiden 1000 times on this graph from gamma=0 to gamma=2
partitions = repeated_leiden_from_gammas(G, np.linspace(0, 2, 1000))

# prune to the stable partitions from gamma=0 to gamma=2
stable_partitions = prune_to_stable_partitions(G, partitions, 0, 2)
print(stable_partitions)

This prints

[(0, 0, 0, 0, 1, 1, 1, 0, 2, 2, 1, 0, 0, 0, 2, 2, 1, 0, 2, 0, 2, 0, 2, 3, 3, 3, 2, 3, 3, 2, 2, 3, 2, 2)]

which is the stable 4-community split of the Karate Club network.

More Information

The issues (which contains some potential future work) and figure generation runtimes README may also be of interest.

Metadata

Release files for modularitypruning 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modularitypruning 2.0.0
File Size Uploaded
modularitypruning-2.0.0.tar.gz 36.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for modularitypruning 2.0.0
File Interpreter ABI Platform
modularitypruning-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 64.5 kB

Release files / modularitypruning-2.0.0.tar.gz

Download URL modularitypruning-2.0.0.tar.gz
Size 36.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d2c0e944527bb0e6f80cd5b925a9098375baab40de00d3e6dcbf1b4705a4cb13
BLAKE2b-256 checksum
How to use checksums
fa5de0fe0cc9a67cca82f4fc63912669884acaf8d01ec9043d903f0b9972c190
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / modularitypruning-2.0.0-py3-none-any.whl

Download URL modularitypruning-2.0.0-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f3581b675f76b251925f03074f263e2f44ee2397134ec5794ed5d520a3d4a38
BLAKE2b-256 checksum
How to use checksums
19a0b5963088ac394a8c45bf742d54594c806d8ae0779fd935f958144091977e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page