Function Repository Resource:

PairwiseMultidimensionalScaling

Source Notebook

Multidimensional scaling algorithm for embedding pairwise distances into a Cartesian space

Contributed by: Nikolay Murzin

ResourceFunction["PairwiseMultidimensionalScaling"][dm]

return a list of 2-dimensional coordinates representing embedding of a distance matrix dm.

ResourceFunction["PairwiseMultidimensionalScaling"][dm,dim]

embed into a given integer dimension dim.

Details

Usually the multidimensional scaling algorithm is used for a given list of vectors, and there is an intermediate step of computing distances between them. In some cases, only the distances are known and the task is to find a lower-dimensional embedding such that the resulting distances are approximately preserved.
DimensionReduce with Method "MultidimensionalScaling"or ResourceFunction["MultidimensionalScaling"] can be used for computing Multidimensional scaling for a list of vectors.
ResourceFunction["PairwiseMultidimensionalScaling"] implements classical multidimensional scaling, which is an exact solution to a minimization of the strain function problem.

Examples

Basic Examples (2) 

Compute 2-dimensional embedding from a distance matrix of three points:

In[1]:=
ResourceFunction["PairwiseMultidimensionalScaling"][( {
   {0., 1., 2.},
   {1., 0., 3.},
   {2., 4., 0.}
  } )]
Out[1]=

Compute 3-dimensional embedding from a distance matrix of four points:

In[2]:=
ResourceFunction["PairwiseMultidimensionalScaling"][( {
   {0., 1., 2., 3.},
   {4., 0., 5., 6.},
   {7., 8., 0., 9.},
   {-1., -2., -3., 0.}
  } ), 3]
Out[2]=

Applications (3) 

Coordinatize an edge-weighted graph:

In[3]:=
With[{g = Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 1}, EdgeWeight -> {1 \[UndirectedEdge] 2 -> 1.9}]},
 Graph[g, VertexCoordinates -> ResourceFunction["PairwiseMultidimensionalScaling"][
    GraphDistanceMatrix[g]]]
 ]
Out[3]=

Coordinatize a graph given pairwise distances between vertices:

In[4]:=
SeedRandom[2];
g = RandomGraph[{10, 20}]
Out[5]=

Providing distances of its GraphEmbedding the original graph can be closely reconstructed (up-to translational/rotational/reflectional symmetry):

In[6]:=
Graph[g, VertexCoordinates -> ResourceFunction["PairwiseMultidimensionalScaling"][
   DistanceMatrix[GraphEmbedding[g]]]]
Out[6]=

Coordinatize a causal graph:

In[7]:=
SeedRandom[14];
cg = ResourceFunction["FlatSpacetimeSprinkling"][2, 20]["CausalGraph"]
Out[8]=
In[9]:=
Graph[cg, VertexCoordinates -> ResourceFunction["PairwiseMultidimensionalScaling"][
   DistanceMatrix[GraphEmbedding[cg]]]]
Out[9]=

Properties and Relations (1) 

PairwiseMultidimensionalScaling embedding is homomorphic to the one computed using ResourceFunction[“MultidimensionalScaling”] for a DistanceMatrix with DistanceFunction EuclideanDistance, and also similar to DimensionReduce with various methods:

In[10]:=
With[{vectors = ExampleData[{"MachineLearning", "FisherIris"}, "Data"][[All, 1]]}, GraphicsRow[ListPlot /@ {
    ResourceFunction["PairwiseMultidimensionalScaling"][
     DistanceMatrix[vectors, DistanceFunction -> EuclideanDistance]],
    ResourceFunction["MultidimensionalScaling"][vectors],
    Map[{{0, 1}, {-1, 0}} . # &, DimensionReduce[vectors, Method -> "MultidimensionalScaling"]],
    Map[{{-1, 0}, {0, 1}} . # &, DimensionReduce[Standardize[vectors, Mean, 1 &], Method -> "LatentSemanticAnalysis"]],
    Map[{{-1, 0}, {0, 1}} . # &, DimensionReduce[vectors, Method -> "PrincipalComponentsAnalysis"]]
    }, Frame -> All, ImageSize -> Full]
 ]
Out[10]=

Version History

  • 1.0.0 – 28 September 2022

Source Metadata

Related Resources

Author Notes

Ideally there would be a way to provide a distance matrix to the DimensionReduce directly instead, and this will become obsolete.

License Information