# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Generate the graph associated with a parametric description of a manifold

Contributed by:
Samuele Mongodi

ResourceFunction["ParametricManifoldToGraph"][{ generates a graph with approximately | |

ResourceFunction["ParametricManifoldToGraph"][{ generates a graph with approximately |

ResourceFunction["ParametricManifoldToGraph"] can take as input any parametrization from a region ℛ in the variables {*x*_{1},*x*_{2},…} via the functions {*f*_{1},*f*_{2},…}, as long as the latter are expressions whose derivatives can be symbolically computed.

If the functions {*f*_{1},*f*_{2},…} do not give an injective parametrization of (a piece of) an embedded manifold, the vertices of the resulting graph might not be evenly distributed with respect to the parametrized object.

The actual number of points produced by the function as graph vertices will be roughly (but not exactly) equal to *n*.

If called without options, ResourceFunction["ParametricManifoldToGraph"] will generate a graph in ℛ according to the volume density of the parametrized manifold described by {*f*_{1},*f*_{2},…}, where two vertices are connected by an edge if and only if their distance in ℛ is less than a threshold depending on the number of input variables and the measure of the region.

The following options can be given:

"Neighbors" | "Epsilon" | neighborhood construction method |

"Distance" | "Parameters" | distance function to be used to implement the neighborhood construction method |

"VertexCoordinatesSpace" | Automatic | space for the coordinates of the vertices |

"MaxConnectedComponent" | False | behavior in case of a disconnected graph |

"RemoveIsolatedVertices" | False | behavior in case of isolated vertices |

Method | Automatic | method for the random vertex sampling |

The "Neighbors" option can be set to

"Epsilon" | two points are connected if their distance is less than an automatically computed threshold |

"KNN" | each point is connected to its k closest neighbors, with k being exponential in the dimension of the space where the distance is measured |

{"Epsilon",ϵ} | two points are connected if their distance is less than ϵ |

{"KNN",k} | each point is connected to its k closest neighbors |

The "Distance" option can be set to "Parameters", where distances are measured in ℛ, or to "Embedding", where distances are measured in the target space of the parametrization.

The option "VertexCoordinatesSpace" sets the VertexCoordinates option in NearestNeighborGraph as follows:

Automatic | coordinates assigned depending on the "Distance" option |

None | no coordinates in the resulting graph |

"Source" | coordinates take values in the source of the parametrization, i.e. ℛ |

"Target" | coordinates take values in the target space of the parametrization |

If the option "MaxConnectedComponent" is set to True, the function will return only (one of the) largest connected component(s) of the resulting graph.

If the option "RemoveIsolatedVertices" is set to True, the function will return the graph with all the isolated vertices removed.

The options "MaxConnectedComponent" and "RemoveIsolatedVertices", if set to True, will, in general, remove points, thus worsening the approximation of the manifold obtained by the resulting graph; in both cases, the function will return a pair consisting of the resulting graph and the ratio between the number of vertices in the output and the number of generated random points.

ResourceFunction["ParametricManifoldToGraph"] takes the same Method settings as InhomogeneousPoissonPointProcess.

Generate a graph from the volume density of a (piece of a) paraboloid parametrized on a disc of radius 1, with roughly 1000 points, where edges connect points that are sufficiently close:

In[1]:= |

Out[1]= |

Generate a graph with the same parameters with vertices on the paraboloid:

In[2]:= |

Out[2]= |

Generate a graph with vertices in ℛ=[-* π*,

In[3]:= |

Out[3]= |

Compute the minimal, average and maximal length of an edge:

In[4]:= |

Out[4]= |

Construct the same graph with vertices in the same region, but taking the distances in , between the images of the points:

In[5]:= |

Out[5]= |

The minimal, average and maximal length of an edge in the region as opposed to minimal, average and maximal length of an edge in the target space (where the nearest neighbors algorithm was applied):

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

The same graph with vertices in :

In[8]:= |

Out[8]= |

Construct a graph associated with a piece of the pseudosphere, parametrized on [-2,2]×[0,2* π*], by connecting points with the

In[9]:= |

Out[9]= |

Using GraphPlot or GraphPlot3D with different values for GraphLayout will produce different visualizations of the result:

In[10]:= |

Out[10]= |

Construct a graph associated with a piece of the pseudosphere, parametrized on [-2,2]×[0,2* π*], by connecting points with the

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

The graph construction is not limited to surfaces in three-dimensional space:

In[13]:= |

Out[13]= |

In[14]:= |

Out[14]= |

However, plotting the result might lead to unwanted behaviours, as the vertices are given as points of a four-dimensional space:

In[15]:= |

Out[15]= |

In this case the embedding is obtained simply by discarding the fourth coordinate of each vertex:

In[16]:= |

Out[16]= |

Using the option None for the "VertexCoordinatesSpace" option will produce a result where no VertexCoordinates specification is given, so GraphPlot3D will automatically find an embedding:

In[17]:= |

Out[17]= |

In[18]:= |

Out[18]= |

One could also use an explicit setting for GraphLayout:

In[19]:= |

Out[19]= |

The construction of the edges is based on the distances between the vertices. The option "Distance" specifies if it has to be computed in the parameter space, i.e. the region ℛ, or in the embedding space . When the Jacobian matrix of the parametrization {*f*_{1},*f*_{2},…} presents huge variations in the eigenvalues or when "distant" points in ℛ end up being "close" in , the results of the two options can be quite different. The "Embedding" setting gives results which follow more closely the geometry of the manifold.

Build a graph given by a parametrization of a slice of a sphere over a disk:

In[20]:= |

Out[20]= |

Build the same graph, but with the distance computed in the embedding space (keeping the VertexCoordinates values in the disk to obtain a comparable graphic representation):

In[21]:= |

Out[21]= |

Compare the length of the edges of the planar plot of the result with the distribution of the ratio of the smallest eigenvalue to the largest eigenvalue of the matrix (where the Jacobian matrix of the parametrization), where it can be seen how the points with lower ratio correspond to points in which longer edges are located:

In[22]:= |

In[23]:= |

Out[23]= |

By letting the GraphPlot3D function decide how to represent the two graphs, one can see what difference the choice of the distance function makes on the graph structure (with the original manifold depicted below the graphs):

In[24]:= |

Out[24]= |

If the "MaxConnectedComponent" option is set to True, the function will return the largest connected component of the resulting graph (or one of them, if there are many) together with the ratio between the number of vertices of such connected component and the total number of generated random points:

In[25]:= |

Out[25]= |

As we can see, depending on the other options, the set of vertices of the result can be significantly smaller than the initial set of random points.

Specify the method used to define the neighbors of a vertex. The default value is "Epsilon"; i.e. every point is connected to those which are closer than a given threshold:

In[26]:= |

Out[26]= |

The threshold is computed in terms of the number of points and the measure of the parameters region; however, it can be specified in the form "Neighbors"→{"Epsilon",*ϵ*}:

In[27]:= |

Out[27]= |

The value "KNN" means that every point is connected with its *k* nearest neighbors, with no bounds on the distance, where *k* depends on the dimension of the region where the distance is computed:

In[28]:= |

Out[28]= |

As before, *k* can be specified as "Neighbors"→{"KNN",*k*}:

In[29]:= |

In[30]:= |

Out[30]= |

If the "RemoveIsolatedVertices" option is set to True, the function will delete from the resulting graph all the isolated vertices and return the result together with the ratio between its number of vertices and the total number of generated random points:

In[31]:= |

Out[31]= |

In[32]:= |

Out[32]= |

When "MaxConnectedComponent" is set to True, the option "RemoveIsolatedVertices" is ignored.

The option "VertexCoordinatesSpace" is set to Automatic by default, where the first two or three components of the coordinates are used. Depending on the "Distance" option, the vertices will have the coordinates of the points in the parameters space or the coordinates of the points in the embedding space:

In[33]:= |

Out[33]= |

In[34]:= |

In[35]:= |

Out[35]= |

In[36]:= |

Out[36]= |

The value None will produce a graph without any specification for VertexCoordinates, therefore allowing one to specify an effective GraphLayout setting:

In[37]:= |

Out[37]= |

In[38]:= |

Out[38]= |

In[39]:= |

Out[39]= |

In[40]:= |

Out[40]= |

The values "Source" and "Target" will give VertexCoordinates respectively in the source (parameters) region ℛ and in the target (embedding) space of the parametrization , independently of the value given for the "Distance" option:

In[41]:= |

Out[41]= |

In[42]:= |

Out[42]= |

Produce increasingly finer graphs from a given manifold with the nearest neighbors method:

In[43]:= |

Out[43]= |

Obtain some basic information about these graphs:

In[44]:= |

Out[44]= |

Compute, for each graph, the number of vertices that lie at distance 10 from the point closer to (0,0) over the total number of vertices:

In[45]:= |

Out[45]= |

Estimate the radii of these "balls" using the average edge length:

In[46]:= |

Out[46]= |

Plot the volume ratios against the estimated radii and try to find a fit:

In[47]:= |

Out[47]= |

In[48]:= |

Out[48]= |

We now produce graphs from the same manifold, with the same size, but with a different parameter for the KNN algorithm and we repeat the previous computations:

In[49]:= |

Out[49]= |

In[50]:= |

Out[50]= |

In[51]:= |

Out[51]= |

In[52]:= |

Out[52]= |

In[53]:= |

Out[53]= |

In[54]:= |

Out[54]= |

By varying *ϵ*, with the same parametrization and number of points, one can obtain graphs with an increasing number of edges and average vertex degree:

In[55]:= |

Out[55]= |

In[56]:= |

Out[56]= |

For each graph, find the vertex closest to (0,0) and extract the neighborhood of that vertex (i.e. all the vertices connected to it):

In[57]:= |

Out[57]= |

Plot the corresponding points on the manifold:

In[58]:= |

Out[58]= |

Wolfram Language 12.2 (December 2020) or above

- 1.0.0 – 09 August 2021

This work is licensed under a Creative Commons Attribution 4.0 International License