hierarchicalCluster
hierarchicalCluster(
n,getDistance,threshold,options?):number[][]
Defined in: hierarchical-cluster.ts:38
Agglomerative hierarchical clustering with selectable linkage.
Pre-computes a full n×n pairwise distance matrix and uses the Lance–Williams recurrence to update inter-cluster distances after each merge — O(n) per merge instead of recomputing from raw point pairs.
Complexity: O(n²) space; O(n³) time in the worst case (n−1 merges × O(n²) scan). Acceptable for n up to a few hundred (e.g. palette entries across a gallery).
Parameters
Section titled “Parameters”number
Number of items (indexed 0 … n-1).
getDistance
Section titled “getDistance”(i, j) => number
Pairwise distance between original items by index.
threshold
Section titled “threshold”number
Merge threshold: cluster pairs whose inter-cluster distance is ≥ this value are not merged.
options?
Section titled “options?”Optional linkage selection. Default: "average".
Returns
Section titled “Returns”number[][]
Array of clusters; each cluster is an array of original indices.