spectralClustering: Spectral clustering

View source: R/codeSpectral.R

spectralClusteringR Documentation

Spectral clustering

Description

Perform spectral clustering thanks to a similarity matrix.

Usage

spectralClustering(
  sim,
  K,
  nruns = 1,
  test.dim = FALSE,
  projection = "Ng",
  post.norm = "sphere",
  clustering = "kmeans",
  max.dim = 30,
  add.1 = FALSE
)

Arguments

sim

similarity matrix.

K

number of clusters.

nruns

number of random sets.

test.dim

boolean, only used to test dimensions (setting the number of left singular vectors to be computed).

projection

character: final data projection. Must be 'Ng' (default), 'LPP', or 'AFC'.

post.norm

character: final data normalization. Must be 'sphere' (default) or 'Shi'.

clustering

character: clustering method in the spectral space. Must be 'kmeans' (default) or 'pam'.

max.dim

maximal number of dimensions for the computation of left sigular vectors.

add.1

boolean : if TRUE add a column to the matrix containing the eigenvectors of the similarity matrix equal to 1/sqrt(nrow(similarity matrix))

Details

spectralClustering returns a partition obtained by spectral clustering

Value

The function returns a list containing:

label

vector of labels.

medoids

matrix of cluster centers in the space of the K first normalized eigenvectors.

id.med

vector containing the medoids indices.

x

matrix containing, in columns, the eigenvectors of the similarity matrix.

eigen.val

vector containing the eigenvalues of the similarity matrix.

cluster.info

some statistics on each cluster.

ncp

number of left singular vectors computed.

References

A. Ng, M. Jordan, Y. Weiss, On spectral clustering: Analysis and an algorithm, Neural Inf. Process. Systems NIPS14 (2002), pp. 849-856.

See Also

spectralClusteringNg

Examples

dat <- rbind(matrix(rnorm(100, mean = 0, sd = 0.3), ncol = 2), 
           matrix(rnorm(100, mean = 2, sd = 0.3), ncol = 2), 
           matrix(rnorm(100, mean = 4, sd = 0.3), ncol = 2))

sim <- computeGaussianSimilarity(dat, 1)
res <- spectralClustering(sim, K=3)

plot(dat[,1], dat[,2], type = "p", xlab = "x", ylab = "y", 
col = res$label, main = "Initial features space")
plot(res$x[,1], res$x[,2], type = "p", xlab = "2nd eigenvector", 
	ylab = "3rd eigenvector", col = res$label, main = "Spectral embedding")


RclusTool documentation built on Aug. 29, 2022, 9:07 a.m.