Documentation
¶
Overview ¶
Package clustering is a require()-able host module exposing unsupervised clustering algorithms (k-means, DBSCAN, agglomerative/hierarchical, and mean shift) to .lsc code. Data is passed as an array of points, where a point is itself an array of numbers; results report 1-based cluster ids so they index naturally from Lua.
Index ¶
Constants ¶
const (
Noise = 0
)
DBSCAN labels. Cluster ids start at 1; Noise marks points that fall in no dense region, and undefined is the internal "not yet visited" state.
Variables ¶
This section is empty.
Functions ¶
func DBSCAN ¶
DBSCAN performs density-based spatial clustering. A point is a core point if at least minPts points (including itself) lie within eps; clusters grow by transitively absorbing the neighbourhoods of core points. Points reachable from no core point are labelled Noise (0).
Returned labels are 1-based cluster ids, with 0 reserved for noise. Unlike k-means, DBSCAN discovers the cluster count on its own and finds arbitrarily shaped clusters.
func Hierarchical ¶
Hierarchical performs bottom-up agglomerative clustering: every point starts as its own cluster and the two closest clusters are merged repeatedly until exactly k clusters remain. The pairwise point-distance matrix is precomputed once; linkage decides how cluster-to-cluster distance is derived from it.
This is an O(n^3) implementation suited to small/medium inputs. Returned labels are 1-based cluster ids.
func RegisterClusteringPreload ¶
RegisterClusteringPreload installs the loader under package.preload so the module table is built lazily on the first require("clustering").
Types ¶
type KMeansResult ¶
KMeansResult bundles the converged cluster centers with the per-point cluster assignment. Assignments are 0-based indices into Centers.
type Linkage ¶
type Linkage int
Linkage selects how the distance between two clusters is measured during agglomerative merging.
func ParseLinkage ¶
ParseLinkage maps a string name to a Linkage, defaulting to average.
type MeanShiftResult ¶
MeanShiftResult bundles the discovered modes (cluster centers) with the per-point assignment. Like DBSCAN, mean shift discovers the number of clusters on its own — here it is governed by the bandwidth.
func MeanShift ¶
func MeanShift(data []Point, bandwidth float64, maxIter int) MeanShiftResult
MeanShift is a centroid-seeking, non-parametric clusterer. Every point is iteratively shifted toward the weighted mean of its neighbourhood (using a Gaussian kernel parameterised by bandwidth) until convergence; points that settle on the same mode form a cluster.
Smaller bandwidths yield more, tighter clusters. Returned assignments are 1-based cluster ids.