SriniShine
SriniShine

Reputation: 1139

How to create a list of igraph graphs from .graphml files in R

I'm trying to execute the CalculateVertexHistKernel(G) in the graphkernels R package method to compute the similarity between two graphs.

G is a list of igraph graphs. How do I create a igraph list from a set of graphml files?

Upvotes: 0

Views: 272

Answers (1)

SriniShine
SriniShine

Reputation: 1139

Below is the code for building a list of igraph graphs for existing .graphml files. graphkernals work with only (positive) numerical values. Hence I had to replace the operators with numerical codes. I have used (* == 1). Otherwise the and the function CalculateVertexHistKernel(G) crashes.

#loading the files
g1 <- read.graph("15_4.graphml", format = "graphml")
g2 <- read.graph("30_2.graphml", format = "graphml")

#replacing * with 1
V(G[[1]])$label
[1] NaN  15   4 #NaN is the *
V(G[[2]])$label
[1] NaN  30   2

V(G[[1]])$label[1] <- 1
V(G[[2]])$label[1] <- 1

#creating the list
gList = list(g1,g2)

#computing similarity
k<-CalculateVertexHistKernel(gList)

Author of the package Dr. Mahito Sugiyama provided this solution.

Upvotes: 1

Related Questions