ArticleslgStudy

mathematics

Distance matrix

Distance matrix is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Distance matrix rather than just read about it. In short: In mathematics, computer science and especially graph theory, a distance matrix is a square matrix (two-dimensional array) containing the distances, taken pairwise, between the elements of a set. Depending upon the application involved, the "distance" being used to define this matrix may or may not be a metric.

Distance matrix — main illustration
Distance matrix — illustration

Key takeaways

  • Distance matrix belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Distance matrix to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Distance matrix from memory before moving on to harder problems.

Reference excerpt

In mathematics, computer science and especially graph theory, a distance matrix is a square matrix (two-dimensional array) containing the distances, taken pairwise, between the elements of a set. Depending upon the application involved, the "distance" being used to define this matrix may or may not be a metric. If there are N elements, this matrix will have size N×N. In graph-theoretic applications, the elements are usually referred to as points, nodes or vertices.

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.

Metric distance matrix The value of a distance matrix formalism in many applications is in how the distance matrix can manifestly encode the metric axioms and in how it lends itself to the use of linear algebra techniques. That is, if M = (xij) with 1 ≤ i, j ≤ N is a distance matrix for a metric distance, then

the entries on the main diagonal are all zero (that is, the matrix is a hollow matrix), i.e. xii = 0 for all 1 ≤ i ≤ N, all the off-diagonal entries are positive (xij > 0 if i ≠ j), (that is, a non-negative matrix), the matrix is a symmetric matrix (xij = xji), and for any i and j, xij ≤ xik + xkj for all k (the triangle inequality). This can be stated in terms of tropical matrix multiplication When a distance matrix satisfies the first three axioms (making it a semi-metric) it is sometimes referred to as a pre-distance matrix. A pre-distance matrix that can be embedded in a Euclidean space is called a Euclidean distance matrix. For mixed-type data that contain numerical as well as categorical descriptors, Gower's distance is a common alternative. Another common example of a metric distance matrix arises in coding theory when in a block code the elements are strings of fixed length over an alphabet and the distance between them is given by the Hamming distance metric. The smallest non-zero entry in the distance matrix measures the error correcting and error detecting capability of the code.

Additive distance matrix An additive distance matrix is a special type of matrix used in bioinformatics to build a phylogenetic tree. Let x be the lowest common ancestor between two species i and j, we expect Mij = Mix + Mxj. This is where the additive metric comes from. A distance matrix M for a set of species S is said to be additive if and only if there exists a phylogeny T for S such that:

Every edge (u,v) in T is associated with a positive weight duv For every i,j ∈ S, Mij equals the sum of the weights along the path from i to j in T For this case, M is called an additive matrix and T is called an additive tree. Below we can see an example of an additive distance matrix and its corresponding tree:

Ultrametric distance matrix The ultrametric distance matrix is defined as an additive matrix which models the constant molecular clock. It is used to build a phylogenetic tree. A matrix M is said to be ultrametric if there exists a tree T such that:

Mij equals the sum of the edge weights along the path from i to j in T A root of the tree can be identified with the distance to all the leaves being the same Here is an example of an ultrametric distance matrix with its corresponding tree:

Bioinformatics

The distance matrix is widely used in the bioinformatics field, and it is present in several methods, algorithms and programs. Distance matrices are used to represent protein structures in a coordinate-independent manner, as well as the pairwise distances between two sequences in sequence space. They are used in structural and sequential alignment, and for the determination of protein structures from NMR or X-ray crystallography. Sometimes it is more convenient to express data as a similarity matrix. It is also used to define the distance correlation.

… excerpt ends here. Continue reading the full article.

Illustrations

Distance matrix illustration
Distance matrix: Phylogenetic tree from 3 species
Phylogenetic tree from 3 species
Distance matrix illustration
Distance matrix illustration
Distance matrix: Conversion formula between cosine similarity and Euclidean distance
Conversion formula between cosine similarity and Euclidean distance

Worked examples

Example 1 — a first encounter with Distance matrix

Start with the simplest possible case. Write down what Distance matrix claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Distance matrix before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Distance matrix ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Distance matrix

In research
Distance matrix appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Distance matrix in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Distance matrix is common in secondary-school and first-year university syllabi. It links to neighbouring topics Bioinformatics, Graph distance, Matrices (mathematics), so understanding it makes those chapters shorter.
In everyday life
Look for Distance matrix outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Distance matrix” →

How to study Distance matrix in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Distance matrix means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Distance matrix out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Distance matrix in simple terms?

In mathematics, computer science and especially graph theory, a distance matrix is a square matrix (two-dimensional array) containing the distances, taken pairwise, between the elements of a set. Depending upon the application involved, the "distance" being used to define this matrix may or may not…

Why does Distance matrix matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Distance matrix?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Distance matrix.

Tags

  • Bioinformatics
  • Graph distance
  • Matrices (mathematics)
  • Metric geometry

Keep exploring