Single-Linkage connectivity clustering
A fast algorithm computing connectivity components (clusters) of elements based on their feature cosine similarity. Two elements are connected by an edge if their cosine similarity is above a given threshold. Accepts either a numpy 2D array or a scipy column-sparse (CSR) matrix.
Install from PyPI with pip install silicon-clustering
Tomáš Gavenčiak gavento@ucw.cz
Usage example
import silicon, numpy # 1000 rows, 10 features data = numpy.random.rand(1000, 10) # The ensemble normalizes rows of the data by default # Choose high verbosity (via logging), cosine similarity >=0.97 ens = silicon.CosineClustering(data, sim_threshold=0.97, verbosity=2) ens.run() # (... progress reports) ens.clusters[0] # <Cluster no 0, size 13> ens.clusters_by_size()[0] # <Cluster no 36, size 22> # With pyplot you can see the projected points import matplotlib.pyplot as plt ens.plot(); plt.show() # or the individual clusters ens.clusters_by_size()[0].plot(ens); plt.show()
Details
The algorithm uses several tricks to speed up the computation compared to traditional all-pair scalar products via matrix multiplication:
The data is projected into cell_dims principal components (PCA) by feature. The projection divides the data into cells of size self.distance so only rows from adjacent cells have a chance to be similar enough. Then the vectors of the rows of the adjacent cells are multiplied.
This would still mean that some cells are too big for matrix multiplication so a second trick is used before the cell multiplication: nibbling at cca 1000 random points of the dataset. For a random center row, the similarities to all other rows are computed and all similar points are clustered together (possibly merging existing clusters). This has the effect of pre-clustering most dense points of the dataset (esp. repeated values) - dense clusters have a good chance to be hit with a center, eliminating most of the mass of the cluster (as well as the respective cells). The number of nibble iterations should be tuned according to data (to reasonably decrease the cell size).
To combine the two tricks, a portion of the clustered points (e.g. 10%) together with all the unclustered points are considered for adjacent cell multiplication. The 10% returned points should ensure that the nibbled clusters are linked with any points not hit by the nibble but close to and in effect belonging to the clusters.
Since not all nibbled rows are used in the adjacent cell scalar product, the algorithm may miss few individual cluster connections at nibble ball boundaries, but we found it unlikely in practice.
The algorithm clusters 10000 gaussian points in 30 dimensions in under a second.
Metadata
Release files for silicon-clustering 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| silicon-clustering-0.3.1.tar.gz | 11.9 kB | Without provenance | Details for silicon-clustering-0.3.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| silicon_clustering-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for silicon_clustering-0.3.1-py3-none-any.whl |
| silicon_clustering-0.3.1-py2-none-any.whl | Python 2 | none | any | Details for silicon_clustering-0.3.1-py2-none-any.whl |
Total release size: 45.1 kB
Release files / silicon-clustering-0.3.1.tar.gz
| Download URL | silicon-clustering-0.3.1.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28e94dfbd8d0806436b1222ec8658622d21e08354e957e1b52b8f0cc957dc20a
|
|
BLAKE2b-256 checksum How to use checksums |
330725632217badc10da1bcbff428722b5c6b36dfcfccd4720e570bca0d96fba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / silicon_clustering-0.3.1-py3-none-any.whl
| Download URL | silicon_clustering-0.3.1-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e221d3e68c0a9b62ed42039dfadd54c610f962b313fc15952b76b6a68e4b446
|
|
BLAKE2b-256 checksum How to use checksums |
327a916fe5913e8d9dd02b5d2061e980bfc0ee7305949deaf9d4c94f570d3f17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / silicon_clustering-0.3.1-py2-none-any.whl
| Download URL | silicon_clustering-0.3.1-py2-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
264ceb7e3df1f39813e25a65276a624ec5540df1136f030e4fe7715ccca47f64
|
|
BLAKE2b-256 checksum How to use checksums |
195cf323c6338361548ba082f01369b95b00ac46346eef1103aeb1bcf2094e4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for silicon-clustering 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.