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.12.0.tar.gz (453.6 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.12.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.12.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.12.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.12.0-pp311-pypy311_pp73-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded PyPymacOS 11.0+ ARM64

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

Uploaded PyPymacOS 10.15+ x86-64

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

Uploaded CPython 3.8+Windows x86-64

leidenalg-0.12.0-cp38-abi3-win32.whl (1.7 MB view details)

Uploaded CPython 3.8+Windows x86

leidenalg-0.12.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.12.0-cp38-abi3-musllinux_1_2_i686.whl (4.1 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

leidenalg-0.12.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.12.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.12.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.12.0-cp38-abi3-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

leidenalg-0.12.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.12.0.tar.gz.

File metadata

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

File hashes

Hashes for leidenalg-0.12.0.tar.gz
Algorithm Hash digest
SHA256 c81a45a2fb874fe71e903d43a869d0efeb7f907af70476c03f6945ef0e8f44c5
MD5 5b4b34fe3913363eed5e3ee16a805936
BLAKE2b-256 82b745bae25ab59321a14902bec2f47e32b92e76f8b4b3887a13ee69a0b32c60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 43176c9470648098f6b642a6e070a12e65ef347700059da9132fefdf98e70df9
MD5 5a48a565b92726883d58c0991e16aeb3
BLAKE2b-256 45c05b5afcd49d49b2b249e6326d991ab3e74d5603ef917bdd9f283a6cf9cfa9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_26_i686.manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 b213229d8aa2708117642b478d5b51cae2cfeddf9d80aa98667fe7260119c3ee
MD5 6cb999c80077c4d9d37f90ff05fa6f2e
BLAKE2b-256 fe14f18249ee7f94f3c15066c4b2fb207236c0908ebea61252b5f10d131cffda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ecf067611776bf3acf33afcd1ecd8a381f67ab664c14e9530dd63eef0da646f8
MD5 c393cf4333938aba52e0126d1a9524d0
BLAKE2b-256 22f06839fb4a5de5892fbd47abaf6c9afe09d525eeabe6973e0bc1e731dd651c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-pp311-pypy311_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65466be8f6b14117cc285d4d785bedec8fc6792c48cf89a3df3551dba36fb782
MD5 edb69eb3d4c18c4c9c35c2321af508ba
BLAKE2b-256 7bd382f79c7615a5787737c4d11443afbdbbfcd6f9d6e304f767966954dd83d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-pp311-pypy311_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b48e26f746b3f3cee49d609f42b0eb4c3e80a174e16d13c6e371d9a555c93419
MD5 9dd9ee21c949fcdf2653a6fc2d80cb52
BLAKE2b-256 d1c7a6433027c603b97cba5748a5f00ff10aaaefcfdea46a9fc0e3f0f733591a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: leidenalg-0.12.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.12

File hashes

Hashes for leidenalg-0.12.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f5d9529b44d5f6add0847d68fa6ced99f581357f6ca02b54c049eb3a2f45ff04
MD5 1e9a6f08879516c360b63f874e276c2e
BLAKE2b-256 ea770c8fb67729e83bddd43971cd4851f497a96810fca63f8029e3f008e82b1b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for leidenalg-0.12.0-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 283cd987623e2c5e7b11ed3f15b7805d597a934bf387a7e820d2f673001b635f
MD5 b76dd7e4bad5da326e69b7dadd50bb31
BLAKE2b-256 d135f4f07ddac6718a11c70d858fd4afcc849ca84f485b5d7092bcf09492ec06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 63b49f5716c7cb155f3a3e25505bcc33f3c8c62105734fc152bc07518e63e9ab
MD5 29f06e204568819cfad4a8c66568f3bf
BLAKE2b-256 05e52f3322376fddd6b85790eaddcd314c9402bf81e984b35870acb4cfcbd0e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 c6a6231d3db490ee3cc4004f214b0bb947dc3fabde75bd61d878bc3fb9685d06
MD5 5101073e9aeb990b6e7affb29acde98d
BLAKE2b-256 e10222597cf6d7ee093523ad5885a31499d698812db5744d98086383c3da08b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-cp38-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fcbd89655243cc739d28ba23fe894587d8d7235124a9248ba375819585e70090
MD5 6c8d8ab610a325e82895949f64a7bf65
BLAKE2b-256 f7bedba31e662c2ee028e20dd0308c1bc6e398dd7a1786fdd0821722537b4124

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-cp38-abi3-manylinux_2_26_i686.manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 78df2e463f3ffffffda590e9b0d790107e59f722f095731b78a58803d1ca92e5
MD5 8802d5ba675c1b19f5922dfce4629eec
BLAKE2b-256 5f45cf5eb36b4517bb85397760a6033628695e8b0723b45f10f487b07cec84df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-cp38-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5f6a97f698f13a588e1ae7344908cddee9f87d33acc226fc5c5b99752ebd71f8
MD5 08f5c8a7ad67f1e3dffd3bc49d007a5a
BLAKE2b-256 cf367480eef0473bd87f69826e0dfb6bb1c1ee0915fa6d31be445d0bfcbd3a1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e0e1c2321c2e06a7f4f8a73ca15fcd54e0139a62afb448933c42badcfab8adc
MD5 9e69a41d3e35f62803fc10c291e3b0b3
BLAKE2b-256 72f6d15c889c7c65dbc41c84fe83243c203b083f70cef62ed0acc630098b2012

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for leidenalg-0.12.0-cp38-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 96eec407f540d9ddb0c103dadc632d5519cfcdb39689fb21ae0ceeaa97bb2ec3
MD5 5c9dd7a2fc16935865bcfe8ea674825c
BLAKE2b-256 537f0900c05ccbb27744f9dd11321dc2978e9f5ffe678db54f23eb94cf4e5951

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