Wikipedia / Single-linkage clustering
Wikipedia / Single-linkage clustering
In statistics, single-linkage clustering is one of several methods of hierarchical clustering. It is based on grouping clusters in bottom-up fashion (agglomerative clustering), at each step combining two clusters that contain the closest pair of elements not yet belonging to the same cluster as each other.
This method tends to produce long thin clusters in which nearby elements of the same cluster have small distances, but elements at opposite ends of a cluster may be much farther from each other than two elements of other clusters. For some classes of data, this may lead to difficulties in defining classes that could usefully subdivide the data. However, it is popular in astronomy for analyzing galaxy clusters, which may often involve long strings of matter; in this application, it is also known as the friends-of-friends algorithm.
Overview of agglomerative clustering methods
In the beginning of the agglomerative clustering process, each element is in a cluster of its own. The clusters are then sequentially combined into larger clusters, until all elements end up being in the same cluster. At each step, the two clusters separated by the shortest distance are combined. The function used to determine the distance between two clusters, known as the linkage function, is what differentiates the agglomerative clustering methods.
In single-linkage clustering, the distance between two clusters is determined by a single pair of elements: those two elements (one in each cluster) that are closest to each other. The shortest of these pairwise distances that remain at any step causes the two clusters whose elements are involved to be merged. The method is also known as nearest neighbour clustering. The result of the clustering can be visualized as a dendrogram, which shows the sequence in which clusters were merged and the distance at which each merge took place.
Mathematically, the linkage function – the distance D(X,Y) between clusters X and Y – is described by the expression
where X and Y are any two sets of elements considered as clusters, and d(x,y) denotes the distance between the two elements x and y.
Naive algorithm
The following algorithm is an agglomerative-th clustering. A cluster with sequence number m is denoted (m.
The single linkage algorithm is composed of the following steps:
.
where the minimum is over all pairs of clusters in the current clustering.
.
If all objects are in one cluster, stop. Else, go to step 2.
Working example
This working example is based on a JC69 genetic distance matrix computed from the 5S ribosomal RNA sequence alignment of five bacteria: Bacillus subtilis), Bacillus stearothermophilus), Lactobacillus viridescens), Acholeplasma modicum), and Micrococcus luteus).
First step
First clustering
of pairwise distances between them:
, so we cluster elements and .
First branch length estimation
Let denote the node to which and ensures that elements and are equidistant from . This corresponds to the expectation of the ultrametricity hypothesis. The branches joining and to (see the final dendrogram)
First distance matrix update
(see below), reduced in size by one row and one column because of the clustering of with correspond to the new distances, calculated by retaining the minimum distance and each of the remaining elements:
are not affected by the matrix update as they correspond to distances between elements not involved in the first cluster.
Second step
Second clustering
: with element and with element .
Second branch length estimation
Let , and are now connected. Because of the ultrametricity constraint, the branches joining or to , and to , and also to are equal and have the following total length:
We deduce the missing branch length:
Second distance matrix update
with and with :
Final step
matrix is:.
then have lengths:
We deduce the remaining branch length:
The single-linkage dendrogram
:
, its deepest node.
Other linkages
The naive algorithm for single linkage clustering is essentially the same as Kruskal's algorithm for minimum spanning trees. However, in single linkage clustering, the order in which clusters are formed is important, while for minimum spanning trees what matters is the set of pairs of points that form distances chosen by the algorithm.
Alternative linkage schemes include complete linkage clustering, average linkage clustering (UPGMA and WPGMA), and Ward's method. In the naive algorithm for agglomerative clustering, implementing a different linkage scheme may be accomplished simply by using a different formula to calculate inter-cluster distances in the algorithm. The formula that should be adjusted has been highlighted using bold text in the above algorithm description. However, more efficient algorithms such as the one described below do not generalize to all linkage schemes in the same way.
Faster algorithms
. that contains both item, maps item, maps item. The SLINK algorithm then loops over the items, one by one, adding them to the representation of the clustering.
An alternative algorithm, running in the same optimal time and space bounds, is based on the equivalence between the naive algorithm and Kruskal's algorithm for minimum spanning trees. Instead of using Kruskal's algorithm, one can use Prim's algorithm.