[Math] Calculate Gram matrix from distance matrix

linear algebramatrices

I've been trying to wrap my head around this homework question we've gotten for a few days but made little progress.

We've been instructed, given a euclidean distance matrix of $n$ coordinates in $\mathbb R^2$ to calculate the Gram matrix of the coordinates, namely, $X^TX$ if $X$ is a $2 \times n$ matrix whose columns are the coordinates (note we don't have $X$). We've also been told that the center of mass (namely the average of the coordinates) is exactly (0,0).

As the second part of the question, we've been given a $312 \times 312$ distance matrix and the first 5 coordinates and have been asked to find the full coordinate matrix. I've tried to use eigenvalue decomposition and calculate $U\sqrt D$ assuming it'd satisfy the demands but I am not sure how to use the coordinates we have been given. It is important to note that for the second part it is not known what the center of mass is.

I tried searching on here but only found solutions for when (0,0) is $x_1$ and I am not sure how to move from there.

Thank you in advance!

Best Answer

I will answer a slightly broader question:

Problem 1: Can a given distance matrix $D$ arise as distance matrix of points in an euclidean space $\mathbf R^n$?

Problem 2: If not, give points of an $\mathbf R^n$ that realise $D$ best possible.

Both can be answered as follows. Let $X=\{x^1,\dotsc,x^r\}\subset\mathbf R^N$ be a set of points taken from some metric space, together with their distances $d_X$.

Provided that $(X, d_X)$ has an isometric embedding $\iota$ into some lower dimensional $\mathbf R^n$ which we do not know yet, our goal is to find possible images $\hat x^i=\iota(x^i)$.

Let $D=(d_{ij})_{ij}$ with $d_{ij}=d_X(x^i, x^j)$. Since $\mathbf R^N$ is a euclidean space, we can form the Gram matrix $B=(b_{ij})_{ij}$ with $b_{ij}=\langle x^i, x^j\rangle$. Let $X=(x^1,\dotsc,x^n)$ and $\hat X=(\hat x^1,\dotsc,\hat x^n)$ as matrices so that $B=X^\mathrm T X$, and assume w. l. o. g. that $\{\hat x^i\}$ have the origin at their centre of mass. The pairwise distances satisfy \begin{align} d_{ij}^2 &= \langle x^i-x^j, x^i-x^j\rangle \\ &= b_{ii} -2b_{ij} + b_{jj}. \end{align}

Since $\iota$ is supposed to become an isometry, $B=\hat X^\mathrm T \hat X$. Since the points $\hat x^i$ are supposed to be centered at the origin,

$$\textstyle\sum_i b_{ij} = \textstyle\sum_{ik} \hat x^i_k \hat x^j_k = 0;$$

hence

\begin{align} \textstyle\sum_{i} d_{ij}^2 &= \operatorname{tr} B + r b_{jj}\\ \textstyle\sum_{j} d_{ij}^2 &= \operatorname{tr} B + r b_{ii}\\ \textstyle\sum_{ij} d_{ij}^2 &= 2r\operatorname{tr} B \end{align}

and conversely

\begin{align} b_{ij} &= \textstyle -\frac 12 \left[ d_{ij}^2 - \frac 1r \left( \sum_k d_{kj}^2 + \sum_k d_{ik}^2\right) + \frac{1}{r^2}\sum_{kl} d_{kl}^2\right]. \end{align} With the matrix $C=(\delta_{ij}-\frac 1r)_{ij}$ the last line can be written as

$$ \quad B = -\tfrac 12 CDC. \tag{Gram matrix}$$

Since $B$ is a symmetric matrix, it can be factored as $B=Q\Lambda Q^\mathrm T$ for $Q$ normal and $\Lambda=\operatorname{diag}(\lambda_1,\dotsc, \lambda_n, 0, \dotsc, 0)$ diagonal with nonnegative entries in descending order. Then

$$ \quad\hat X = \Lambda^{\frac 12}Q^\mathrm T \tag{realising coordinates}$$

contains coordinates for the $r$ points $\hat x^i\in\mathbf R^n$ which give rise to the prescribed distance matrix $D$, and all other rows of $\hat X$ are zero.

If $X$ cannot be embedded into $\mathbf R^n$ as assumed initially, $\Lambda$ might have non-zero entries beyond $\lambda_n$. If we drop all but the first $n$ eigenvectors and -values in $Q$ and $\Lambda$ respectively, we obtain a map $X\to\mathbf R^n$ for which the metric distortion $\sum_{ij} \bigl(d_{ij} - \Vert \hat x^i - \hat x^j \Vert\bigr)^2$ becomes minimal. A necessary and sufficient criterion for the embeddability of $X$ in $\mathbf R^n$ is the vanishing of all higher Cayley-Menger determinants. If $X$ cannot be embedded in any euclidean space, $\Lambda$ might contain negative entries.