Skip to content

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)

T

readonly centroidDistance: (a, b) => number

Defined in: kmeans.ts:36

Distance between two centroid values. Used for the convergence check and in k-medoids update.

T

T

number


readonly clone: (centroid) => T

Defined in: kmeans.ts:47

Returns an independent copy of a centroid value to detect movement across iterations.

T

T


readonly computeCentroid: (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.

number[]

T


readonly pointValue: (i) => T

Defined in: kmeans.ts:15

Returns the value of data point at index i. Used for kmeans++ seeding.

number

T


readonly optional pointWeight?: (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.

number

number


readonly squaredDistance: (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.

number

T

number