Reconstructing a point set from a Euclidean Distance Matrix
Recovering point locations from vectors.
Recovering point locations from Euclidean Distance Matrices has practical applications in ultrasound tomography and other fields that must determine the position of recording devices from acoustic signals. This post explains the solution to a concrete problem, drawing on the explanations in Linear Algebra and Learning from Data and a paper on Euclidean distance geometry.
I want to answer the question: How to reconstruct the locations of the original vectors given the Euclidean distance matrix,
We assume the distances in
Theory
This procedure, known as classical multidimensional scaling (MDS), comes from this paper. The approach extends to real-world problems like noisy data.
Consider a collection of
Expanding this norm yields:
The matrix equation for the distance matrix
The operator
Let the first point
It is now possible to construct the term
The Gram matrix
The final stage is to identify the point set using Eigenvalue Decomposition (EVD), for example:
Remember that
Example problem
This problem is Q5 from Problem Set
Let’s start with some useful imports:
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import distance_matrix
from scipy.spatial.distance import cdist
And now let’s define the matrix
D = np.array([[0, 9, 25], [9, 0, 16], [25, 16, 0]])
Calculate the Gram matrix. To verify it is positive semidefinite, see J. C. Gower, “Euclidean Distance Geometry,” Math. Sci., vol. 7, pp. 1–14, 1982.
G = -0.5 * (D - np.outer(np.ones(3), D[1, :]) - np.outer(D[:, 1], np.ones(3)))
G
array([[9., -0., -0.],
[-0., -0., -0.],
[-0., -0., 16.]])
Now use np.linalg.svd to solve
Q, Lambda, _ = np.linalg.svd(G)
print(Q)
print(Lambda)
[[0. 1. 0.]
[0. 0. 1.]
[1. 0. 0.]]
[16. 9. -0.]
Return the original point set using
np.power(Lambda, 0.5) * Q.T
array([[0., 0., 0.],
[4., 0., 0.],
[0., 3., 0.]])
These coordinates satisfy the original distance constraints. Point 1 is at the origin (0, 0), point 2 at distance 4, and point 3 at distance 3, matching the distances specified in the input matrix