Skip to main content

Leiden is a general algorithm for methods of community detection in large networks.

Project description

This package implements the Leiden algorithm in C++ and exposes it to python. It relies on (python-)igraph for it to function. Besides the relative flexibility of the implementation, it also scales well, and can be run on graphs of millions of nodes (as long as they can fit in memory). The core function is find_partition which finds the optimal partition using the Leiden algorithm [1], which is an extension of the Louvain algorithm [2] for a number of different methods. The methods currently implemented are (1) modularity [3], (2) Reichardt and Bornholdt’s model using the configuration null model and the Erdös-Rényi null model [4], (3) the Constant Potts model (CPM) [5], (4) Significance [6], and finally (5) Surprise [7]. In addition, it supports multiplex partition optimisation allowing community detection on for example negative links [8] or multiple time slices [9]. There is the possibility of only partially optimising a partition, so that some community assignments remain fixed [10]. It also provides some support for community detection on bipartite graphs. See the documentation for more information.

Leiden documentation status Leiden build status (GitHub Actions) DOI Anaconda (conda-forge)

Installation

In short: pip install leidenalg. All major platforms are supported on Python>=3.9, earlier versions of Python are no longer supported. Alternatively, you can install from Anaconda (channel conda-forge).

For Unix like systems it is possible to install from source. For Windows this is more complicated, and you are recommended to use the binary wheels. This Python interface depends on the C++ package libleidenalg which in turn depends on igraph. You will need to build these packages yourself before you are able to build this Python interface.

Make sure you have all necessary tools for compilation. In Ubuntu this can be installed using sudo apt-get install build-essential autoconf automake flex bison, please refer to the documentation for your specific system. Make sure that not only gcc is installed, but also g++, as the leidenalg package is programmed in C++. Note that there are build scripts included in the scripts/ directory. These are also used to build the binary wheels.

  1. Compile (and install) the C core of igraph (version >= 1.0.0). You can use the file build_igraph.sh (on Unix-like systems) or build_igraph.bat (on Windows) in the scripts/ directory to do this. For more details, see https://igraph.org/c/doc/igraph-Installation.html.

  2. Compile (and install) the C core of libleidenalg (version >= 0.12). You can use the file build_libleidenalg.sh (on Unix-like systems) or build_libleidenalg.bat (on Windows) in the scripts/ directory to do this. For more details, see https://github.com/vtraag/libleidenalg.

  3. Build the Python interface using python setup.py build and python setup.py install, or use pip install .

You can check if all went well by running a variety of tests using python -m unittest.

Troubleshooting

In case of any problems, best to start over with a clean environment. Make sure you remove the igraph and leidenalg package completely. Then, do a complete reinstall starting from pip install leidenalg. In case you installed from source, and built the C libraries of igraph and libleidenalg yourself, remove them completely and rebuild and reinstall them.

Usage

This is the Python interface for the C++ package libleidenalg. There are no plans at the moment for developing an R interface to the package. However, there have been various efforts to port the package to R. These typically do not offer all available functionality or have some other limitations, but nonetheless may be very useful. The available ports are:

Please refer to the documentation for more details on function calls and parameters.

This implementation is made for flexibility, but igraph nowadays also includes an implementation of the Leiden algorithm internally. That implementation is less flexible: the implementation only works on undirected graphs, and only CPM and modularity are supported. It is likely to be substantially faster though.

Just to get you started, below the essential parts. To start, make sure to import the packages:

>>> import leidenalg
>>> import igraph as ig

We’ll create a random graph for testing purposes:

>>> G = ig.Graph.Erdos_Renyi(100, 0.1);

For simply finding a partition use:

>>> part = leidenalg.find_partition(G, leidenalg.ModularityVertexPartition);

Contribute

Source code: https://github.com/vtraag/leidenalg

Issue tracking: https://github.com/vtraag/leidenalg/issues

See the documentation on Implementation for more details on how to contribute new methods.

References

Please cite the references appropriately in case they are used.

Licence

Copyright (C) 2020 V.A. Traag

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Project details


Download files

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

Source Distribution

leidenalg-0.11.0.tar.gz (452.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

leidenalg-0.11.0-pp311-pypy311_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.6 MB view details)

Uploaded PyPymanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

leidenalg-0.11.0-pp311-pypy311_pp73-manylinux_2_26_i686.manylinux_2_28_i686.whl (2.7 MB view details)

Uploaded PyPymanylinux: glibc 2.26+ i686manylinux: glibc 2.28+ i686

leidenalg-0.11.0-pp311-pypy311_pp73-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.4 MB view details)

Uploaded PyPymanylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

leidenalg-0.11.0-pp311-pypy311_pp73-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded PyPymacOS 11.0+ ARM64

leidenalg-0.11.0-pp311-pypy311_pp73-macosx_10_15_x86_64.whl (2.3 MB view details)

Uploaded PyPymacOS 10.15+ x86-64

leidenalg-0.11.0-cp38-abi3-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.8+Windows x86-64

leidenalg-0.11.0-cp38-abi3-win32.whl (1.6 MB view details)

Uploaded CPython 3.8+Windows x86

leidenalg-0.11.0-cp38-abi3-musllinux_1_2_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

leidenalg-0.11.0-cp38-abi3-musllinux_1_2_i686.whl (4.1 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

leidenalg-0.11.0-cp38-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

leidenalg-0.11.0-cp38-abi3-manylinux_2_26_i686.manylinux_2_28_i686.whl (2.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.26+ i686manylinux: glibc 2.28+ i686

leidenalg-0.11.0-cp38-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

leidenalg-0.11.0-cp38-abi3-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

leidenalg-0.11.0-cp38-abi3-macosx_10_9_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.8+macOS 10.9+ x86-64

File details

Details for the file leidenalg-0.11.0.tar.gz.

File metadata

  • Download URL: leidenalg-0.11.0.tar.gz
  • Upload date:
  • Size: 452.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for leidenalg-0.11.0.tar.gz
Algorithm Hash digest
SHA256 f454be96bbc8089ea2a90ca853d8d389ab646de964a03bd58417f8b29ff8ef5d
MD5 037af0ef7431b394d6e769c2684e7cba
BLAKE2b-256 5da5853e93441aed7f82b0389f86f37e19413e817ba0c54cc790895935256968

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-pp311-pypy311_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-pp311-pypy311_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 023e97e4c96573e89fdea876da663e38694f6fa91e2c85e98455101409381d88
MD5 9e6837627c770af543ecf06373b0deb4
BLAKE2b-256 79b9d84d6225d79fed4fee19faef49e8b8fa58b70fcf55de5061bb1adf602eaa

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-pp311-pypy311_pp73-manylinux_2_26_i686.manylinux_2_28_i686.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-pp311-pypy311_pp73-manylinux_2_26_i686.manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 3d9c74f9c3d97d1daec5cc9f43b56a62bb3f40d5fef9f2b5defd8d715bfb5cdd
MD5 548898fa1a6c6491d615bfdfa0252cc0
BLAKE2b-256 b80d0560646fe75f6d161006cb6f164ef7d25096b9d59d68e836bce931ec8724

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-pp311-pypy311_pp73-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-pp311-pypy311_pp73-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9c1672eb4b24c2c484c0f4d2225267a456751f4624ac99619fed4fb9e4a31049
MD5 6bef66eaa3efc8f3bfd257b2412d8a80
BLAKE2b-256 9d7c7683c87e9d0bf70519a0d6cdbb27363b3520a4d5edd9c5f59181e393e2ff

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-pp311-pypy311_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-pp311-pypy311_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bed72262f181774de8425d6951c0e9c1d9c3d9bc64e030993e4215d6ab67933b
MD5 4a89f10588d98d950e72e115cf74368e
BLAKE2b-256 9b50ffad5f00e995ea064d1345867f6aa3534ebfb58e361309e088a12ef278d1

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-pp311-pypy311_pp73-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-pp311-pypy311_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 aa9b3bb5e75c5120b57cb8a3ba176610853359a9f5e787ecd6ba7e85c61f4fdc
MD5 c87bc7c026c964a184c4ff0ca7fecb8d
BLAKE2b-256 b201f6bdfb489ce86cb11f7b5428bb8c3cff751436fff4e12c99f3b5f59d622e

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: leidenalg-0.11.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for leidenalg-0.11.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5e789c0960008d185413344a402d0587580c441644d4d20bf57c96f25d4d1710
MD5 734e4f691727c41d79d47ad42615dcca
BLAKE2b-256 47157d459a8e2a43f17c1db129b997b7bb7aa7f000a0967bab87c28b8c5cf448

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-cp38-abi3-win32.whl.

File metadata

  • Download URL: leidenalg-0.11.0-cp38-abi3-win32.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for leidenalg-0.11.0-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 5ea4cd7ee054540112b28f7e2d64658dcccd59f61a5d6a08a41df808645f96e9
MD5 b83ec0c6b35c172ac9a89b6487015727
BLAKE2b-256 6e8e8caf4ba38fd7d8e6197348b348a4ab666b1b3117225ea2f0934a98a93176

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 310b9269a11fd1e960590c1a2b6ff685a2cc42aa3234ce67bc2a623ab61f26a9
MD5 fd63edd2fa853e05f545c0a9d084933b
BLAKE2b-256 fe94beaab5ee9968f9389f705532c31ffb868bad8a5ce68fb699ddde5ddc5409

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 aec03e7178b19102dd271b453a39b9865cf283b4113151ba60514e5681046294
MD5 fe4dd519e84a9d3fe2539108e4c20bac
BLAKE2b-256 e8fe8923cac6cd7c9e0ac5f38aaa69a4744c93d025575763d05f7a3baae8020d

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-cp38-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-cp38-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 571a0934f831a69442d82889d319bdba93de924bd9e09b720cd8cbe6fdc08c17
MD5 3447b14dbc81cb45ed8e82c19fdd6f76
BLAKE2b-256 b0a4a89e2ce16a580f7bea066ed49364f0b3e04a6412f0c3692975bee8515141

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-cp38-abi3-manylinux_2_26_i686.manylinux_2_28_i686.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-cp38-abi3-manylinux_2_26_i686.manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 2143be3e80485584ccbdf927323fce65345da17facd0f8b438f11015f5dc6c27
MD5 2d1011b0216272e3e6b26e7234e27d40
BLAKE2b-256 7787b087584750a788535b4a8d56ddeb82a175d32b472aa5338a4e2cc593a42c

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-cp38-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-cp38-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a80f49477f8e793f27d8e08949177f19e3834cd878af50a662b4f87335d06549
MD5 ec5eccd62da2117e887a76bc9ca8bfdc
BLAKE2b-256 9b38fd6ac21af10b12828b472eada4fce0edf2a212581238ad0c8d1afebc6f98

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b5781876b1f1faed72a4f9926ff52de286843556b9d6791fe25a2acb33b7a5c
MD5 ad198249e4c9350b0773430dc99b00e4
BLAKE2b-256 98f498db342d603671ae0a233f0a624939a47161044a2716cbd62a50440a1132

See more details on using hashes here.

File details

Details for the file leidenalg-0.11.0-cp38-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for leidenalg-0.11.0-cp38-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5607589050bfc1926e657b4d8a3b5341fe1eb81018c22cf4a3d3a39e368d1fcb
MD5 0659cef67521a7960b0e998e7bc23648
BLAKE2b-256 28a94ab4e244215db0c8b626e4bed0d3e0fbd191c52d2d5f5cb9d160139ecc7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page