% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spectral.R
\name{spectral_clustering}
\alias{spectral_clustering}
\title{Spectral clustering of an affinity matrix}
\usage{
spectral_clustering(affinity, k = NULL, max_k = 10, nstart = 10)
}
\arguments{
\item{affinity}{A symmetric \eqn{n \times n} non-negative similarity/affinity
matrix over the objects.}

\item{k}{Number of clusters. If \code{NULL}, chosen by the largest eigengap
of the normalised Laplacian (searched over \code{2:max_k}).}

\item{max_k}{Upper bound for the eigengap search when \code{k = NULL}.}

\item{nstart}{Number of k-means restarts.}
}
\value{
A list with \code{cluster} (named integer labels), \code{k} and the
spectral \code{embedding}.
}
\description{
Normalised (Ng-Jordan-Weiss) spectral clustering. Given a symmetric,
non-negative affinity matrix it forms the normalised Laplacian, embeds the
objects in the space of its leading eigenvectors and applies k-means.
}
\examples{
set.seed(1)
X <- rbind(matrix(rnorm(20 * 5, 0), 20), matrix(rnorm(20 * 5, 6), 20))
A <- exp(-as.matrix(dist(X))^2 / 2)
spectral_clustering(A, k = 2)$cluster[1:5]
}
\references{
Ng, A. Y., Jordan, M. I. & Weiss, Y. (2002). On spectral
clustering: analysis and an algorithm. NIPS 14.
}
\seealso{
\code{\link{NEMO}}, \code{\link{SNF}}
}
