set.seed(1987)
##Generates a data matrix of dimension 50X13
n=50; m=13
x <- matrix(runif(n*m, min = -5, max = 10), nrow=n, ncol=m)
##Computes a distance matrix of x.
library("stats")
d <- base::as.matrix(stats::dist(x, method="euclidean"))
##Generates complete graph (CG) without suggested.k parameter
cg <- generate.complete.graph(1:nrow(x),d)
##Generates kNN graph
knn <- generate.knn(cg)
##Visualizing kNN graph
plot(knn$knn.graph,
main=paste("kNN \n k=", knn$k, sep=""))
##Generates complete graph (CG) with suggested.k parameter
cg <- generate.complete.graph(1:nrow(x),d)
##Generates kNN graph
knn <- generate.knn(cg, suggested.k=4)
##Visualizing kNN graph
plot(knn$knn.graph,
main=paste("kNN \n k=", knn$k, sep=""))
Run the code above in your browser using DataLab