Skip to main content

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

partition_igraph-0.0.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

partition_igraph-0.0.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file partition_igraph-0.0.1.tar.gz.

File metadata

  • Download URL: partition_igraph-0.0.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

File hashes

Hashes for partition_igraph-0.0.1.tar.gz
Algorithm Hash digest
SHA256 992a246ace35e699b1d69d40790c16087fed89477e79bff8373a0cd3a86ee463
MD5 fb56fbb39b26d20c87202e87ba0cc4a3
BLAKE2b-256 18e483ba161571cb82c25d4fa57e5acaf26479608e11d16ee7f7c299d9632066

See more details on using hashes here.

File details

Details for the file partition_igraph-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: partition_igraph-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

File hashes

Hashes for partition_igraph-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f402302b1924f20d5d360324452496112f0d94add76849f38d33386e0aea50dc
MD5 65304f72d12c87f11af5d68219f9e522
BLAKE2b-256 8db7bea5eca56b7025779ef0597793ef8dc5c37d2913698299a07a87115f812d

See more details on using hashes here.

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