math.stats.kmeans

centroid

added in 3.0

(centroid ps)

finds the central position of a group of points

(centroid [3 3 4 4 5 5 6 6]) => 9/2 9/2

cluster

added in 3.0

(cluster ps centroids)

takes an array centroids and groups points based upon closest distance

(cluster [0 0 1 1 2 2 3 3 4 4 5 5 6 6] [1 1 4 4]) => [[0 0 1 1 2 2] [3 3 4 4 5 5 6 6]]

distance2

added in 3.0

(distance2 p0 pc)

sum of squared distances between two points

(distance2 1 3 5 2 4 6) => 3

initial-centroids

added in 3.0

(initial-centroids ps k)

finds a set of centroids from the initial set of points

k-means

added in 3.0

(k-means ps k)(k-means ps k max-steps)

clusters points together based on the number of groups specified

(set (k-means [0.2 0.4 0.2 0.3 0.3 0.4 1.2 0.4 1.1 0.3 2.3 0.4] 2)) => (any #{[0.2 0.4 0.2 0.3 0.3 0.4] [1.2 0.4 1.1 0.3 2.3 0.4]} #{[0.2 0.4 0.2 0.3 0.3 0.4 1.2 0.4 1.1 0.3] 2.3 0.4})

min-index

added in 3.0

(min-index p0 centroids)

finds the index of the centroid closest to p0

(min-index 0 0 [-1 -1 0.5 0.5 1 1]) => 1