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.6, 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 >= 0.10). 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.10). 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.10.2.tar.gz (452.6 kB view hashes)

Uploaded Source

Built Distributions

leidenalg-0.10.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

leidenalg-0.10.2-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

leidenalg-0.10.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

leidenalg-0.10.2-pp310-pypy310_pp73-macosx_10_9_x86_64.whl (1.7 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

leidenalg-0.10.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

leidenalg-0.10.2-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

leidenalg-0.10.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

leidenalg-0.10.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (1.7 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

leidenalg-0.10.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

leidenalg-0.10.2-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

leidenalg-0.10.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

leidenalg-0.10.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (1.7 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

leidenalg-0.10.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

leidenalg-0.10.2-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

leidenalg-0.10.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

leidenalg-0.10.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (1.7 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

leidenalg-0.10.2-cp38-abi3-win_amd64.whl (1.6 MB view hashes)

Uploaded CPython 3.8+ Windows x86-64

leidenalg-0.10.2-cp38-abi3-win32.whl (1.3 MB view hashes)

Uploaded CPython 3.8+ Windows x86

leidenalg-0.10.2-cp38-abi3-musllinux_1_1_x86_64.whl (2.5 MB view hashes)

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

leidenalg-0.10.2-cp38-abi3-musllinux_1_1_i686.whl (2.6 MB view hashes)

Uploaded CPython 3.8+ musllinux: musl 1.1+ i686

leidenalg-0.10.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ x86-64

leidenalg-0.10.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ i686

leidenalg-0.10.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

leidenalg-0.10.2-cp38-abi3-macosx_11_0_arm64.whl (1.4 MB view hashes)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

leidenalg-0.10.2-cp38-abi3-macosx_10_9_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.8+ macOS 10.9+ x86-64

leidenalg-0.10.2-cp37-cp37m-win_amd64.whl (1.6 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

leidenalg-0.10.2-cp37-cp37m-win32.whl (1.3 MB view hashes)

Uploaded CPython 3.7m Windows x86

leidenalg-0.10.2-cp37-cp37m-musllinux_1_1_x86_64.whl (2.5 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

leidenalg-0.10.2-cp37-cp37m-musllinux_1_1_i686.whl (2.6 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

leidenalg-0.10.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

leidenalg-0.10.2-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (2.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

leidenalg-0.10.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

leidenalg-0.10.2-cp37-cp37m-macosx_10_9_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

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