Getting started#
Install#
Thetan is built from source. The Cython extensions need a C compiler
(GCC 8 or later, Clang, or MSVC 2019 or later). On macOS, install
libomp with Homebrew to get OpenMP.
git clone https://github.com/thetan-ai/thetan.git
cd thetan
pip install -r requirements/build.txt
pip install --no-build-isolation .
This installs thetan with NumPy as its only requirement. A few modules need more:
Module |
Needs |
|---|---|
|
scikit-learn |
|
scipy, scikit-learn |
|
scikit-image |
|
matplotlib, scikit-learn |
Install them all with:
pip install -r requirements/optional.txt
Cluster an array#
The clustering functions take a 2D array of shape (n_samples, n_features).
The Cython kernels read it as C-contiguous float64, so convert it first:
import numpy as np
from thetan import TB
rng = np.random.default_rng(0)
centres = np.array([[0, 0], [10, 0], [5, 8]])
points = np.vstack([c + rng.standard_normal((500, 2)) for c in centres])
X = np.ascontiguousarray(points, dtype=np.float64)
centroids, labels = TB(X, theta=4.0)
TB returns two arrays:
centroidsShape
(n_clusters, n_features). The mean of the points in each cluster.labelsShape
(n_samples,). The cluster index of each point, in the order ofX.
Here len(centroids) is 3: TB found the three clusters without being told
how many there are.
TB shuffles the data internally with NumPy’s global random state. Call
np.random.seed first when you need the same result on every run.
The main functions#
Name |
Alias |
What it does |
|---|---|---|
|
Two self-correcting passes. The method to use by default. |
|
|
One pass. Fast and online, but depends on the order of the data. |
|
|
One pass seeded with prior centroids. |
|
TB followed by DBSCAN on the centroids, for non-convex clusters. |
||
Any of the metrics between every pair of rows of two arrays. |
All of them are importable from the top-level package:
from thetan import TB, TS, tbscan, distance_matrix
Next steps#
From TS to TB explains what the two passes do.
Choosing θ shows how to pick θ.
The gallery has complete, runnable examples.