Learn R Programming

NetworkDistance (version 0.3.6)

nd.moments: Log Moments Distance

Description

For a graph with an adjacency matrix \(A\), graph moment is defined as $$\rho_m (A) = tr(A/n)^m$$ where \(n\) is the number of vertices and \(m\) is an order of the moment. nd.moments computes pairwise distances based on log of graph moments from \(m=1\) to \(m=k\).

Usage

nd.moments(
  A,
  k = 3,
  metric = c("euclidean", "maximum", "manhattan", "canberra", "binary", "minkowski"),
  out.dist = TRUE
)

Value

a named list containing

D

an \((N\times N)\) matrix or dist object containing pairwise distance measures.

Arguments

A

a list of length \(N\) containing \((M\times M)\) adjacency matrices.

k

the integer order of moments. If \(k\) is too large, it may incur numerical overflow.

metric

type of distance measures for log-moment features. See dist for more details.

out.dist

a logical; TRUE for computed distance matrix as a dist object.

References

mukherjee_clustering_2017NetworkDistance

Examples

Run this code
## load example data
data(graph20)

## compute distance based on different k's.
out3 <- nd.moments(graph20, k=3, out.dist=FALSE)
out5 <- nd.moments(graph20, k=5, out.dist=FALSE)
out7 <- nd.moments(graph20, k=7, out.dist=FALSE)
out9 <- nd.moments(graph20, k=9, out.dist=FALSE)

## visualize
opar = par(no.readonly=TRUE)
par(mfrow=c(2,2), pty="s")
image(out3$D[,20:1], col=gray(0:32/32), axes=FALSE, main="k=3")
image(out5$D[,20:1], col=gray(0:32/32), axes=FALSE, main="k=5")
image(out7$D[,20:1], col=gray(0:32/32), axes=FALSE, main="k=7")
image(out9$D[,20:1], col=gray(0:32/32), axes=FALSE, main="k=9")
par(opar)

Run the code above in your browser using DataLab