library(igraph)
# Generating a set of graphs with 3 groups
groups = rep(-1,60)
groups[1:20] = 1
groups[21:40] = 2
groups[41:60] = 3
names(groups) = as.character(1:60)
# A first set with a few links between groups 1 and 3
gList = c()
for(i in 1:5){
pm <- rbind( c(0, .5, 0.05), c(0, 0, 0.5), c(0,0,0) )
graphLoc <- sample_sbm(60, pref.matrix=pm, block.sizes=c(20,20,20), directed=TRUE)
V(graphLoc)$name = as.character(1:60)
gList = c(gList,list(graphLoc))
}
# A second set with many links between groups 1 and 3
for(i in (6:10)){
pm <- rbind( c(0, .5, .5), c(0, 0, 0.5), c(0,0,0) )
graphLoc <- sample_sbm(60, pref.matrix=pm, block.sizes=c(20,20,20), directed=TRUE)
V(graphLoc)$name = as.character(1:60)
gList = c(gList,list(graphLoc))
}
names(gList) = LETTERS[1:10]
# Computing different embeddings and
usermfrow <- par()$mfrow
par(mfrow=c(2,2))
embd <- embedding(gList, method="metric2vec")
pca <- prcomp(embd, rank=2)$x
plot(pca, main="metric2vec")
text(x=pca[,1], y=pca[,2], labels=rownames(embd), pos=2, col=c(rep("blue",5),rep("red",5)))
embd <- embedding(gList, method="motif2vec")
pca <- prcomp(embd, rank=2)$x
plot(pca, main="motif2vec")
text(x=pca[,1], y=pca[,2], labels=rownames(embd), pos=2, col=c(rep("blue",5),rep("red",5)))
embd <- embedding(gList, method="shortestpath2vec")
pca <- prcomp(embd, rank=2)$x
plot(pca, main="shortestpath2vec")
text(x=pca[,1], y=pca[,2], labels=rownames(embd), pos=2, col=c(rep("blue",5),rep("red",5)))
embd <- embedding(gList, method="shortestpath2vec", groups)
pca <- prcomp(embd, rank=2)$x
plot(pca, main="shortestpath2vec_group")
text(x=pca[,1], y=pca[,2], labels=rownames(embd), pos=2, col=c(rep("blue",5),rep("red",5)))
par(mfrow=usermfrow)
Run the code above in your browser using DataLab