KmeansOps
KmeansOps<
T> =object
Defined in: kmeans.ts:13
Operations that define a k-means (or k-medoids) problem over an arbitrary value type T.
By swapping computeCentroid, the same generic engine covers: - Standard
k-means (arithmetic mean centroid in Euclidean space) - Circular k-means
(circular mean centroid for angular data such as hue) - K-medoids via
kmedoids (medoid update handled internally — do not pass computeCentroid
there)
Type Parameters
Section titled “Type Parameters”T
Properties
Section titled “Properties”centroidDistance
Section titled “centroidDistance”
readonlycentroidDistance: (a,b) =>number
Defined in: kmeans.ts:36
Distance between two centroid values. Used for the convergence check and in k-medoids update.
Parameters
Section titled “Parameters”T
T
Returns
Section titled “Returns”number
readonlyclone: (centroid) =>T
Defined in: kmeans.ts:47
Returns an independent copy of a centroid value to detect movement across iterations.
Parameters
Section titled “Parameters”centroid
Section titled “centroid”T
Returns
Section titled “Returns”T
computeCentroid
Section titled “computeCentroid”
readonlycomputeCentroid: (pointIndices) =>T
Defined in: kmeans.ts:42
Computes a new centroid from the given set of assigned point indices. For
k-means: arithmetic mean (or circular mean for angular data). Do not
provide this when calling kmedoids — it is supplied internally.
Parameters
Section titled “Parameters”pointIndices
Section titled “pointIndices”number[]
Returns
Section titled “Returns”T
pointValue
Section titled “pointValue”
readonlypointValue: (i) =>T
Defined in: kmeans.ts:15
Returns the value of data point at index i. Used for kmeans++ seeding.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”T
pointWeight?
Section titled “pointWeight?”
readonlyoptionalpointWeight?: (i) =>number
Defined in: kmeans.ts:31
Optional importance weight for data point i. Used only in k-means++
seeding: the sampling probability is proportional to pointWeight(i) × d²(i, nearestCentroid), so high-weight points attract seeds more strongly
than low-weight points at equal distance. Does NOT affect cluster
assignment — that remains nearest-centroid by distance. Default: uniform
weight 1.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”number
squaredDistance
Section titled “squaredDistance”
readonlysquaredDistance: (pointIndex,centroid) =>number
Defined in: kmeans.ts:22
Squared distance from data point i to centroid c. Used in the assignment
step and kmeans++ seeding. The squared form avoids a Math.sqrt in the hot
assignment loop while still producing the same nearest-centroid
assignment.
Parameters
Section titled “Parameters”pointIndex
Section titled “pointIndex”number
centroid
Section titled “centroid”T
Returns
Section titled “Returns”number