Lably
Skip to content

Distance matrix

Square matrix containing the distances between elements in a set

  • 17 min read
  • 10 chapters

Related on Lably

Through Mathematics, Computer science and Square matrix

Non-metric distance matrix

In general, a distance matrix is a weighted adjacency matrix of some graph. In a network, a directed graph with weights assigned to the arcs, the distance between two nodes of the network can be defined as the minimum of the sums of the weights on the shortest paths joining the two nodes (where the number of steps in the path is bounded). This distance function, while well defined, is not a metric. There need be no restrictions on the weights other than the need to be able to combine and compare them, so negative weights are used in some applications. Since paths are directed, symmetry can not be guaranteed, and if negative-weight cycles exist the distance matrix may not be hollow (and in the absence of a bound on the step count, the matrix may be undefined).

An algebraic formulation of the above can be obtained by using the min-plus algebra. Matrix multiplication in this system is defined as follows: Given two n × n matrices A = (aij) and B = (bij), their distance product C = (cij) = A ⭑ B is defined as an n × n matrix such that

cij=mink=1n{aik+bkj}.

Note that the off-diagonal elements that are not connected directly will need to be set to infinity or a suitable large value for the min-plus operations to work correctly. A zero in these locations will be incorrectly interpreted as an edge with no distance, cost, etc.

If W is an n × n matrix containing the edge weights of a graph, then Wk (using this distance product) gives the distances between vertices using paths of length at most k edges, and so is the distance matrix of the graph when the step count bound is set to k. If there are no loops of negative weight, Wn will give the true distance matrix, with no bound, because removing repeated vertices from a path cannot lower its weight. On the other hand, if i and j are on a negative-weight loop, Wkij will decrease without bound as k increases.

An arbitrary graph G on n vertices can be modeled as a weighted complete graph on n vertices by assigning a weight of one to each edge of the complete graph that corresponds to an edge of G and infinity to all other edges. W for this complete graph is the adjacency matrix of G. The distance matrix of G can be computed from W as above; by contrast, if normal matrix multiplication is used, and unlinked vertices are represented with 0, Wn would instead encode the number of paths between any two vertices of length exactly n.

Sign in to keep reading

9 more chapters are free with a Lably account.

More in Statistics