edgeWeights of a distGraph object
1
0
Entering edit mode
Burak Kutlu ▴ 140
@burak-kutlu-3941
Last seen 10.2 years ago
Hi I have a question (hopefully clear enough) on the edge weights when we construct the distGraph as in the example below; Is there a way to populate the edgeWeights with the distance values ? Thanks! -burak x <- rnorm(26) names(x) <- letters library(stats) d1 <- dist(x) g1 <- new("distGraph", Dist=d1) g1 distGraph with 26 nodes -- Burak Kutlu, PhD. Research Scientist Hood Lab Institute for Systems Biology
• 693 views
ADD COMMENT
0
Entering edit mode
@vincent-j-carey-jr-4
Last seen 9 weeks ago
United States
Strictly speaking you cannot populate edgeWeights because there is no component of the representation called "edgeWeights". edgeWeights() is a method that returns weight information. It may seem natural to have the edgeWeights method return the distances used to define the distGraph instance, but one can think of situations in which weights are an attribute distinct from edge lengths (inter-node distances) so the software doesn't make this identification. I will answer a slightly different question by attending not to the representation (populating weights) but to a use case: suppose I want to use RBGL's dijkstra.sp to compute shortest paths among nodes using the distances defining the distGraph instance as the edge lengths from which path lengths are computed. The interface for dijkstra.sp is > args(dijkstra.sp) function (g, start = nodes(g)[1], eW = unlist(edgeWeights(g))) NULL so we see that it would be nice to have an edgeWeights method for distGraph instances that uses the distances. (Of course all it wants is a vector that can easily be constructed from the Dist slot contents but let's see about making the method anyway so that the defaults for dijkstra.sp can be used.) Here is a method that does it: setMethod("edgeWeights", c("distGraph", "missing"), function (object, index, ..., attr = "weight", default = 1, type.checker = is.numeric) { m = as.matrix(Dist(object)) lapply(1:length(nodes(object)), function(i) m[i, -i]) }) Before introducing this code (which can probably be improved upon), we have > dijkstra.sp(g1) $distances a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 $penult a b c d e f g h i j k l m n o p q r s t u v w x y z 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 $start a 1 an obvious solution based on the default weights, which have no relation to the distance data. After introducing the method, we have > dijkstra.sp(g1) $distances a b c d e f 0.000000000 1.120608862 1.504178544 1.820095043 0.832708593 0.003969415 g h i j k l 0.164740552 1.158955387 2.527352266 0.813731035 0.562805814 0.673491956 m n o p q r 0.277304598 1.953836429 2.796151581 1.721397223 1.580663992 1.152378113 s t u v w x 1.744418257 1.547055821 0.858686442 1.647301232 0.712820326 0.331892402 y z 1.575280653 1.358322322 $penult a b c d e f g h i j k l m n o p q r s t u v w x y z 1 1 1 23 1 1 1 1 22 11 1 1 1 22 22 23 23 1 23 1 1 26 11 1 1 23 $start a 1 which seems to be the intended solution but should be checked. It is a fair question whether or not this edgeWeights method is reasonable for distGraph instances. But even if it must be transiently defined, it may be a more appropriate way of addressing whatever problem underlies your query about how to "populate the edgeWeights". You can populate the edgeData in such a way that the use case above can be solved without any new methods -- but I find that will involve me with a study of infrastructure that I would rather not undertake, and this solution would be frail to alterations of the class definition. The solution I give depends only on the stability of behavior of Dist() and nodes() for distGraph instances, and those should not change (not much, anyway :)). On Thu, May 13, 2010 at 4:39 PM, Burak Kutlu <bkutlu@systemsbiology.org>wrote: > Hi > I have a question (hopefully clear enough) on the edge weights when we > construct the distGraph as in the example below; > Is there a way to populate the edgeWeights with the distance values ? > Thanks! > -burak > > x <- rnorm(26) > names(x) <- letters > library(stats) > d1 <- dist(x) > g1 <- new("distGraph", Dist=d1) > > g1 > distGraph with 26 nodes > > > > -- > Burak Kutlu, PhD. > Research Scientist > Hood Lab > Institute for Systems Biology > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT

Login before adding your answer.

Traffic: 645 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6