tomaster: Topological Mode Analysis on Steroids
tomaster implements algorithms for topological mode analysis.
The code is simple to read because it is written in pure Python.
The performance is good thanks to jit compilation with numba.
Usage
>>> from tomaster import tomato
>>> from sklearn import datasets
>>> X, y = datasets.make_moons(n_samples=1000, noise=0.05, random_state=1337)
>>> clusters, _ = tomato(X, k=5, n_clusters=2)
>>> import matplotlib.pyplot as plt
>>> plt.scatter(*X.T, c=clusters)
>>> plt.show()
Installation
pip install tomaster
Testing
pytest
API
def tomato(
points,
*,
k,
tau=None,
n_clusters=None,
relative_tau: bool = True,
keep_cluster_labels: bool = False,
):
"""ToMATo clustering
Parameters
----------
points : np.ndarray
Array of shape (n, dim)
k : int
Number of nearest neighbors to build the graph with
tau : float or None
Prominence threshold. Must not be specified if `n_clusters` is given.
relative_tau : bool
If `relative_tau` is set to `True`, `tau` will be multiplied by the standard deviation of the densities, making easier to have a unique value of `tau` for multiple datasets.
n_clusters : int or None
Target number of clusters. Must not be specified if `tau` is given.
keep_cluster_labels : bool
If False, converts the labels to make them contiguous and start from 0.
Returns
-------
clusters : np.ndarray
Array of shape (n,) containing the cluster indexes.
tau : float
Prominence threshold. Only present if `n_clusters` was given.
"""
def tomato_img(
img: np.ndarray, *, spatial_weight: float = 0, lab_space: bool = True, **kwargs
):
"""ToMATo for images
Parameters
----------
img : np.ndarray
Image of shape (h, w) or (h, w, 3)
spatial_weight : float
Importance of the pixel positions in the distance function
lab_space : bool
If True, converts color images to the CIE L*a*b color space (<https://en.wikipedia.org/wiki/CIELAB_color_space>)
see tomato() for other arguments.
Returns
-------
clusters : np.ndarray
Array of shape (h, w) containing the cluster indexes.
"""
References
-
Chazal, Frédéric, Leonidas J. Guibas, Steve Y. Oudot, and Primoz Skraba. "Persistence-based clustering in riemannian manifolds." Journal of the ACM (JACM) 60, no. 6 (2013): 41. [pdf]
-
Reference implementations: https://geometrica.saclay.inria.fr/data/ToMATo/, https://geometrica.saclay.inria.fr/data/Steve.Oudot/clustering/
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tomaster-0.0.1.tar.gz.
File metadata
- Download URL: tomaster-0.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/2.0.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1205533476684dfa5eb6a8edc2086775a20cb98890f599907eefcfa0df6261ef
|
|
| MD5 |
61a0a553d92fd48601d6708ce58ac617
|
|
| BLAKE2b-256 |
58b461e9f1196d2f3ed945563ae142386a6d53f8ef6198a391f4b9a46c48c3e3
|
File details
Details for the file tomaster-0.0.1-py3-none-any.whl.
File metadata
- Download URL: tomaster-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/2.0.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55eb1abe45ecdc61af3541e504d8b777e1c94a8ae5ca7286cfc504e95645af03
|
|
| MD5 |
0e74b4a79b25ff025efface75236a1f7
|
|
| BLAKE2b-256 |
0ff4cbd3a550583b8acd7e13cf660b55e9b93a7faaed390000cc613a1cff5cd5
|