|
| | KMeans (std::size_t k, std::size_t nJobs=0) |
| | Construct a reusable k-means fitter.
|
| | KMeans (const KMeans &)=delete |
| KMeans & | operator= (const KMeans &)=delete |
| | KMeans (KMeans &&)=delete |
| KMeans & | operator= (KMeans &&)=delete |
| | ~KMeans ()=default |
| void | run (const NDArray< T, 2 > &X, std::size_t maxIter=300, T tol=T{1e-4}, std::uint64_t seed=0) |
| | Fit to X.
|
| const NDArray< std::int32_t, 1 > & | labels () const noexcept |
| | Length-n assignment; each entry is in [0, k).
|
| const NDArray< T, 2, Layout::Contig > & | centroids () const noexcept |
| | k x d fitted centroids.
|
| double | inertia () const noexcept |
| | Final inertia: Kahan-summed f64 total of per-point squared distance to assignment.
|
| std::size_t | nIter () const noexcept |
| | Iterations executed before tol or maxIter fired.
|
| bool | converged () const noexcept |
| | True iff the last run stopped because centroid shift fell at or below tol.
|
| void | reset () |
| | Release every scratch buffer. The next run call reallocates against its shape.
|
template<class T, class Algo = kmeans::LloydFusedGemm<T>, class Seeder = kmeans::AutoSeeder<T>>
requires kmeans::LloydStrategy<Algo, T> && kmeans::SeederStrategy<Seeder, T>
class clustering::KMeans< T, Algo, Seeder >
Lloyd-family k-means.
The algorithm and seeder are template parameters with concept constraints. The default instantiation carries LloydFusedGemm<T> and AutoSeeder<T>, the latter picking between greedy k-means++ and AFK-MC2 against workload shape at run time. Callers who want to pin a specific combination spell it out, e.g. KMeans<float, LloydFusedGemm<float>, AfkMc2Seeder<float>>.
- Note
KMeans does NOT own X. The caller must keep the NDArray alive for the lifetime of every run call on this instance. An n_init > 1 harness constructs KMeans once and calls run repeatedly against the same X so policy scratch amortizes across runs at a fixed (n, d, k, nJobs) tuple.
- Template Parameters
-
Definition at line 40 of file kmeans.h.