Adds ensemble clustering (ecg) and graph-aware measures (gam) to igraph.
Project description
Graph Partition and Measures
Python3 code implementing 11 graph-aware measures (gam) for comparing graph partitions as well as a stable ensemble-based graph partition algorithm (ecg). This verion works with the igraph package. A version for networkx is also available: partition-networkx.
Graph aware measures (gam)
The measures are respectively:
- 'rand': the RAND index
- 'jaccard': the Jaccard index
- 'mn': pairwise similarity normalized with the mean function
- 'gmn': pairwise similarity normalized with the geometric mean function
- 'min': pairwise similarity normalized with the minimum function
- 'max': pairwise similarity normalized with the maximum function
Each measure can be adjusted (recommended) or not, except for 'jaccard'. Details can be found in:
Valérie Poulin and François Théberge, "Comparing Graph Clusterings: Set partition measures vs. Graph-aware measures", https://arxiv.org/abs/1806.11494.
Ensemble clustering for graphs (ecg)
This is a good, stable graph partitioning algorithm. Details for ecg can be found in:
Valérie Poulin and François Théberge, "Ensemble clustering for graphs: comparisons and applications", Appl Netw Sci 4, 51 (2019). https://doi.org/10.1007/s41109-019-0162-z
Example
We need to import the supplied Python file partition_igraph.
import numpy as np
import igraph as ig
import partition_igraph
Next, let's build a graph with communities.
P = np.full((10,10),.025)
np.fill_diagonal(P,.1)
## 1000 nodes, 10 communities
g = ig.Graph.Preference(n=1000, type_dist=list(np.repeat(.1,10)),
pref_matrix=P.tolist(),attribute='class')
## the 'ground-truth' communities
tc = {k:v for k,v in enumerate(g.vs['class'])}
Run Louvain and ecg:
ml = g.community_multilevel()
ec = g.community_ecg(ens_size=32)
Finally, we show a few examples of measures we can compute with gam:
## for 'gam' partition are either 'igraph.clustering.VertexClustering' or 'dict'
print('Adjusted Graph-Aware Rand Index for Louvain:',g.gam(ml,tc))
print('Adjusted Graph-Aware Rand Index for ECG:',g.gam(ec,tc))
print('\nJaccard Graph-Aware for Louvain:',g.gam(ml,tc,method="jaccard",adjusted=False))
print('Jaccard Graph-Aware for ECG:',g.gam(ec,tc,method="jaccard",adjusted=False))
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
Built Distribution
File details
Details for the file partition_igraph-0.0.3.tar.gz
.
File metadata
- Download URL: partition_igraph-0.0.3.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c81d583e97420e73857a963ca4ce04f32bc60cc1ab17b28d9764a98c687cee8 |
|
MD5 | 6f1261b7d697eec8eb260c59ebbbf531 |
|
BLAKE2b-256 | 5c0cdfb93f10cf21b87f3bec50c84c2fa602e69c738e3d10187af3e5a8649015 |
File details
Details for the file partition_igraph-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: partition_igraph-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af2b15f12f6e47cb9983a1c062e652c9ee47db4f42c4eee7af2fdbf8a7e2022e |
|
MD5 | 7222a775fbe08b288a6b77988c4b6ae8 |
|
BLAKE2b-256 | f1d182978e84074ea9aead1cb8ccd3b6f3e6de98c0fcb0ba3e456745da0c10ae |