Begin

1. Compute A, the *n* × *n* affinity matrix

2. Get the eigensystem of A:

> Compute the first k eigenvectors of its Laplacian matrix to define a feature vector for each object:

> Set U = *n* × k matrix containing the normalized eigenvectors of the k largest eigenvalues of A in its columns

3. Apply *k*-means on the row space of U to find the k cluster End

Formally, let *n* be the number of data points to be grouped and *W* = *wi*, *<sup>j</sup>nxn* the weight matrix where each *wi*, *j* is the similarity between *xi* and *xj* data points. So, a clustering problem can be formulated into the minimum cut problem, i.e.,

$$q^\* = \arg\min\_{q \in \{-1, 1\}^n} \sum\_{i, \ j=1}^n w\_{i, \ j} \left(q\_i - q\_j\right)^2 = q^T L q \tag{7}$$

where *q* = (*q*1, *q*2, ... , *qn*) is a vector for binary memberships and if we express a partition (A, B) as the vector *qi*, each *qi* can be 1 if *i* ∈ *A* or −1 *i* ∈ *B*. *L* is the Laplacian matrix, defined as *L* = *D* − *W*, where *D* = [*di*, *<sup>i</sup>*]*nxn* is a diagonal matrix with each element *di*, *i* = δ*i*, *j* ∑*nj*=<sup>1</sup> *wi*, *j*.

For grouping into several classes, the objective function can be defined as:

$$J\_{norm\\_nc}(q) = \sum\_{z=1}^{k} \sum\_{z' \neq z} \frac{\mathbb{C}\_{z,\ z'}\left(\mathbf{q}\right)}{D\_{z}\left(\mathbf{q}\right)}\tag{8}$$

where *k* is the number of clusters, *q* ∈ {1, 2, . . . , *<sup>k</sup>*}*<sup>n</sup>*, *Cz*, *z*, = ∑*n i*, *j*=1 <sup>δ</sup>(*qi*, *z*)<sup>δ</sup> *qj*, *z*, *wi*, *j* and *Dz* = ∑*n i*=1 ∑*n j*=1 <sup>δ</sup>(*qi*, *<sup>z</sup>*)*wi*, *j*. However, efficiently finding the solution that minimizes the above equation is quite difficult. Therefore, a common strategy is to first ge<sup>t</sup> the smallest *v* eigen-vectors of the Laplacian matrix *L* (excluding the one with zero eigen-value), and project the data points in the low-dimensional space spanning the *v* eigen-vectors. Then, a standard clustering algorithm, such as *k*-means, is applied to the cluster data points in this low-dimensional space [14].

In short terms, spectral clustering is based on two main steps: first embedding the data points in a space in which clusters are more "obvious" (using the eigenvectors of a Gram matrix), and then applying a classical clustering algorithm such as *k*-means [15]. The affinity matrix *M* is formed using a kernel such as the Gaussian kernel. To obtain *m* clusters, the first *m* principal eigenvectors of *M* are computed, and *k*-means is applied on the unit-norm coordinates. So, if we consider a data set which consists of *n* data points, the time complexity of spectral clustering is *O n*<sup>3</sup> , which makes it prohibitive for large-scale data application [16]. Moreover, there is evidence [13] that spectral clustering can be quite sensitive to changes in the similarity graph so noisy datasets can cause problems.

Choosing the number *k* of clusters is a general problem for all clustering algorithms, and just like *k*-means and GMM, it requires the number of clusters to be specified.
