Description Usage Arguments Value Author(s) Examples
Making the kNN graph from given distance matrix.
1 |
DM |
A distance matrix. |
k |
Number of neighbers |
symm |
If TRUE, then the connectivity matrix is symmetrized. |
weight |
If TRUE, then the weighted kNN graph is created. |
The adjacency matrix of a kNN graph.
Yoshikazu Terada
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #Create a toy data
x <- seq(-5,5,by=1)
y <- seq(1,6,by=1)
hx1 <- seq(-3.5,-1.5,by=0.5)
hx2 <- seq(1.5,3.5,by=0.5)
hy <- seq(2.5,4.5,by=0.5)
D1 <- matrix(0,66,2)
for(i in 1:11){
for(j in 1:6){
D1[i+11*(j-1),] <- c(x[i],y[j])
}
}
D2n <- matrix(0,25,2)
D2p <- matrix(0,25,2)
for(i in 1:5){
for(j in 1:5){
D2n[i+5*(j-1),] <- c(hx1[i],hy[j])
D2p[i+5*(j-1),] <- c(hx2[i],hy[j])
}
}
D2n <- D2n[-c(7,9,17,19),]
D2p <- D2p[-c(7,9,17,19),]
Data <- rbind(D1,D2n,D2p)
Data <- scale(Data[order(Data[,1]),], scale=FALSE)
#Visualization of Data
plot(Data,pch=20,xlab="",ylab="",cex=1,col=rainbow(108,start=.7,end=.9),
xlim=c(-7,7),ylim=c(-7,7))
#Creating a k-NN graph based on Data
DM <- as.matrix(dist(Data))
ADM <- make.kNNG(DM,k=25)
|
Loading required package: MASS
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.