​
​
A Wolfram Notebook on Graphons

A graphon is a symmetric, Lebesgue-measurable function
W:[0,1]
2
[0,1]
. Graphons are the limiting objects for sequences of finite simple graphs with respect to the cut metric
δ
□
(W,U)=inf
ϕ,ψ
sup
S,T
∫∫
ST
(W(ϕ(x),ϕ(y))-U(ψ(x),ψ(y)))xy
, where the infimum is taken over all pairs of invertible, measure-preserving transformations of
[0,1]
, and the supremum is taken over all pairs of measurable subsets of
[0,1]
. In this notebook, we explore the subject of graphons using the
Wolfram Language
. For a more thorough introduction to graphons, including further exposition on some of the examples presented here, see
“What Is a Graphon?”
by Daniel Glasscock.

Clickinthecode,thenholdandpresstorunit.

We start by defining two graphons that we’ll use throughout the notebook.

graphon1[x_,y_]:=√(x*y)​​graphon2[x_,y_]:=1-Max[x,y]
In[1]:=

Graphons are graphically represented by shading the unit square. The point
(x,y)
, located
x
units down and
y
units to the right of the upper-left corner, is shaded based on where
W(x,y)
lies between 0 (white) and 1 (black). The DensityPlot function follows the normal Cartesian coordinate system of the plane and also sets 0 as black and 1 as white, so a simple transformation is needed inside the function.

plot[graphon_]:=DensityPlot[Abs[1-graphon[1-y,x]],{x,0,1},{y,0,1},ColorFunction->GrayLevel,FrameTicksFalse]
In[3]:=
Map[plot,{graphon1,graphon2}]
In[4]:=
Out[4]=

Every
n
-vertex graph can be represented as the graphon that is drawn by dividing the unit square into an
nn
grid of equally sized blocks and shading the blocks pure black if the corresponding entry in the adjacency matrix is 1 and white if the entry is 0. We call this the “pixel picture” of the graph.

graph=Graph[{1,2,3,4,5},{12,23,31,45},VertexLabels->"Name"];​​am=AdjacencyMatrix[graph];​​{graph,MatrixForm[am],ArrayPlot[am]}
In[5]:=
Out[7]=

Hence the following code formally converts a graph to a graphon.

graphToGraphon[graph_]:=With[{am=Normal[AdjacencyMatrix[graph]],n=VertexCount[graph]},Function[{x,y},Indexed[am,{Max[⌈n*x⌉,1],Max[⌈n*y⌉,1]}]]]
In[8]:=

We apply it to our graph and then plot it.

plot[graphToGraphon[graph]]
In[9]:=

We now create the graph and its pixel picture.

We put everything together in the following function.

Associate each vertex of our graph with a variable of integration.

We put everything together in the following function.

Recover the vertices from the partition.

Associate each vertex with the index of its subset in the partition.

Convert these vertex pairs into edges and create the graph.

Put everything together into a single function.