Euclidean distance matrix

In mathematics, a Euclidean distance matrix is an $n×n$ matrix representing the spacing of a set of $n$ points in Euclidean space. For points $$x_1,x_2,\ldots,x_n$$ in $k$-dimensional space $ℝ^{k}$, the elements of their Euclidean distance matrix $A$ are given by squares of distances between them. That is


 * $$\begin{align}

A & = (a_{ij}); \\ a_{ij} & = d_{ij}^2 \;=\; \lVert x_i - x_j\rVert^2 \end{align} $$

where $$\|\cdot\|$$ denotes the Euclidean norm on $ℝ^{k}$.


 * $$A = \begin{bmatrix}

0 & d_{12}^2 & d_{13}^2 & \dots & d_{1n}^2 \\ d_{21}^2 & 0 & d_{23}^2 & \dots & d_{2n}^2 \\ d_{31}^2 & d_{32}^2 & 0 & \dots & d_{3n}^2 \\ \vdots&\vdots & \vdots & \ddots&\vdots& \\ d_{n1}^2 & d_{n2}^2 & d_{n3}^2 & \dots & 0 \\ \end{bmatrix} $$

In the context of (not necessarily Euclidean) distance matrices, the entries are usually defined directly as distances, not their squares. However, in the Euclidean case, squares of distances are used to avoid computing square roots and to simplify relevant theorems and algorithms.

Euclidean distance matrices are closely related to Gram matrices (matrices of dot products, describing norms of vectors and angles between them). The latter are easily analyzed using methods of linear algebra. This allows to characterize Euclidean distance matrices and recover the points $$x_1,x_2,\ldots,x_n$$ that realize it. A realization, if it exists, is unique up to rigid transformations, i.e. distance-preserving transformations of Euclidean space (rotations, reflections, translations).

In practical applications, distances are noisy measurements or come from arbitrary dissimilarity estimates (not necessarily metric). The goal may be to visualize such data by points in Euclidean space whose distance matrix approximates a given dissimilarity matrix as well as possible — this is known as multidimensional scaling. Alternatively, given two sets of data already represented by points in Euclidean space, one may ask how similar they are in shape, that is, how closely can they be related by a distance-preserving transformation — this is Procrustes analysis. Some of the distances may also be missing or come unlabelled (as an unordered set or multiset instead of a matrix), leading to more complex algorithmic tasks, such as the graph realization problem or the turnpike problem (for points on a line).

Properties
By the fact that Euclidean distance is a metric, the matrix $A$ has the following properties.


 * All elements on the diagonal of $A$ are zero (i.e. it is a hollow matrix); hence the trace of $A$ is zero.
 * $A$ is symmetric (i.e. $$a_{ij} = a_{ji}$$).
 * $$ \sqrt{a_{ij}} \le \sqrt{a_{ik}} + \sqrt{a_{kj}} $$ (by the triangle inequality)
 * $$ a_{ij}\ge 0$$

In dimension $k$, a Euclidean distance matrix has rank less than or equal to $k+2$. If the points $$x_1,x_2,\ldots,x_n$$ are in general position, the rank is exactly $min(n, k + 2).$

Distances can be shrunk by any power to obtain another Euclidean distance matrix. That is, if $$A=(a_{ij})$$ is a Euclidean distance matrix, then $$({a_{ij}}^s)$$ is a Euclidean distance matrix for every $0<s<1$.

Relation to Gram matrix
The Gram matrix of a sequence of points $$x_1,x_2,\ldots,x_n$$ in $k$-dimensional space $ℝ^{k}$ is the $n×n$ matrix $$G = (g_{ij})$$ of their dot products (here a point $$x_i$$ is thought of as a vector from 0 to that point):
 * $$g_{ij} = x_i \cdot x_j = \|x_i\| \|x_j\| \cos \theta$$, where $$\theta$$ is the angle between the vector $$x_i$$ and $$x_j$$.

In particular
 * $$g_{ii} = \|x_i\|^2$$ is the square of the distance of $$x_i$$ from 0.

Thus the Gram matrix describes norms and angles of vectors (from 0 to) $$x_1,x_2,\ldots,x_n$$.

Let $$X$$ be the $k×n$ matrix containing $$x_1,x_2,\ldots,x_n$$ as columns. Then
 * $$G = X^\textsf{T} X$$, because $$g_{ij} = x_i^\textsf{T} x_j$$ (seeing $$x_i$$ as a column vector).

Matrices that can be decomposed as $$X^\textsf{T}X$$, that is, Gram matrices of some sequence of vectors (columns of $$X$$), are well understood — these are precisely positive semidefinite matrices.

To relate the Euclidean distance matrix to the Gram matrix, observe that
 * $$d_{ij}^2 = \|x_i - x_j\|^2 = (x_i - x_j)^\textsf{T} (x_i - x_j) = x_i^\textsf{T} x_i - 2x_i^\textsf{T} x_j + x_j^\textsf{T} x_j = g_{ii} -2g_{ij} + g_{jj}$$

That is, the norms and angles determine the distances. Note that the Gram matrix contains additional information: distances from 0.

Conversely, distances $$d_{ij}$$ between pairs of $n+1$ points $$x_0,x_1,\ldots,x_n$$ determine dot products between $n$ vectors $$x_i-x_0$$ ($1≤i≤n$):
 * $$g_{ij} = (x_i-x_0) \cdot (x_j-x_0) = \frac{1}{2}\left(\|x_i-x_0\|^2 + \|x_j-x_0\|^2 - \|x_i - x_j\|^2 \right) = \frac{1}{2}(d_{0i}^2 + d_{0j}^2 - d_{ij}^2)$$

(this is known as the polarization identity).

Characterizations
For a $n×n$ matrix $A$, a sequence of points $$x_1,x_2,\ldots,x_n$$ in $k$-dimensional Euclidean space $ℝ^{k}$ is called a realization of $A$ in $ℝ^{k}$ if $A$ is their Euclidean distance matrix. One can assume without loss of generality that $$x_1 = \mathbf{0}$$ (because translating by $$-x_1$$ preserves distances).

$$ This follows from the previous discussion because $G$ is positive semidefinite of rank at most $k$ if and only if it can be decomposed as $$G = X^\textsf{T} X$$ where $X$ is a $n×n$ matrix. Moreover, the columns of $X$ give a realization in $ℝ^{k}$. Therefore, any method to decompose $G$ allows to find a realization. The two main approaches are variants of Cholesky decomposition or using spectral decompositions to find the principal square root of $G$, see Definite matrix.

The statement of theorem distinguishes the first point $$x_1$$. A more symmetric variant of the same theorem is the following: $$

Other characterizations involve Cayley–Menger determinants. In particular, these allow to show that a symmetric hollow $(n-1)×(n-1)$ matrix is realizable in $k×n$ if and only if every $ℝ^{k}$ principal submatrix is. In other words, a semimetric on finitely many points is embedabble isometrically in $n×n$ if and only if every $n×n$ points are.

In practice, the definiteness or rank conditions may fail due to numerical errors, noise in measurements, or due to the data not coming from actual Euclidean distances. Points that realize optimally similar distances can then be found by semidefinite approximation (and low rank approximation, if desired) using linear algebraic tools such as singular value decomposition or semidefinite programming. This is known as multidimensional scaling. Variants of these methods can also deal with incomplete distance data.

Unlabeled data, that is, a set or multiset of distances not assigned to particular pairs, is much more difficult to deal with. Such data arises, for example, in DNA sequencing (specifically, genome recovery from partial digest) or phase retrieval. Two sets of points are called homometric if they have the same multiset of distances (but are not necessarily related by a rigid transformation). Deciding whether a given multiset of $ℝ^{k}$ distances can be realized in a given dimension $k$ is strongly NP-hard. In one dimension this is known as the turnpike problem; it is an open question whether it can be solved in polynomial time. When the multiset of distances is given with error bars, even the one dimensional case is NP-hard. Nevertheless, practical algorithms exist for many cases, e.g. random points.

Uniqueness of representations
Given a Euclidean distance matrix, the sequence of points that realize it is unique up to rigid transformations – these are isometries of Euclidean space: rotations, reflections, translations, and their compositions.

$$

Rigid transformations preserve distances so one direction is clear. Suppose the distances $$\|x_i-x_j\|$$ and $$\|y_i-y_j\|$$ are equal. Without loss of generality we can assume $$x_1=y_1=\textbf{0}$$ by translating the points by $$-x_1$$ and $$-y_1$$, respectively. Then the $(k+3)×(k+3)$ Gram matrix of remaining vectors $$x_i=x_i-x_1$$ is identical to the Gram matrix of vectors $$y_i$$ ($ℝ^{k}$). That is, $$X^\textsf{T} X = Y^\textsf{T} Y$$, where $X$ and $Y$ are the $k+3$ matrices containing the respective vectors as columns. This implies there exists an orthogonal $n(n-1)/2$ matrix $Q$ such that $ℝ^{k}$, see Definite symmetric matrix. $Q$ describes an orthogonal transformation of $1≤i,j≤n$ (a composition of rotations and reflections, without translations) which maps $$x_i$$ to $$y_i$$ (and 0 to 0). The final rigid transformation is described by $$T(x) = Q(x-x_1)+y_1$$.

In applications, when distances don't match exactly, Procrustes analysis aims to relate two point sets as close as possible via rigid transformations, usually using singular value decomposition. The ordinary Euclidean case is known as the orthogonal Procrustes problem or Wahba's problem (when observations are weighted to account for varying uncertainties). Examples of applications include determining orientations of satellites, comparing molecule structure (in cheminformatics), protein structure (structural alignment in bioinformatics), or bone structure (statistical shape analysis in biology).