kmeans
kmeans<
T>(n,k,ops,options?):KmeansCluster<T>[]
Defined in: kmeans.ts:96
Generic k-means clustering.
Partitions n data points into at most k clusters by iterating: 1. Assignment
— each point is assigned to its nearest centroid. 2. Update — each centroid
is recomputed from its assigned points via ops.computeCentroid.
Initial centroids are chosen via k-means++ (D² weighting), which spreads seeds across the data distribution and reduces the risk of degenerate local minima.
By supplying a circular-mean implementation of computeCentroid, this
function also serves as circular k-means for angular data (e.g. OKLch hue).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”number
Number of data points (indexed 0 … n-1).
number
Desired number of clusters; clamped to min(k, n).
KmeansOps<T>
Problem-specific operations.
options?
Section titled “options?”Optional algorithm tuning.
Returns
Section titled “Returns”KmeansCluster<T>[]
One entry per non-empty cluster, with its final centroid and assigned indices.