Skip to main content
INTRODUCTION
============

This package implements the louvain 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
louvain algorithm for a number of different methods. The methods currently
implemented are:

Modularity
This method compares the actual graph to the expected graph, taking into
account the degree of the nodes [1]. The expected graph is based on a
configuration null-model.

RBConfiguration
This is an extension of modularity which includes a resolution parameter [2].
In general, a higher resolution parameter will lead to smaller communities.

RBER
A variant of the previous method that instead of a configuration null-model
uses a Erdös-Rényi null-model in which each edge has the same probability of
appearing [2].

CPM
This method compares to a fixed resolution parameter, so that it finds
communities that have an internal density higher than the resolution
parameter, and is separated from other communities with a density lowerer than
the resolution parameter [3].

Significance
This is a probabilistic method based on the idea of assessing the probability
of finding such dense subgraphs in an (ER) random graph [4].

Surprise
Another probabilistic method, but rather than the probability of finding dense
subgraphs, it focuses on the probability of so many edges within communities
[5, 6].

INSTALLATION
============

In short, for Unix: ``sudo pip install louvain``.
For Windows: download the binary installers.

For Unix like systems it is possible to install from source. For Windows this is
overly complicated, and you are recommended to use the binary installation files.
There are two things that are needed by this package: the igraph c core library
and the python-igraph python package. For both, please see http://igraph.org.

There are basically two installation modes, similar to the python-igraph package
itself (from which most of the setup.py comes).

1. No C core library is installed yet. The packages will be compiled and linked
statically to an automatically downloaded version of the C core library of
igraph.
2. A C core library is already installed. In this case, the package will link
dynamically to the already installed version. This is probably also the
version that is used by the igraph package, but you may want to double check
this.

In case the python-igraph package is already installed before, make sure that
both use the **same versions**.

The cleanest setup it to install and compile the C core library yourself (make
sure that the header files are also included, e.g. install also the development
package from igraph). Then both the python-igraph package, as well as this
package are compiled and (dynamically) linked to the same C core library.

TROUBLESHOOTING
===============

In case of any problems, best to start over with a clean environment. Make sure
you remove the python-igraph package completely, remove the C core library and
remove the louvain package. Then, do a complete reinstall starting from ``pip
install louvain``. In case you want a dynamic library be sure to then install
the C core library from source before. Make sure you **install the same
versions**.

USAGE
=====

There is no standalone version of louvain-igraph, and you will always need
python to access it. There are no plans for developing a standalone version or R
support. So, use python. Please refer to the documentation within the python
package for more details on function calls and parameters.

To start, make sure to import the packages:
```python
import louvain
import igraph as ig
```

We'll create a random graph for testing purposes:
```python
G = ig.Graph.Erdos_Renyi(100, 0.1);
```

For simply finding a partition use:
```python
part = louvain.find_partition(G, method='Modularity');
```

Notice that ``part`` now contains an additional variable, ``part.quality`` which
stores the quality of the partition as calculated by the used method. You can
always get the quality of the partition using another method by calling
```python
part.significance = louvain.quality(G, partition, method='Significance');
```

You can also find partition for multiplex graphs. For each layer you then
specify the objective function, and the overall objective function is simply the
sum over all layers, weighted by some weight. If we denote by ``q_k`` the quality
of layer ``k`` and the weight by ``w_k``, the overall quality is then ``q = sum_k
w_k q_k``. This can also be useful in case you have negative links. In
principle, this could also be used to detect temporal communities in a dynamic
setting, cf. [7].

For example, assuming you have a graph with positive weights ``G_positive`` and
a graph with negative weights ``G_negative``, and you want to use Modularity for
finding a partition, you can use
```python
membership, quality = louvain.find_partition_multiplex([
louvain.Layer(graph=G_positive, method='Modularity', layer_weight=1.0),
louvain.Layer(graph=G_negative, method='Modularity', layer_weight=-1.0)])
```

Notice the negative layer weight is ``-1.0`` for the negative graph, since we
want those edges to fall between communities rather than within. One particular
problem when using negative links, is that the optimal community is no longer
guaranteed to be connected (it may be a multipartite partition). You may
therefore need the options consider_comms=ALL_COMMS to improve the quality of
the partition. Notice that this runs much slower than only considering
neighbouring communities (which is the default).

Various methods (such as Reichardt and Bornholdt's Potts model, or CPM) support
a (linear) resolution parameter, which can be effectively bisected, cf. [4]. You
can do this by calling:
```python
res_parts = louvain.bisect(G, method='CPM', resolution_range=[0,1]);
```
Notice this may take some time to run, as it effectively calls
louvain.find_partition for various resolution parameters (depending on the
settings possibly hundreds of times).

Then ``res_parts`` is a dictionary containing as keys the resolution, and as
values a ``NamedTuple`` with variables ``partition`` and ``bisect_value``, which
contains the partition and the value at which the resolution was bisected (the
value of the ``bisect_func`` of the ``bisect`` function). You could for example
plot the bisection value of all the found partitions by using:
```python
import pandas as pd
import matplotlib.pyplot as plt
res_df = pd.DataFrame({
'resolution': res_parts.keys(),
'bisect_value': [bisect.bisect_value for bisect in res_parts.values()]});
plt.step(res_df['resolution'], res_df['bisect_value']);
plt.xscale('log');
```

REFERENCES
==========

Please cite the references appropriately in case they are used.

1. Newman, M. & Girvan, M. Finding and evaluating community structure in networks.
Physical Review E 69, 026113 (2004).
2. Reichardt, J. & Bornholdt, S. Partitioning and modularity of graphs with arbitrary
degree distribution. Physical Review E 76, 015102 (2007).
3. Traag, V. A., Van Dooren, P. & Nesterov, Y. Narrow scope for resolution-limit-free
community detection. Physical Review E 84, 016114 (2011).
4. Traag, V. A., Krings, G. & Van Dooren, P. Significant scales in community structure.
Scientific Reports 3, 2930 (2013).
5. Aldecoa, R. & Marín, I. Surprise maximization reveals the community structure
of complex networks. Scientific reports 3, 1060 (2013).
6. Traag, V.A., Aldecoa, R. & Delvenne, J.-C. Detecting communities using Asymptotical
Surprise. Forthcoming (2015).
7. Mucha, P. J., Richardson, T., Macon, K., Porter, M. A. & Onnela, J.-P.
Community structure in time-dependent, multiscale, and multiplex networks.
Science 328, 876–8 (2010).

Metadata

Release files for louvain 0.5.1

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

Source distribution (sdist)

Source distribution for louvain 0.5.1
File Size Uploaded Provenance Actions
louvain-0.5.1.tar.gz 44.2 kB Without provenance Details for louvain-0.5.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for louvain 0.5.1
File Actions
louvain-0.5.1.win-amd64-py3.4.msi Details for louvain-0.5.1.win-amd64-py3.4.msi
louvain-0.5.1.win-amd64-py2.7.msi Details for louvain-0.5.1.win-amd64-py2.7.msi
louvain-0.5.1.win32-py3.4.msi Details for louvain-0.5.1.win32-py3.4.msi
louvain-0.5.1.win32-py2.7.msi Details for louvain-0.5.1.win32-py2.7.msi
louvain-0.5.1-py3.4-linux-x86_64.egg Legacy Egg format - - Details for louvain-0.5.1-py3.4-linux-x86_64.egg
louvain-0.5.1-py2.7-linux-x86_64.egg Legacy Egg format - - Details for louvain-0.5.1-py2.7-linux-x86_64.egg

Total release size: 1.9 MB

Release files / louvain-0.5.1.tar.gz

Download URL louvain-0.5.1.tar.gz
Size 44.2 kB
Tags Source
SHA-256 checksum
How to use checksums
10d75c71a84de93874defec360014156d1d293a2c482f9e6dc9fdcac49c668c9
BLAKE2b-256 checksum
How to use checksums
af111b07649480bac60ab9d5557794f5ec94f8d10fe17af75b3f37a1844e932d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / louvain-0.5.1.win-amd64-py3.4.msi

Download URL louvain-0.5.1.win-amd64-py3.4.msi
Size 138.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cb1ebb2f6bc1d7797de771fe49fe5e9a991062963fcb1a675e86e96a3e8ae308
BLAKE2b-256 checksum
How to use checksums
36ad0f6f183a6c54924e3a627ef5cf28c886ed33635a54cfd2e5c11e4e7506d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / louvain-0.5.1.win-amd64-py2.7.msi

Download URL louvain-0.5.1.win-amd64-py2.7.msi
Size 420.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6f68c00e554b86ee5ad4be51fc13ad0cb7fce29229659c4f651f4213bf0ca25c
BLAKE2b-256 checksum
How to use checksums
8341c77699ee7773aa3e3f5f43a0614203953074247ac896ef37513b4c071742
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / louvain-0.5.1.win32-py3.4.msi

Download URL louvain-0.5.1.win32-py3.4.msi
Size 127.5 kB
Tags Source
SHA-256 checksum
How to use checksums
79dda7b16b7e15d18d49fc2a85c38cc8f4be081bd5cb5fc3c385f2c17b703786
BLAKE2b-256 checksum
How to use checksums
2cf6ae928ed864785e02407e195649ea0767428efcd4772dbb0a34593ee688e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / louvain-0.5.1.win32-py2.7.msi

Download URL louvain-0.5.1.win32-py2.7.msi
Size 390.7 kB
Tags Source
SHA-256 checksum
How to use checksums
08360ad645fea52492d17651cb27b5e91124b2f05a34361c6d47d532ba06ed0a
BLAKE2b-256 checksum
How to use checksums
57542792751767fb715a6ba6f0cb4a8e85b2f439da9af6d11d2f00dff64da365
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / louvain-0.5.1-py3.4-linux-x86_64.egg

Download URL louvain-0.5.1-py3.4-linux-x86_64.egg
Size 373.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
4fe789ac848ba8ab9c26a701d0fad6dd5916db5de5548cd655f8aa435389a71a
BLAKE2b-256 checksum
How to use checksums
3459d0f7814be8cb1625611e12cf9527f5e9ff056a481c6b1a0d7bc6f52e4560
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / louvain-0.5.1-py2.7-linux-x86_64.egg

Download URL louvain-0.5.1-py2.7-linux-x86_64.egg
Size 366.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
b33d1ddfa06bc5930164aa8b1110f382c786f3063054865df60ad7cc9636007f
BLAKE2b-256 checksum
How to use checksums
79b1570ac9d34852140d23f4915e436959248fbf869923260e87ed1ed974171a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for louvain 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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