Skip to main content

SClump implemented in Python.

Project description

PySClump Build Status

A Python implementation of 'Spectral Clustering in Heterogeneous Information Networks' from AAAI, 2019.
This was heavily inspired by the original implementation in MATLAB.

Figure: A similarity matrix represented as a graph. Nodes are coloured according to their assigned cluster.

References

Li, Xiang and Kao, Ben and Ren, Zhaochun and Yin, Dawei. 'Spectral Clustering in Heterogeneous Information Networks'. Proceedings of the AAAI Conference on Artificial Intelligence: 4221-4228.

Installation

PySClump is available on PyPI! Install with:

pip install pysclump

PathSim

We provide PathSim as a similarity metric between pairs of nodes. However, PySClump works with any similarity metric! See the SClump section below.

from pysclump import PathSim
import numpy as np

type_lists = {
    'A': ['Mike', 'Jim', 'Mary', 'Bob', 'Ann'],
    'C': ['SIGMOD', 'VLDB', 'ICDE', 'KDD'],
    'V': ['Pasadena', 'Guwahati', 'Bangalore']
}

incidence_matrices = { 
   'AC': np.array([[2, 1, 0, 0], [50, 20, 0, 0], [2, 0, 1, 0], [2, 1, 0, 0], [0, 0, 1, 1]]),
   'VC': np.array([[3, 1, 1, 1], [1, 0, 0, 0], [2, 1, 0, 1]])
}

# Create PathSim instance.
ps = PathSim(type_lists, incidence_matrices)

# Get the similarity between two authors (indicated by type 'A').
ps.pathsim('Mike', 'Jim', metapath='ACA')

# Get the similarity matrix M for the metapath.
ps.compute_similarity_matrix(metapath='ACVCA')

SClump

Once we have the similarity matrices (PathSim shown here), running SClump is really simple.

from pysclump import SClump

# Construct similarity matrices.
similarity_matrices = {
    'ACA': pathsim.compute_similarity_matrix(metapath='ACA'),
    'ACVCA': pathsim.compute_similarity_matrix(metapath='ACVCA'),
}

# Create SClump instance.
sclump = SClump(similarity_matrices, num_clusters=2)

# Run the algorithm!
labels, learned_similarity_matrix, metapath_weights = sclump.run()

If we have n nodes to be clustered into k clusters, labels is a n-by-1 vector, with entries from 0 to (k - 1) indicating the cluster index assigned. learned_similarity_matrix is the n-by-n matrix S referenced in the paper, indicating node-to-node similarity.

The clusters themselves are assigned by k++-means clustering either on the similarity matrix directly, or on the Laplacian of the learned similarity matrix.

Acknowledgements

This would not have been possible without the assistance of my CS529 teammates at IIT Guwahati:

Credit for visualization is completely due to Ramyani Ghosh (ramyani-ghosh).

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

pysclump-0.0.4.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

pysclump-0.0.4-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file pysclump-0.0.4.tar.gz.

File metadata

  • Download URL: pysclump-0.0.4.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.6.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.5.2

File hashes

Hashes for pysclump-0.0.4.tar.gz
Algorithm Hash digest
SHA256 b87faf847334f4866b6ff2f494bbcbccaa6bc3dc7b7d81a1d9f9753607d82bfc
MD5 35fdf59bdd1785a34fd10d5e512c75e7
BLAKE2b-256 ea1e6bdefc47c96ee9f59f22c1b3b5803bc951fa2181087fa68549e73f9295ad

See more details on using hashes here.

File details

Details for the file pysclump-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pysclump-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.6.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.5.2

File hashes

Hashes for pysclump-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e89b7e980b7919956d1ef3a774df0dabe6131ad52d3c1fbedf1e205b275860c7
MD5 fdb51f66cb30116ffb82b0b3e26c3558
BLAKE2b-256 34d3788d8caf2614ded6fbbdcfea4928ba05132568740c2eee18685864f306da

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