Learn R Programming

statGraph (version 0.5.1)

graph.kmeans: K-means for Graphs

Description

graph.kmeans clusters graphs following a k-means algorithm based on the Jensen-Shannon divergence between the spectral densities of the graphs.

Usage

graph.kmeans(x, k, nstart = 2)

Value

a vector of the same length of x containing the clusterization labels.

Arguments

x

a list containing the graphs or their adjacency matrices to be clustered.

k

an integer specifying the number of clusters.

nstart

the number of trials of k-means clusterizations. The algorithm returns the clusterization with the best silhouette.

References

MacQueen, James. "Some methods for classification and analysis of multivariate observations." Proceedings of the fifth Berkeley symposium on mathematical statistics and probability. Vol. 1. No. 14. 1967.

Lloyd, Stuart. "Least squares quantization in PCM." IEEE transactions on information theory 28.2 (1982): 129-137.

Examples

Run this code
set.seed(42)
g <- list()
for(i in 1:5){
  g[[i]] <- igraph::sample_gnp(30, p=0.2)
}
for(i in 6:10){
  g[[i]] <- igraph::sample_gnp(30, p=0.5)
}
res <- graph.kmeans(g, k=2, nstart=2)
res

Run the code above in your browser using DataLab