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.
Version 0.0.8 is now compatible with igraph 1.0.0 where the semantics of the permutation argument changed.
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))
Metadata
Release files for partition-igraph 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| partition_igraph-0.0.8.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| partition_igraph-0.0.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / partition_igraph-0.0.8.tar.gz
| Download URL | partition_igraph-0.0.8.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42c80e80ecf556a8b94aa9657c7bdf1a23ded05c8833bd0fba4c25216f98af0b
|
|
BLAKE2b-256 checksum How to use checksums |
64c77517c9002962d539538a64b2039ce8e344a459b4262638930e5d2ce8a3d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Release files / partition_igraph-0.0.8-py3-none-any.whl
| Download URL | partition_igraph-0.0.8-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7932aa4561c575c7a744e5b433b8358fe15e8af44a234cc458f662e6aa04a10f
|
|
BLAKE2b-256 checksum How to use checksums |
8a17fe381b000d90c9f4cf395dc4ea20f46e325a54e54dd909b319fa41ffb1c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|