[R] Help

David A Richmond richmond at saintmarys.edu
Sun Apr 21 23:15:21 CEST 2002


On Fri, 12 Apr 2002, Ambrosini Alessandro wrote:

> I have an adjacency matrix and I want to obtain a matrix of the minimum
> paths between the nodes. Thank you
> Alessandro Ambrosini

In my experience "geodist" in the sna package is rather slow. Compare its
system time on a 100x100 adj matrix to a routine that doesn't rely quite
so much on loops:

> system.time(graph.geod(a) -> result)
[1] 0.08 0.00 0.18 0.00 0.00
> system.time(geodist(a) -> result2)
[1]  78.58   0.00 184.73   0.00   0.00

(this test was done on a G3 iMac running os X/R 1.4.0)

here is the 'meat' of graph.geod()

graph.geod <- function(dat) {
	d <- dim(dat)
	dists <- dat
	dat2 <- dat
	for (i in 2:d[1]) {
		dat2 <- dat2 %*% dat
		dists2 <- dists + (i*(dat2 != 0) * !dists)
		if (all(dists==dists2)) break
		dists <- dists2
	}
	return(dists)
}


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|David Richmond                It works on a          |
+ Dept. of Sociology          complex scientific      +
|Saint Mary's College          principle, known as    |
+ Notre Dame, IN 46556               "pot luck."      +
|574-284-4517                    - The Doctor         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list