DistGraph: Compute the vertex pair distance matrix for a graph

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/DistGraph.R

Description

Compute the distances between pairs of vertices in a graph, using a shortest path, diffusion kernel, or mean first-passage time-based measure.

Usage

1
2
DistGraph(g, v=V(g), edge.attr=NULL, dist.method=c("shortest.paths", "diffusion", "mfpt"), 
correct.inf=TRUE, correct.factor=1, verbose=TRUE)

Arguments

g

igraph object, the graph on which to work.

v

igraph object or numeric vector, the vertices from which each distance is calculated.

edge.attr

String, the name of the edge attribute to be used as distances along the edges. If NULL, then each edge is assumed to have a distance of 1. Smaller edge distances denote stronger interactions between vertex pairs.

dist.method

String, the method used to compute the distance between each vertex pair.

correct.inf

Logical, if TRUE then infinite vertex pair distances are replaced with distances equal to the maximum distance measured across the network, multiplied by correct.factor.

correct.factor

Numeric value, if the graph contains unconnected vertices, then the distance between these vertices is set as the maximum distance between the connected vertices multiplied by correct.factor.

verbose

Logical, if TRUE messages about the progress of the function are displayed.

Details

This function computes a distance matrix for a graph. Different methods can be used to calculate the distance between each pair of vertices. If a set of vertices is specified, a smaller distance matrix containing only vertices corresponding to the vertices is returned.

Descriptions of how the shortest paths (shortest.paths), diffusion kernel-based (GraphDiffusion) and mean first-passage time (GraphMFPT) distance measures work are given in their respective function descriptions.

Value

Numeric matrix, containing the distances between vertex pairs.

Author(s)

Alex J. Cornish a.cornish12@imperial.ac.uk

References

Kondor, R.I. and Lafferty, J. (2002). Diffusion Kernels on Graph and Other Discrete Structures. Proc. Intl. Conf. Machine Learning.

White, S. and Smyth, P. (2003). Algorithms for Estimating Relative Importance in Networks. Technical Report UCI-ICS 04-25.

See Also

shortest.paths, GraphDiffusion, GraphMFPT

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# create a graph and compute the distance matrix using the shortest paths measure
g1 <- barabasi.game(6, directed=FALSE)
DistGraph(g1, dist.method="shortest.paths")
plot(g1, layout=layout.fruchterman.reingold)

# create a graph, assign edge distances and compute the distance matrix using the 
# diffusion kernel-based measure
g2 <- erdos.renyi.game(6, p.or.m=0.5, directed=FALSE)
g2 <- set.edge.attribute(g2, name="distance", value=runif(ecount(g2)))
DistGraph(g2, dist.method="diffusion", edge.attr="distance")
plot(g2, layout=layout.fruchterman.reingold)

Example output

Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union

computing graph distance matrix... done
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    1    1    1    2    3
[2,]    1    0    2    2    3    4
[3,]    1    2    0    2    3    4
[4,]    1    2    2    0    1    2
[5,]    2    3    3    1    0    1
[6,]    3    4    4    2    1    0
computing graph distance matrix... done
          [,1]      [,2]      [,3]     [,4]      [,5]      [,6]
[1,] 0.0000000 1.1088186 0.8394837 1.045823 0.6542285 0.9534795
[2,] 1.1088186 0.0000000 0.8455217 1.245274 0.9826014 1.0364288
[3,] 0.8394837 0.8455217 0.0000000 1.062742 0.5008188 0.5181283
[4,] 1.0458234 1.2452744 1.0627421 0.000000 1.0544069 1.1378713
[5,] 0.6542285 0.9826014 0.5008188 1.054407 0.0000000 0.6972087
[6,] 0.9534795 1.0364288 0.5181283 1.137871 0.6972087 0.0000000

SANTA documentation built on Oct. 31, 2019, 3:21 a.m.

Related to DistGraph in SANTA...