Wolfram Research

Function Repository Resource:

MultiPerspectiveEmbedding

Source Notebook

Compute a 3D embedding for multiple graphs so that all pairwise distances are preserved simultaneously along various 2D projections

Contributed by: Nikolay Murzin

ResourceFunction["MultiPerspectiveEmbedding"][gs]

gives multi-perspective 3D embedding of graphs gs.

ResourceFunction["MultiPerspectiveEmbedding"][ds]

gives multi-perspective 3D embedding for explicit distance matrices.

Details and Options

The Graph inputs gs should have the same set of vertices.
Distance matrices ds should be square and of the same dimensions.
ResourceFunction["MultiPerspectiveEmbedding"] accepts the following options:
"InitialEmbedding" Automatic array of initial embedding vectors
"InitialProjection" Automatic array of initial normal vectors
"FixProjection" False whether to fix or learn projection vectors
"UseGraphEmbedding" True if input are graphs, whether to use its embeddings for computing distances
"NormalizeDistances" True whether to normalize distances
"NetTrainOptions" {} custom options for NetTrain
TrainingProgressReporting Automatic use "Verbose" for custom reporting
This is an elementary layer for training embeddings X, with one projection normal vector Q and a distance matrix D.

Examples

Basic Examples

Compute a 3D embedding for a grid graph and a path graph:

In[1]:=
ResourceFunction[
 "MultiPerspectiveEmbedding"][{GridGraph[{4, 4}], PathGraph[Range[4^2]]}]
Out[1]=

Define larger grid and path graph and show them:

In[2]:=
With[{n = 8},
  g1 = GridGraph[{n, n}, VertexLabels -> Automatic];
  g2 = Graph[VertexList[g1], DirectedEdge @@@ Partition[
      Catenate@
       MapAt[Reverse, Partition[Range[n^2], n], List /@ Range[2, n, 2]], 2, 1], VertexCoordinates -> GraphEmbedding[g1], VertexLabels -> Automatic]
  ];
GraphicsRow[{g1, g2}]
Out[3]=

Compute an embedding:

In[4]:=
graphMPSE = ResourceFunction["MultiPerspectiveEmbedding"][{g1, g2}, "UseGraphEmbedding" -> False, "TrainingProgressReporting" -> "Verbose"]
Out[4]=

View the embedding with the resource function MultiPerspectiveEmbeddingViewer:

In[5]:=
ResourceFunction["MultiPerspectiveEmbeddingViewer"][graphMPSE, "DisplayFunction" -> Function[Graphics3D[Point@graphMPSE["Embedding"], ##, AspectRatio -> 1, ImageSize -> Large]]]
Out[5]=

Here is a progress of training an embedding for points that look like digits 1, 2 and 3 in 2D from three distance matrices and how they form into their position:

View the embedding:

In[6]:=
ResourceFunction["MultiPerspectiveEmbeddingViewer"][digitsMPSE]
Out[6]=

Options

NetTrainOptions

Specify custom options for NetTrain, for example MaxTrainingRounds:

In[7]:=
ResourceFunction[
 "MultiPerspectiveEmbedding"][{GridGraph[{4, 4}], PathGraph[Range[4^2]]}, "NetTrainOptions" -> {MaxTrainingRounds -> 1}]
Out[7]=

InitialEmbedding

Specify an initial embedding:

In[8]:=
ResourceFunction[
 "MultiPerspectiveEmbedding"][{GridGraph[{4, 4}], PathGraph[Range[4^2]]}, "NetTrainOptions" -> {MaxTrainingRounds -> 1}, "InitialEmbedding" -> Append[0] /@ GraphEmbedding[GridGraph[{4, 4}]]]
Out[8]=

InitialProjection

Specify initial normal projection vectors using the "InitialProjection" option. The "Normals" key of the resulting association would contain a new projection normal vectors after training:

In[9]:=
ResourceFunction[
 "MultiPerspectiveEmbedding"][{GridGraph[{4, 4}], PathGraph[Range[4^2]]}, "NetTrainOptions" -> {MaxTrainingRounds -> 10}, "InitialProjection" -> {{1, 0, 0}, {0, 1, 0}}]
Out[9]=

FixProjection

Disable learning for normal vectors. The "Normals" value stays the same:

In[10]:=
ResourceFunction[
 "MultiPerspectiveEmbedding"][{GridGraph[{4, 4}], PathGraph[Range[4^2]]}, "NetTrainOptions" -> {MaxTrainingRounds -> 1}, "InitialProjection" -> {{1, 0, 0}, {0, 1, 0}}, "FixProjection" -> True]
Out[10]=

UseGraphEmbedding

By default, distances are taken to be distances between its GraphEmbeddings:

UseGraphEmbedding False would use GraphDistanceMatrix instead:

NormalizeDistances

Without normalizing distances, training may diverge:

Resource History

Source Metadata

Related Resources

License Information