igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] as.undirected strips edge weights?


From: Gábor Csárdi
Subject: Re: [igraph] as.undirected strips edge weights?
Date: Wed, 21 Oct 2009 11:25:49 +0200

Carson,

On Wed, Oct 21, 2009 at 8:32 AM, address@hidden
<address@hidden> wrote:
> Dear igraph-help,
>
> I am attempting to compute eigenvector centrality on a weighted graph.
> The evcent function provides a warning concerning "Weighted directed
> graph in eigenvector centrality." Assuming that the centrality
> function is not equipped to handle directed graphs,

the error message is not the best, but the manual says that:
"graph: The input graph. It might be directed, but it will be treated
as undirected anyway."
and it is right. Even if you supply a directed graph, edge directions
are not used. This is true for the 0.5.x version, but will change in
the 0.6 version.

> I have been
> working to provide it with an undirected graph with weights. My code
> now is as follows:
>
> centralnode <- function(csvfile)
>  { # read weighted graph
>    m <- as.matrix(read.csv(csvfile, header=F))
>    g <- graph.adjacency(m, weighted=TRUE)
>    g <- as.undirected(g) # this line strips the E(g)$weight
> information?
>    wv <- normalize(E(g)$weight)
>    return(which.max(evcent(g, weights=wv)$vector))
>  }
>
> What I am struggling with is the line as.undirected(g)...it removes
> the edge weight information.

Yes, it does, because it is not clear how to keep it if multiple
directed edges are mapped to the same undirected edge. We could sum
them up, but it would not be a very flexible solution.

> Is there some sort of work-around?

You can convert the graph to an edge list, add the weights as a third
column, merge the edges and the weights any way you want and then
convert it back to an igraph graph. Not very elegant, I agrree.

Best,
Gabor

> I
> tried "as.undirected2" which I found in the igraph source, but it
> appears that e(g)$weight is not a vertex attribute.
>
> Thanks in advance,
>
> -carson-
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>



-- 
Gabor Csardi <address@hidden>     UNIL DGM




reply via email to

[Prev in Thread] Current Thread [Next in Thread]