Function Repository Resource:

ParametricManifoldToGraph

Generate the graph associated with a parametric description of a manifold

Contributed by: Samuele Mongodi
 ResourceFunction["ParametricManifoldToGraph"][{f1,f2,…},{x1,x2,…},ℛ,n] generates a graph with approximately n pseudorandom points in the region ℛ, drawn from the distribution given by the volume density of the manifold parametrized by {f1,f2,…} as {x1,x2,…} vary in ℛ, where two vertices are joined by an edge if their distance in ℛ is less than a certain threshold depending on n and ℛ. ResourceFunction["ParametricManifoldToGraph"][{f1,f2,…},{x1,a1,b1},{x2,a2,b2},…,n] generates a graph with approximately n pseudorandom points in the region defined by the set of inequalities aj<=xj<=bj,j=1,…, drawn from the distribution given by the volume density of the manifold parametrized by {f1,f2,…} as {x1,x2,…} vary between the given bounds, where two vertices are joined by an edge if their distance in the coordinates x1,x2, … is less than a certain threshold depending on n and aj,bj,j=1,….

Details and Options

ResourceFunction["ParametricManifoldToGraph"] can take as input any parametrization from a region ℛ in the variables {x1,x2,} via the functions {f1,f2,}, as long as the latter are expressions whose derivatives can be symbolically computed.
If the functions {f1,f2,} 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 {f1,f2,}, 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.

Examples

Basic Examples (4)

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 =[-π,π]×[-π/2,π/2], uniformly distributed with respect to the volume density of a torus embedded in , using the k-nearest neighbors method with k=6 and using the Euclidean distance in the rectangle ℛ:

 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 ϵ-neighbors algorithm with respect to the embedding distance in , with no vertex coordinates:

 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 ϵ-neighbors algorithm with respect to the embedding distance in , using a small ϵ, with no vertex coordinates and only one connected component:

 In[11]:=
 Out[11]=
 In[12]:=
 Out[12]=

Scope (5)

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]=

Options (11)

Distance (4)

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 {f1,f2,} 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]=

MaxConnectedComponent (1)

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.

Neighbors (2)

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]=

RemoveIsolatedVertices (1)

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.

VertexCoordinatesSpace (3)

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]=

Applications (2)

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]=

Neat Examples (3)

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]=

Samuele Mongodi

Requirements

Wolfram Language 12.2 (December 2020) or above

Version History

• 1.0.0 – 09 August 2021