I am getting some unexpected results from some functions of igraph and it is possible that I am misinterpreting the vertex numbers. Eg., the max betweenness measure seems to be from a vertex that is not connected to a single other vertex. Below if my code snippet: require(igraph) my.graph <- graph.adjacency(adjmatrix = my.adj.matrix, mode=c("undirected")) most.between.vert <- colnames(my.adj.matrix)[which(betweenness(graph = my.graph, v=V(my.graph), directed = FALSE) == max(betweenness(graph = my.graph, v=V(my.graph), directed = FALSE))) + 1] sum(my.adj.matrix[most.between.vertext,]) 0 Is there a way to automatically set the vertex name attributes from the row and colnames of the inputted adjacency matrix to graph.adjacency? This would seem like an intuitive feature, but I can't find it documented. In the absence of this feature, how can I make sure that I am setting the vertex name attributes correctly? -- Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, & Mobile & VoiceMail (317) 204-4202 Home (no voice mail please) mwkimpel<at>gmail<dot>com
On Mar 5, 2008, at 1:39 AM, Mark W Kimpel wrote:> I am getting some unexpected results from some functions of igraph and > it is possible that I am misinterpreting the vertex numbers. Eg., the > max betweenness measure seems to be from a vertex that is not > connected > to a single other vertex. Below if my code snippet: > > require(igraph) > my.graph <- graph.adjacency(adjmatrix = my.adj.matrix, mode=c > ("undirected")) > > most.between.vert <- colnames(my.adj.matrix)[which(betweenness(graph > my.graph, v=V(my.graph), directed = FALSE) == max(betweenness(graph > my.graph, v=V(my.graph), directed = FALSE))) + 1]What is the +1 for? Seems to me that this would give you the wrong vertex, since you find the vertex which is the max, and then you ask it to give you the next vertex in the list. Btw, you will likely want to take the betweenness call out, and call it once and store the result, instead of calling it twice (well, assuming the graph is largish). Or even better, use which.max: which.max(betweenness(graph = my.graph, v=V(my.graph), directed = FALSE)) Haris Skiadas Department of Mathematics and Computer Science Hanover College> sum(my.adj.matrix[most.between.vertext,]) > 0 > > > Is there a way to automatically set the vertex name attributes from > the > row and colnames of the inputted adjacency matrix to graph.adjacency? > This would seem like an intuitive feature, but I can't find it > documented. In the absence of this feature, how can I make sure that I > am setting the vertex name attributes correctly? > -- > > Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry > Indiana University School of Medicine > > 15032 Hunter Court, Westfield, IN 46074 > > (317) 490-5129 Work, & Mobile & VoiceMail > (317) 204-4202 Home (no voice mail please) > > mwkimpel<at>gmail<dot>com >
On Wed, Mar 05, 2008 at 02:27:21AM -0500, Charilaos Skiadas wrote: [...]> > Btw, you will likely want to take the betweenness call out, and call > it once and store the result, instead of calling it twice (well, > assuming the graph is largish). Or even better, use which.max: > > which.max(betweenness(graph = my.graph, v=V(my.graph), directed = > FALSE))This is almost good, but there is a catch, in igraph vertices are numbered from zero. So if you want an igraph vertex id, then you need to subtract one from this, i.e.: maxb <- which.max(betweennness(my.graph, directed=FALSE))-1 You can double check it: betweenness(my.graph, maxb, directed=FALSE) Gabor PS. there is also an igraph mailing list, see the igraph homepage at igraph.sf.net> Haris Skiadas > Department of Mathematics and Computer Science > Hanover College >[...] -- Csardi Gabor <csardi at rmki.kfki.hu> UNIL DGM
Mark, graph.adjacency always preserves the order of the vertices, so the vertex at row/column 1 will be vertex #0 in the igraph graph, etc. I'll document this in a minute. This means that you can always do g <- graph.adjacency(A) V(g)$name <- colnames(A) But i completely agree that this should be done by default, i'll do that in the near future. Btw, weighted shortest path calculation (= where the edges have weights or capacities) is only implemented in the development version of igraph. Just in case you're looking for that. Best, Gabor On Wed, Mar 05, 2008 at 01:39:41AM -0500, Mark W Kimpel wrote:> I am getting some unexpected results from some functions of igraph and > it is possible that I am misinterpreting the vertex numbers. Eg., the > max betweenness measure seems to be from a vertex that is not connected > to a single other vertex. Below if my code snippet: > > require(igraph) > my.graph <- graph.adjacency(adjmatrix = my.adj.matrix, mode=c("undirected")) > > most.between.vert <- colnames(my.adj.matrix)[which(betweenness(graph = > my.graph, v=V(my.graph), directed = FALSE) == max(betweenness(graph = > my.graph, v=V(my.graph), directed = FALSE))) + 1] > > sum(my.adj.matrix[most.between.vertext,]) > 0 > > > Is there a way to automatically set the vertex name attributes from the > row and colnames of the inputted adjacency matrix to graph.adjacency? > This would seem like an intuitive feature, but I can't find it > documented. In the absence of this feature, how can I make sure that I > am setting the vertex name attributes correctly? > -- > > Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry > Indiana University School of Medicine > > 15032 Hunter Court, Westfield, IN 46074 > > (317) 490-5129 Work, & Mobile & VoiceMail > (317) 204-4202 Home (no voice mail please) > > mwkimpel<at>gmail<dot>com > > ******************************************************************-- Csardi Gabor <csardi at rmki.kfki.hu> UNIL DGM
Looks like I turned an "off my one error" into an "off by two error" by adding rather than subtracting. Clearly a logic error on my part. Also, which.max is clearly superior as it results in half as many function calls. Thanks guys! As an aside, although igraph may use the C indexing convention, R users and their code, is much more in tune with indexing beginning at 1. Adjusting this in the R interface to igraph may solve many headaches down the road. Mark Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, & Mobile & VoiceMail (317) 204-4202 Home (no voice mail please) mwkimpel<at>gmail<dot>com ****************************************************************** Gabor Csardi wrote:> On Wed, Mar 05, 2008 at 02:27:21AM -0500, Charilaos Skiadas wrote: > [...] >> Btw, you will likely want to take the betweenness call out, and call >> it once and store the result, instead of calling it twice (well, >> assuming the graph is largish). Or even better, use which.max: >> >> which.max(betweenness(graph = my.graph, v=V(my.graph), directed = >> FALSE)) > > This is almost good, but there is a catch, in igraph vertices are > numbered from zero. So if you want an igraph vertex id, then you > need to subtract one from this, i.e.: > > maxb <- which.max(betweennness(my.graph, directed=FALSE))-1 > > You can double check it: > > betweenness(my.graph, maxb, directed=FALSE) > > Gabor > > PS. there is also an igraph mailing list, see the igraph homepage > at igraph.sf.net > >> Haris Skiadas >> Department of Mathematics and Computer Science >> Hanover College >> > [...] >