structdist
returns the structural distance between the labeled graphs g1
and g2
in stack dat
based on Hamming distance for dichotomous data, or else the absolute (manhattan) distance. If normalize
is true, this distance is divided by its dichotomous theoretical maximum (conditional on |V(G)|).structdist(dat, g1=c(1:dim(dat)[1]), g2=c(1:dim(dat)[1]),
normalize=FALSE, diag=FALSE, mode="digraph", method="anneal",
reps=1000, prob.init=0.9, prob.decay=0.85, freeze.time=25,
full.neighborhood=TRUE, mut=0.05, pop=20, trials=5,
exchange.list=rep(0, dim(dat)[2]))
dat
g1
should be compared (by default, all graphs)diag
is FALSE
by default.mode
is set to "digraph" by default.The accessible permutation set is determined by the exchange.list
argument, which is dealt with in the following manner. First, exchange.list
is expanded to fill an nx2 matrix. If exchange.list
is a single number, this is trivially accomplished by replication; if exchange.list
is a vector of length n, the matrix is formed by cbinding two copies together. If exchange.list
is already an nx2 matrix, it is left as-is. Once the nx2 exchangeabiliy matrix has been formed, it is interpreted as follows: columns refer to graphs 1 and 2, respectively; rows refer to their corresponding vertices in the original adjacency matrices; and vertices are taken to be theoretically exchangeable iff their corresponding exchangeability matrix values are identical. To obtain an unlabeled distance (the default), then, one could simply let exchange.list
equal any single number. To obtain the Hamming distance, one would use the vector 1:n
.
Because the set of accessible permutations is, in general, very large ($o(n!)$), searching the set for the minimum distance is a non-trivial affair. Currently supported methods for estimating the structural distance are hill climbing, simulated annealing, blind monte carlo search, or exhaustive search (it is also possible to turn off searching entirely). Exhaustive search is not recommended for graphs larger than size 8 or so, and even this may take days; still, this is a valid alternative for small graphs. Blind monte carlo search and hill climbing tend to be suboptimal for this problem and are not, in general recommended, but they are available if desired. The preferred (and default) option for permutation search is simulated annealing, which seems to work well on this problem (though some tinkering with the annealing parameters may be needed in order to get optimal performance). See the help for lab.optimize
for more information regarding these options.
Structural distance matrices may be used in the same manner as any other distance matrices (e.g., with multidimensional scaling, cluster analysis, etc.) Classical null hypothesis tests should not be employed with structural distances, and QAP tests are almost never appropriate (save in the uniquely labeled case). See cugtest
for a more reasonable alternative.
hdist
, sdmat
#Generate two random graphs
g<-array(dim=c(3,5,5))
g[1,,]<-rgraph(5)
g[2,,]<-rgraph(5)
#Copy one of the graphs and permute it
g[3,,]<-rmperm(g[2,,])
#What are the structural distances between the labeled graphs?
structdist(g,exchange.list=1:5)
#What are the structural distances between the underlying unlabeled
#graphs?
structdist(g,method="anneal", prob.init=0.9, prob.decay=0.85,
freeze.time=50, full.neighborhood=TRUE)
Run the code above in your browser using DataLab