retrography
8/4/2015 - 7:04 AM

Finding the structural equivalent of a node for matching purposes using CONCOR

Finding the structural equivalent of a node for matching purposes using CONCOR

library(igraph)
library(magrittr)
library(textir)
library(Matrix)

# fetch the network file
download.file("http://www-personal.umich.edu/~mejn/netdata/lesmis.zip", "lesmis.zip", "auto")
unzip("lesmis.zip")

g <- read.graph("lesmis.gml", format = "gml")

adj<-get.adjacency(g)

# this is needed only when the graph is directed -- not in this example
# adj<-rbind2(adj,t(adj))

findMatch <- function(x) {
  concor <- corr(adj, adj[,x])
  bestmatch <- which.max(concor[-x,])
  if (bestmatch >= x) bestmatch = bestmatch + 1 
  personnage2<-get.vertex.attribute(g, "label")[bestmatch]
  personnage1<-get.vertex.attribute(g, "label")[x]
  print(paste(personnage1, personnage2, sep = "~")) 
}

# Closest structural equivalent for Cosette
findMatch(27)
# Closest structural equivalent for Valjean
findMatch(12)