Skip to main content

Ensemble Clustering for Graphs (ECG) and Graph aware measurse (GAM) for sknetwork.

Project description

Graph Partition and Measures

Python 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 sknetwork package. Versions for networkx and igraph are also available: partition-networkx, partition-igraph.

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", IEEE Transactions on Pattern Analysis and Machine Intelligence 43, 6 (2021) https://doi.org/10.1109/TPAMI.2020.3009862

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_sknetwork.

import sknetwork as sn
import partition_sknetwork as ps

Next, let's build a graph with communities.

block_sizes = [100 for _ in range(10)]
g = sn.data.models.block_model(block_sizes, 0.1, 0.025, seed=42)

# Store the ground truth communities
labels = np.array([i for i,block_size in enumerate(block_sizes) for _ in range(block_size)])

Run Louvain and ecg:

louvain = sn.clustering.Louvain(shuffle_nodes=True, random_state=42).fit_predict(g)
ecg = ps.ECG(random_state=42).fit_predict(g)

Finally, we show a few examples of measures we can compute with gam:

print('Adjusted Graph-Aware Rand Index for Louvain:',ps.gam(g, labels, louvain))
print('Adjusted Graph-Aware Rand Index for ECG:',ps.gam(g, labels, ecg))
print('Jaccard Graph-Aware for Louvain:',ps.gam(g, labels, louvain, method="jaccard", adjusted=False))
print('Jaccard Graph-Aware for ECG:',ps.gam(g, labels, ecg, 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_sknetwork-0.0.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

partition_sknetwork-0.0.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file partition_sknetwork-0.0.2.tar.gz.

File metadata

  • Download URL: partition_sknetwork-0.0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for partition_sknetwork-0.0.2.tar.gz
Algorithm Hash digest
SHA256 55aedb3790d6e0977e0d952370fba7049a8b41440486c49ab773ed05b77570e0
MD5 1b7242c35ada76f9593a04d653bfc9c0
BLAKE2b-256 953b4efd82a2c68c1b99bc5281c821c8f9d653d435fdc7223e859d3cc2abecaa

See more details on using hashes here.

File details

Details for the file partition_sknetwork-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for partition_sknetwork-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 816828bc0f589f38cf4b3893fbb5d68f09f73476a7b7c68bce2eb9ee54eee260
MD5 e361b36d024aa7c4bcbec82ce38859e8
BLAKE2b-256 02b9060ddb1f8e2b85725a0e1624723697e74d2aa376566ef70698efc0f29d80

See more details on using hashes here.

Supported by

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