DISCERN: Diversity-based Selection of Centroids for k-Estimation and Rapid Non-stochastic Clustering

November 12, 2020 ยท View on GitHub

This repository contains the implementation of DISCERN in Python. You can download the manuscript from my website or arXiv.

:red_circle: GPU-based DISCERN

:red_circle: New :red_circle:

This is just another implementation of DISCERN, except it is implemented in PyTorch instead of your average numpy. As a result, we can use all of the CUDA greatness to boost DISCERN beyond imagination.

from DISCERN import TorchDISCERN

di = DISCERN()
di.fit(X)

clustering_labels = di.labels_
cluster_centers = di.cluster_centers_
sse_loss = di.inertia_

For now, it automatically sets the variables to CUDA if it is available.

For those who've read the paper: the similarity precomputation and diversity-based selection are now a lot faster than on an average CPU. I'm also working on a torch-based K-Means to really push this over the edge.

Here's the progress so far:

:white_check_mark: Cosine similarity matrix computation

:white_check_mark: Diversity-based selection

:black_square_button: Finite differences

:black_square_button: K-Estimation

:black_square_button: K-Means

Examples

X = load_data() # This is assumed to be a 2-dimensional numpy array, where rows represent data samples.

Basic DISCERN instance (numpy-based):

from DISCERN import DISCERN

di = DISCERN()
di.fit(X)

clustering_labels = di.labels_
cluster_centers = di.cluster_centers_
sse_loss = di.inertia_

Fix the number of clusters to a specific number (only use DISCERN to initialize K-Means)

di = DISCERN(n_clusters=K)

Use Spherical K-Means

di = DISCERN(metric='cosine')

Specify an upper bound for the number of clusters

di = DISCERN(max_n_clusters=1000)

Notebooks

Two Jupyter notebooks are also provided in this repository (see examples/). Multivariate applies DISCERN to two of the multivariate datasets in the paper. The other (ImageNette) applies it to one of the image datasets in the paper, ImageNette. However, unlike the paper, the notebook uses MoCo [1][2] instead of a labeled-imagenet pretrained ResNet.

Stay tuned for more notebooks.

Citation

@article{hassani2020discern,
	title        = {DISCERN: diversity-based selection of centroids for k-estimation and rapid non-stochastic clustering},
	author       = {Hassani, Ali and Iranmanesh, Amir and Eftekhari, Mahdi and Salemi, Abbas},
	year         = 2020,
	journal      = {International Journal of Machine Learning and Cybernetics},
	doi          = {10.1007/s13042-020-01193-5}
}

References

[1] He, Kaiming, Haoqi Fan, Yuxin Wu, Saining Xie, and Ross Girshick. "Momentum contrast for unsupervised visual representation learning." In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 9729-9738. 2020. (arXiv | GitHub)
[2] Chen, Xinlei, Haoqi Fan, Ross Girshick, and Kaiming He. "Improved baselines with momentum contrastive learning." arXiv preprint arXiv:2003.04297 (2020).