|
Clustering
C++20 header-only: DBSCAN, HDBSCAN, k-means.
|
Fused-argmin-GEMM Lloyd driver. More...
#include <clustering/kmeans/policy/lloyd_fused_gemm.h>
Public Member Functions | |
| LloydFusedGemm () | |
| void | run (const NDArray< T, 2, Layout::Contig > &X, NDArray< T, 2, Layout::Contig > ¢roids, std::size_t k, std::size_t maxIter, T tol, math::Pool pool, NDArray< std::int32_t, 1 > &outLabels, double &outInertia, std::size_t &outNIter, bool &outConverged) |
| Run the Lloyd loop against caller-seeded centroids. | |
Static Public Attributes | |
| static constexpr std::size_t | kahanNThreshold = 100000 |
n threshold at which the centroid accumulator switches to Kahan-compensated summation. | |
Fused-argmin-GEMM Lloyd driver.
Runs the Lloyd iteration over caller-seeded centroids: assignment via the fused AVX2 argmin-GEMM hot path at d <= math::defaults::pairwiseArgminMaxD and the chunked materialized fallback above it, label-grouped fold into per-cluster sums (Kahan-compensated at n >= LloydFusedGemm::kahanNThreshold), empty-cluster reseed against the current per-point distance scratch, mean step, and convergence test on the Kahan-summed total squared shift. All scratch buffers live inside the policy instance; no allocation fires between the first assignment call and the convergence check of any iteration once the shape has been warmed.
| T | Element type; float or double. |
Definition at line 98 of file lloyd_fused_gemm.h.
|
inline |
Definition at line 103 of file lloyd_fused_gemm.h.
|
inline |
Run the Lloyd loop against caller-seeded centroids.
| X | Contiguous n x d dataset. Borrowed; caller retains ownership. |
| centroids | k x d centroid matrix. Caller has already populated the rows with the seeder's output; this routine overwrites them in place with the iteration-final values. |
| k | Number of clusters. |
| maxIter | Iteration cap. |
| tol | Convergence tolerance relative to the mean column variance of X (sklearn convention). Internally converted to a sum-of-shift-squared threshold as tol * mean(var(X, axis=0)) and compared against the Kahan-summed per-centroid shift-squared. |
| pool | Parallelism injection. |
| outLabels | Length-n assignment; each entry in [0, k). |
| outInertia | Kahan-summed f64 total of per-point squared distance to assignment. |
| outNIter | Iterations executed before tol or maxIter fired. |
| outConverged | true iff iteration stopped because centroid shift fell at or below tol. |
Definition at line 146 of file lloyd_fused_gemm.h.
|
staticconstexpr |
n threshold at which the centroid accumulator switches to Kahan-compensated summation.
Definition at line 123 of file lloyd_fused_gemm.h.