Introduction
Machine learning is opening new directions in mathematical discovery. Recent work spans automatic provers and autoformalisation for Olympiad-style or research-level problems [38 , 46 , 21 , 49 , 19 , 18 , 1 ] , neural search for combinatorial constructions [48 , 7 , 43 , 33 ] , and pattern-driven progress on long-standing conjectures in pure mathematics [11 , 17 ] . In this paper, we extend this line of research to a class of continuous optimisation problems over graphons , with two motivating problem families drawn from extremal graph theory and the large deviation theory of dense random graphs.
A central object in extremal graph theory is the homomorphism density t ( H , G ) t(H,G) t ( H , G ) between finite undirected simple graphs H H H and G G G : the probability that a uniformly random map from V ( H ) V(H) V ( H ) to V ( G ) V(G) V ( G ) is a graph homomorphism. As a basic example, the constrained optimisation problem
max G t ( K 2 , G ) subject to t ( K 3 , G ) = 0 ∧ ∣ V ( G ) ∣ = n (1) \max_G\ t(K_2,G)\quad\text{subject to}\quad t(K_3,G)=0\ \wedge\ |V(G)|=n \tag*{(1)} G max t ( K 2 , G ) subject to t ( K 3 , G ) = 0 ∧ ∣ V ( G ) ∣ = n (1)
asks for an n n n -vertex triangle-free graph that maximises the edge density. Here K m K_m K m denotes the complete graph on m m m vertices, so K 2 K_2 K 2 and K 3 K_3 K 3 represent an edge and a triangle, respectively. Although the answer is given by the classical theorem of Mantel [28 ] , a large family of similar problems involving homomorphism densities remains open [44 , 6 ] .
A standard approach to such problems is to study their asymptotic counterparts, taking n → ∞ n \to\infty n → ∞ and analysing the limit of the optimum. These asymptotic problems can often be reformulated as continuous optimisation over graphons , i.e., symmetric measurable functions [ 0 , 1 ] 2 → [ 0 , 1 ] [0,1]^2 \to[0,1] [ 0 , 1 ] 2 → [ 0 , 1 ] , that arise as limit objects of dense graph sequences [26 , 24 ] . Another source of graphon optimisation problems comes from the large deviation theory of dense random graphs [8 ] , where the limiting structure of an Erdős–Rényi graph conditioned on an unusually large or small homomorphism density is itself characterised by a constrained optimisation over graphons. In both settings, the objective and constraints are integrals against the graphon W W W (homomorphism densities or pointwise relative entropy), and known or conjectured optima are step-like.
We attack these graphon-optimisation problems directly with deep learning, representing a graphon W W W as a neural network in the spirit of implicit neural representations [35 , 30 , 10 ] and minimising the objective by gradient descent on the network parameters. Three recurring challenges shape our design. First, known and conjectured optima are typically step-like, and standard architectures struggle with such targets because of their bias toward smooth functions. We address this with a multi-scale sinusoidal residual architecture that injects sinusoidal encodings of growing frequency into successive layers, biasing the model toward sharp, step-like solutions. Second, the problems often carry a single scalar density constraint (a fixed homomorphism density) that is poorly handled by penalty terms; we embed a numerical solver for an empirical version of the constraint into the forward pass and backpropagate through it via implicit differentiation, as in deep equilibrium models [3 ] . Third, both the objective and the constraints are graphon integrals that must be estimated from samples, including the high-dimensional homomorphism-density integrals; we use symmetry-aware Monte Carlo estimators.
We demonstrate our framework on two families of graphon optimisation problems: (P1) generalised Turán problems from extremal graph theory, minimising a homomorphism density under a fixed edge-density constraint; and (P2) the variational problems from the large deviation theory of dense random graphs [8 ] , minimising a relative-entropy functional under a fixed homomorphism-density constraint. On (P1), our framework rediscovers nontrivial known optima that previously required substantial human effort [16 , 5 , 25 , 15 , 40 ] , produces candidate minimisers for open instances such as minimisation of C 7 C_7 C 7 -homomorphism density, and through a systematic sweep over small graphs, uncovers, for a six-vertex graph, a previously unreported family of extremal structures that do not match the complete k k k -partite pattern of classical examples. Applied to (P2), the framework produces new candidate optimal graphons, in the cases where the optimal structure is not fully understood, for four pattern graphs in the upper-tail regime and K 3 K_3 K 3 in the lower-tail regime. For K 3 K_3 K 3 , these candidates consistently improve upon the reference construction of Lubetzky and Zhao [2015] in the upper-tail regime. We view the framework as a flexible exploratory tool that complements rigorous lower-bound techniques such as flag algebras [39 , 14 ] : it produces candidate upper bounds, concrete candidate minimisers, and structural conjectures that can be inspected, refined, or subsequently certified. The structures found by our method have also led to new theorems (§D). For problems of (P1), the balanced complete k k k -partite graphon minimises the density of every odd cycle at p = 1 − 1 / k p = 1 - 1/k p = 1 − 1/ k for every k ≥ 3 k \ge3 k ≥ 3 , and that of every connected chordal graph whose maximal cliques have a common size r ≥ 3 r \ge3 r ≥ 3 at p = 1 − 1 / k p = 1 - 1/k p = 1 − 1/ k for every k ≥ r k \ge r k ≥ r . For problems of (P2), close to the boundary of the region where the constant graphon is optimal, the upper-tail problem for regular graphs has a unique optimal graphon, which is bipodal.
Background
For a positive integer n n n , write [ n ] : = { 1 , 2 , … , n } [n] := \{1, 2, \ldots, n\} [ n ] := { 1 , 2 , … , n } . Throughout the paper, a graph is an undirected, finite, simple graph (no self-loops and no multiple edges). For a graph G G G , we write V ( G ) V(G) V ( G ) and E ( G ) E(G) E ( G ) for its vertex and edge sets, and let v ( G ) : = ∣ V ( G ) ∣ v(G) := |V(G)| v ( G ) := ∣ V ( G ) ∣ and e ( G ) : = ∣ E ( G ) ∣ e(G) := |E(G)| e ( G ) := ∣ E ( G ) ∣ . We use standard notation for familiar graphs: K n K_n K n denotes the complete graph on n n n vertices (i.e., V ( K n ) = [ n ] V(K_n) = [n] V ( K n ) = [ n ] and E ( K n ) = { { i , j } : i , j ∈ [ n ] , i ≠ j } E(K_n) = \{\{i, j\} : i, j \in[n], i \ne j\} E ( K n ) = {{ i , j } : i , j ∈ [ n ] , i = j } ), K 1 , n K_{1,n} K 1 , n denotes the complete bipartite graph with part sizes 1 1 1 and n n n (i.e., V ( K 1 , n ) = [ n + 1 ] V(K_{1,n}) = [n + 1] V ( K 1 , n ) = [ n + 1 ] and E ( K 1 , n ) = { { 1 , i } : 2 ≤ i ≤ n + 1 } E(K_{1,n}) = \{\{1, i\} : 2 \le i \le n + 1\} E ( K 1 , n ) = {{ 1 , i } : 2 ≤ i ≤ n + 1 } ), and C n C_n C n denotes the cycle on n n n vertices (i.e., V ( C n ) = [ n ] V(C_n) = [n] V ( C n ) = [ n ] and E ( C n ) = { { i , i + 1 } : 1 ≤ i ≤ n − 1 } ∪ { { n , 1 } } E(C_n) = \{\{i, i + 1\} : 1 \le i \le n - 1\} \cup\{\{n, 1\}\} E ( C n ) = {{ i , i + 1 } : 1 ≤ i ≤ n − 1 } ∪ {{ n , 1 }} ).
Let H H H and G G G be graphs. A homomorphism from H H H to G G G is a map ϕ : V ( H ) → V ( G ) \phi: V(H) \to V(G) ϕ : V ( H ) → V ( G ) that preserves adjacency, i.e., { ϕ ( u ) , ϕ ( v ) } ∈ E ( G ) \{\phi(u), \phi(v)\} \in E(G) { ϕ ( u ) , ϕ ( v )} ∈ E ( G ) for every { u , v } ∈ E ( H ) \{u, v\} \in E(H) { u , v } ∈ E ( H ) . The homomorphism density from H H H to G G G , denoted t ( H , G ) t(H, G) t ( H , G ) , is the probability that a uniformly random map ϕ : V ( H ) → V ( G ) \phi: V(H) \to V(G) ϕ : V ( H ) → V ( G ) is a homomorphism. Equivalently,
t ( H , G ) : = 1 v ( G ) v ( H ) ∑ ϕ : V ( H ) → V ( G ) ∏ { u , v } ∈ E ( H ) I [ { ϕ ( u ) , ϕ ( v ) } ∈ E ( G ) ] . (2) t(H,G) := \frac{1}{v(G)^{v(H)}} \sum_{\phi:V(H)\to V(G)} \prod_{\{u,v\}\in E(H)} \mathbb{I}[\{\phi(u),\phi(v)\}\in E(G)] . \tag*{(2)} t ( H , G ) := v ( G ) v ( H ) 1 ϕ : V ( H ) → V ( G ) ∑ { u , v } ∈ E ( H ) ∏ I [{ ϕ ( u ) , ϕ ( v )} ∈ E ( G )] . (2)
where I [ ⋅ ] \mathbb{I}[\cdot] I [ ⋅ ] is the indicator function. Homomorphism densities are a natural language for extremal graph problems: they are size-normalised statistics of fixed patterns, so objectives and constraints are comparable across graphs of different sizes, and they are central to dense graph limit theory, quasirandomness, and regularity-based approximation [24 ] .
A graphon W W W is a symmetric measurable function W : [ 0 , 1 ] 2 → [ 0 , 1 ] W : [0, 1]^2 \to[0, 1] W : [ 0 , 1 ] 2 → [ 0 , 1 ] . Intuitively, W W W can be viewed as the (probabilistic) adjacency matrix of a continuum graph with vertex set [ 0 , 1 ] [0, 1] [ 0 , 1 ] : W ( x , y ) W(x, y) W ( x , y ) is the probability of an edge between x x x and y y y . Graphons arise as limits of dense graphs: along any graph sequence ( G n ) n ∈ N (G_n)_{n\in\mathbb{N}} ( G n ) n ∈ N whose homomorphism densities t ( H , G n ) t(H, G_n) t ( H , G n ) converge for every fixed graph H H H with vertex set [ v ( H ) ] [v(H)] [ v ( H )] , there is a graphon W W W with t ( H , G n ) → t ( H , W ) t(H, G_n) \to t(H, W) t ( H , G n ) → t ( H , W ) for every H H H with vertex set [ v ( H ) ] [v(H)] [ v ( H )] , where t ( H , W ) t(H, W) t ( H , W ) is the graphon homomorphism density of H H H in W W W defined by
t ( H , W ) : = E x 1 , … , x v ( H ) ∼ i i d Unif [ 0 , 1 ] [ ∏ { i , j } ∈ E ( H ) W ( x i , x j ) ] . (3) t(H,W) := \mathbb{E}_{x_1,\ldots,x_{v(H)}\mathrel{\overset{\mathrm{iid}}{\sim}}\operatorname{Unif}[0,1]}\left[\prod_{\{i,j\}\in E(H)} W(x_i,x_j)\right]. \tag*{(3)} t ( H , W ) := E x 1 , … , x v ( H ) ∼ iid Unif [ 0 , 1 ] { i , j } ∈ E ( H ) ∏ W ( x i , x j ) . (3)
Conversely, every graphon arises in this way [26 , 24 ] . Familiar discrete structure is reflected in W W W : balanced complete bipartite graphs converge to the two-block graphon equal to 1 1 1 on the off-diagonal blocks and 0 0 0 on the diagonal blocks; an Erdős–Rényi G ( n , q ) G(n,q) G ( n , q ) converges to the constant graphon W ≡ q W \equiv q W ≡ q ; a stochastic block model converges to a multi-block graphon whose blocks correspond to the communities.
Graphons provide a common language for both problem families studied in this paper: the objective and constraints in each involve graph homomorphism densities t ( H , W ) t(H, W) t ( H , W ) or closely related graphon integrals, and the structure of the optimal graphons is the central object of interest. The first family arises from extremal graph theory, where optimising over graphs is equivalent to optimising the corresponding asymptotic finite-graph problem [24 ] ; the second arises from the large deviation theory of dense random graphs. We describe each in turn. Constrained density minimisation. The first problem family is concerned with minimising the homomorphism density of a fixed graph H H H subject to a fixed edge density p p p . To state the asymptotic problem formally, we phrase it in terms of graph sequences:
inf { lim inf n → ∞ t ( H , G n ) | ( G n ) is a graph sequence with v ( G n ) → ∞ and t ( K 2 , G n ) → p } . (4) \inf\left\{ \liminf_{n\to\infty} t(H,G_n) \,\middle|\, (G_n)\text{ is a graph sequence with }v(G_n)\to\infty\text{ and }t(K_2,G_n)\to p \right\}. \tag*{(4)} inf { n → ∞ lim inf t ( H , G n ) ( G n ) is a graph sequence with v ( G n ) → ∞ and t ( K 2 , G n ) → p } . (4)
By the graph-limit theory [24 ] , this equals min W : t ( K 2 , W ) = p t ( H , W ) \min_{W:t(K_2,W)=p} t(H,W) min W : t ( K 2 , W ) = p t ( H , W ) , the graphon problem our method optimises directly. It generalises Turán’s theorem [47 ] and the Erdős–Stone–Simonovits theorem [13 , 12 ] . These classical results in extremal graph theory say that for every H H H with at least one edge and p ≤ 1 − 1 / ( χ ( H ) − 1 ) p\leq1-1/(\chi(H)-1) p ≤ 1 − 1/ ( χ ( H ) − 1 ) , where χ ( H ) \chi(H) χ ( H ) is the chromatic number of H H H , the optimum is 0. But for p > 1 − 1 / ( χ ( H ) − 1 ) p>1-1/(\chi(H)-1) p > 1 − 1/ ( χ ( H ) − 1 ) , the problem is much harder. It is completely solved only for cliques: H = K r H=K_r H = K r for all r ≥ 3 r\geq3 r ≥ 3 [42 ] , with earlier results for r = 3 r=3 r = 3 [40 ] and r = 4 r=4 r = 4 [32 ] . For C 5 C_5 C 5 , the minimiser is known only at the special values p = 1 − 1 / k p=1-1/k p = 1 − 1/ k (k k k a positive integer) [4 ] .
Variational problem from large deviation theory. The large deviation theory of dense random graphs addresses two related questions: at what exponential rate does the Erdős–Rényi random graph G ( n , q ) G(n,q) G ( n , q ) have an atypically large or small homomorphism density, and what does the graph typically look like when such a rare event occurs? These questions are of fundamental interest in probability theory and combinatorics, and they carry information-theoretic structure that is natural from an ML perspective: the Chatterjee–Varadhan framework reduces both questions to a single constrained optimisation over graphons whose objective is an averaged KL divergence [8 ] .
Concretely, fix q ∈ ( 0 , 1 ) q\in(0,1) q ∈ ( 0 , 1 ) and let h q ( W ) : = ∫ [ 0 , 1 ] 2 KL ( Bern ( W ( x , y ) ) ∥ Bern ( q ) ) d x d y h_q(W):=\int_{[0,1]^2}\operatorname{KL}(\operatorname{Bern}(W(x,y))\mathbin{\|}\operatorname{Bern}(q))\,\mathrm{d}x\,\mathrm{d}y h q ( W ) := ∫ [ 0 , 1 ] 2 KL ( Bern ( W ( x , y )) ∥ Bern ( q )) d x d y , the integrated per-edge KL divergence of W W W from the base Erdős–Rényi graphon W ≡ q W\equiv q W ≡ q . For a fixed graph H H H and target level r ∈ ( 0 , 1 ) r\in(0,1) r ∈ ( 0 , 1 ) , the large deviation principle yields a variational characterisation of both tails. In the upper tail (r > q r>q r > q ), ( n 2 ) − 1 log Pr [ t ( H , G ( n , q ) ) ≥ r e ( H ) ] \binom{n}{2}^{-1}\log\Pr[t(H,G(n,q))\geq r^{e(H)}] ( 2 n ) − 1 log Pr [ t ( H , G ( n , q )) ≥ r e ( H ) ] converges to − min W : t ( H , W ) ≥ r e ( H ) h q ( W ) -\min_{W:t(H,W)\geq r^{e(H)}}h_q(W) − min W : t ( H , W ) ≥ r e ( H ) h q ( W ) . In the lower tail (r < q r<q r < q ), ( n 2 ) − 1 log Pr [ t ( H , G ( n , q ) ) ≤ r e ( H ) ] \binom{n}{2}^{-1}\log\Pr[t(H,G(n,q))\leq r^{e(H)}] ( 2 n ) − 1 log Pr [ t ( H , G ( n , q )) ≤ r e ( H ) ] converges to − min W : t ( H , W ) ≤ r e ( H ) h q ( W ) -\min_{W:t(H,W)\leq r^{e(H)}}h_q(W) − min W : t ( H , W ) ≤ r e ( H ) h q ( W ) . In either case, the typical structure of G ( n , q ) G(n,q) G ( n , q ) conditioned on the rare event is described by near-minimisers of the corresponding variational problem [27 ] . Thus the minimiser is the graphon closest in KL divergence to W ≡ q W\equiv q W ≡ q that explains the observed excess (upper tail) or deficit (lower tail) in the H H H -homomorphism density, in the same spirit as maximum-entropy modelling in ML. Even in the triangle case H = K 3 H=K_3 H = K 3 , it is not fully understood when the deviation localises (e.g. through a dense clique) versus spreads more uniformly, or what the minimisers look like across ( q , r ) (q,r) ( q , r ) .
Our method applies directly to the boundary form
min W : t ( H , W ) = r e ( H ) h q ( W ) (5) \min_{W:t(H,W)=r^{e(H)}} h_q(W) \tag*{(5)} W : t ( H , W ) = r e ( H ) min h q ( W ) (5)
which is equivalent to the inequality-constrained minimisations above (with ≥ \geq ≥ in the upper tail r > q r>q r > q and ≤ \leq ≤ in the lower tail r < q r<q r < q ).
Implicit neural representations of graphons
We tackle the two graphon optimisation problems introduced in § 2 :
(P1) min W : t ( K 2 , W ) = p t ( H , W ) , (P2) min W : t ( H , W ) = r e ( H ) h q ( W ) . (6) \begin{aligned}
\text{(P1)}\quad&\min_{W:t(K_2,W)=p} t(H,W), \qquad
\text{(P2)}\quad\min_{W:t(H,W)=r^{e(H)}} h_q(W). \tag*{(6)}
\end{aligned} (P1) W : t ( K 2 , W ) = p min t ( H , W ) , (P2) W : t ( H , W ) = r e ( H ) min h q ( W ) . (6)
for a graph H H H , reals p , q , r ∈ ( 0 , 1 ) p,q,r\in(0,1) p , q , r ∈ ( 0 , 1 ) , where W W W ranges over graphons. Both problems carry a single scalar equality constraint.
We represent W W W as a neural network f θ f_\theta f θ , recast these graphon optimisations as optimisations over the parameters θ \theta θ , and apply gradient-based training. A naive instantiation of this idea fails for three reasons. First, known optimal graphons are typically step functions, which standard architectures such as MLPs struggle to represent due to their bias toward smooth functions. Second, the scalar constraints in (P1) and (P2) are poorly handled by penalty terms, so the architecture must enforce them more directly. Third, each occurrence of t ( ⋅ , W ) t(\cdot, W) t ( ⋅ , W ) involves an intractable integral, and estimating these expectations efficiently requires problem-specific sampling. The remainder of this section describes the architecture and training procedure that address these three challenges.
Architecture. We parameterise graphons by a residual MLP that injects a layer-specific sinusoidal encoding of the input at every layer. To handle constraints in (P1) and (P2), the architecture additionally includes a constraint solver.
Fix the number of layers L ≥ 2 L \ge2 L ≥ 2 , the hidden-layer width d d d , and a differentiable activation ϕ : R → R \phi: \mathbb{R} \to\mathbb{R} ϕ : R → R . Also, fix an increasing function s : [ L ] → ( 0 , ∞ ) s : [L] \to(0,\infty) s : [ L ] → ( 0 , ∞ ) , which determines the scale of weight initialisation at each layer; in our experiments, we use s ( ℓ ) = 2 ℓ − 1 s(\ell) = 2^{\ell-1} s ( ℓ ) = 2 ℓ − 1 . The network f θ [ c ] : [ 0 , 1 ] 2 → [ 0 , 1 ] f_{\theta[c]} : [0,1]^2 \to[0,1] f θ [ c ] : [ 0 , 1 ] 2 → [ 0 , 1 ] has a distinguished scalar bias c ∈ R c \in\mathbb{R} c ∈ R and remaining parameters θ \theta θ , and is defined for 2 ≤ ℓ ≤ L 2 \le\ell\le L 2 ≤ ℓ ≤ L by
f θ [ c ] ( x 1 , x 2 ) : = s m ( V g θ ( L ) ( min ( x 1 , x 2 ) , max ( x 1 , x 2 ) ) + c ) , g θ ( 1 ) ( x ) : = sin ( U ( 1 ) x + b ( 1 ) ) , g θ ( ℓ ) ( x ) : = g θ ( ℓ − 1 ) ( x ) + ϕ ( V g θ ( ℓ − 1 ) ( x ) + W ( ℓ ) sin ( U ( ℓ ) x ) + b ( ℓ ) ) . \begin{aligned}
f_{\theta[c]}(x_1,x_2) &:= sm\bigl(Vg_{\theta}^{(L)}(\min(x_1,x_2),\max(x_1,x_2)) + c\bigr),\\
g_{\theta}^{(1)}(\mathbf{x}) &:= \sin(U^{(1)}\mathbf{x} + b^{(1)}),\\
g_{\theta}^{(\ell)}(\mathbf{x}) &:= g_{\theta}^{(\ell-1)}(\mathbf{x}) + \phi\bigl(Vg_{\theta}^{(\ell-1)}(\mathbf{x}) + W^{(\ell)}\sin(U^{(\ell)}\mathbf{x}) + b^{(\ell)}\bigr).
\end{aligned} f θ [ c ] ( x 1 , x 2 ) g θ ( 1 ) ( x ) g θ ( ℓ ) ( x ) := s m ( V g θ ( L ) ( min ( x 1 , x 2 ) , max ( x 1 , x 2 )) + c ) , := sin ( U ( 1 ) x + b ( 1 ) ) , := g θ ( ℓ − 1 ) ( x ) + ϕ ( V g θ ( ℓ − 1 ) ( x ) + W ( ℓ ) sin ( U ( ℓ ) x ) + b ( ℓ ) ) .
Here s m sm s m is the sigmoid, and g θ ( 1 ) , g θ ( ℓ ) g_{\theta}^{(1)}, g_{\theta}^{(\ell)} g θ ( 1 ) , g θ ( ℓ ) are maps from { x = ( x 1 , x 2 ) ∈ [ 0 , 1 ] 2 : x 1 ≤ x 2 } \{\mathbf{x}=(x_1,x_2)\in[0,1]^2:x_1\le x_2\} { x = ( x 1 , x 2 ) ∈ [ 0 , 1 ] 2 : x 1 ≤ x 2 } to R d \mathbb{R}^d R d . The network parameters are c ∈ R c\in\mathbb{R} c ∈ R , b i ( ℓ ′ ) ∈ R d b_i^{(\ell')}\in\mathbb{R}^d b i ( ℓ ′ ) ∈ R d , V ∈ R 1 × d V\in\mathbb{R}^{1\times d} V ∈ R 1 × d , U ( ℓ ′ ) ∈ R d × 2 U^{(\ell')}\in\mathbb{R}^{d\times2} U ( ℓ ′ ) ∈ R d × 2 , and V ( ℓ ′ ′ ) , W ( ℓ ′ ) ∈ R d × d V^{(\ell'')}, W^{(\ell')}\in\mathbb{R}^{d\times d} V ( ℓ ′′ ) , W ( ℓ ′ ) ∈ R d × d , for ℓ ′ ∈ [ L ] \ell'\in[L] ℓ ′ ∈ [ L ] , ℓ ′ ′ ∈ [ L − 1 ] \ell''\in[L-1] ℓ ′′ ∈ [ L − 1 ] . These parameters are initialised independently by
c , b i ( ℓ ′ ) , V 1 , i , V i , j ( ℓ ′ ′ ) , W i , j ( ℓ ′ ) ∼ i i d Unif [ − 1 2 d , 1 2 d ] , U i , k ( ℓ ′ ) ∼ i i d Unif [ − s ( ℓ ′ ) 2 , s ( ℓ ′ ) 2 ] , c,\ b_i^{(\ell')},\ V_{1,i},\ V_{i,j}^{(\ell'')},\ W_{i,j}^{(\ell')} \mathrel{\overset{\mathrm{iid}}{\sim}} \operatorname{Unif}\left[-\frac{1}{\sqrt{2d}},\frac{1}{\sqrt{2d}}\right],\qquad U_{i,k}^{(\ell')} \mathrel{\overset{\mathrm{iid}}{\sim}} \operatorname{Unif}\left[-\frac{s(\ell')}{\sqrt{2}},\frac{s(\ell')}{\sqrt{2}}\right], c , b i ( ℓ ′ ) , V 1 , i , V i , j ( ℓ ′′ ) , W i , j ( ℓ ′ ) ∼ iid Unif [ − 2 d 1 , 2 d 1 ] , U i , k ( ℓ ′ ) ∼ iid Unif [ − 2 s ( ℓ ′ ) , 2 s ( ℓ ′ ) ] ,
for all i , j ∈ [ d ] i,j\in[d] i , j ∈ [ d ] , k ∈ [ 2 ] k\in[2] k ∈ [ 2 ] . We collect every parameter except c c c into θ \theta θ . Using min and max in the definition of f θ [ c ] f_{\theta[c]} f θ [ c ] ensures that f θ [ c ] f_{\theta[c]} f θ [ c ] is symmetric and represents a graphon.
The architecture has two notable features. First, it repeatedly injects a sinusoidal encoding of the input ( x 1 , x 2 ) (x_1,x_2) ( x 1 , x 2 ) at every layer, with an encoding scale that grows with depth. Increasing s ( ℓ ) s(\ell) s ( ℓ ) with depth shifts higher-frequency content into deeper layers [45 ] and encourages late layers to capture sharp boundaries, while early layers stabilise the coarse, low-frequency structure, an inductive bias that fits step-like graphons.
Second, in constrained problems, we determine c c c via a numerical solver rather than learning it directly. To enforce t ( K 2 , f θ [ c ] ) = p t(K_2,f_{\theta[c]})=p t ( K 2 , f θ [ c ] ) = p in (P1), we use a batch of K K K i.i.d. samples
E = { ( x 1 ( k ) , x 2 ( k ) ) } k ∈ [ K ] , ( x 1 ( k ) , x 2 ( k ) ) ∼ i i d Unif ( [ 0 , 1 ] 2 ) , \mathcal{E}=\left\{\left(x_1^{(k)},x_2^{(k)}\right)\right\}_{k\in[K]},\qquad\left(x_1^{(k)},x_2^{(k)}\right)\mathrel{\overset{\mathrm{iid}}{\sim}}\operatorname{Unif}([0,1]^2), E = { ( x 1 ( k ) , x 2 ( k ) ) } k ∈ [ K ] , ( x 1 ( k ) , x 2 ( k ) ) ∼ iid Unif ([ 0 , 1 ] 2 ) ,
and define
Solve θ ( E , p ) : = the unique c ∈ R such that 1 ∣ E ∣ ∑ ( x 1 , x 2 ) ∈ E f θ [ c ] ( x 1 , x 2 ) = p . (7) \operatorname{Solve}_{\theta}(\mathcal{E},p):=\text{the unique }c\in\mathbb{R}\text{ such that }\frac{1}{|\mathcal{E}|}\sum_{(x_1,x_2)\in\mathcal{E}}f_{\theta[c]}(x_1,x_2)=p. \tag*{(7)} Solve θ ( E , p ) := the unique c ∈ R such that ∣ E ∣ 1 ( x 1 , x 2 ) ∈ E ∑ f θ [ c ] ( x 1 , x 2 ) = p . (7)
The left-hand side of the equation in (7) is an unbiased estimator of t ( K 2 , f θ [ c ] ) t(K_2,f_{\theta[c]}) t ( K 2 , f θ [ c ] ) , so the equation is the empirical counterpart of the constraint. The solution exists and is unique, since the left-hand side is continuous and strictly increasing in c c c and tends to 0 0 0 and 1 1 1 as c → − ∞ c\to-\infty c → − ∞ and c → + ∞ c\to+\infty c → + ∞ , respectively. We solve (7) with a clipped variant of Newton’s method (Algorithm 1) and use the resulting c ∗ c^* c ∗ when evaluating f θ [ c ∗ ] f_{\theta[c^*]} f θ [ c ∗ ] on other inputs. The same idea applies to any single homomorphism-density constraint of the form t ( H , W ) = τ t(H,W)=\tau t ( H , W ) = τ : one replaces the edge-density estimator in (7) by an estimator of t ( H , f θ [ c ] ) t(H,f_{\theta[c]}) t ( H , f θ [ c ] ) . Because increasing the scalar bias c c c increases every edge probability, this estimator remains monotone in c c c . For the large-deviation application (P2) with H = K 3 H = K_3 H = K 3 , for instance, this means sampling triples ( x 1 ( k ) , x 2 ( k ) , x 3 ( k ) ) (x_1^{(k)}, x_2^{(k)}, x_3^{(k)}) ( x 1 ( k ) , x 2 ( k ) , x 3 ( k ) ) , storing those samples in T \mathcal{T} T , and solving the empirical equation
1 ∣ T ∣ ∑ ( x 1 , x 2 , x 3 ) ∈ T f θ [ c ] ( x 1 , x 2 ) f θ [ c ] ( x 2 , x 3 ) f θ [ c ] ( x 3 , x 1 ) = r 3 . \frac{1}{|\mathcal{T}|} \sum_{(x_1,x_2,x_3)\in\mathcal{T}} f_{\theta[c]}(x_1,x_2)f_{\theta[c]}(x_2,x_3)f_{\theta[c]}(x_3,x_1) = r^3. ∣ T ∣ 1 ( x 1 , x 2 , x 3 ) ∈ T ∑ f θ [ c ] ( x 1 , x 2 ) f θ [ c ] ( x 2 , x 3 ) f θ [ c ] ( x 3 , x 1 ) = r 3 .
The same construction applies to any other pattern graph H H H by replacing the triangle-density estimator with the corresponding H H H -density estimator from (8) .
Estimating homomorphism density. Let H H H be a graph with vertex set [ v ( H ) ] [v(H)] [ v ( H )] . By (3) , t ( H , f θ [ c ] ) t(H, f_{\theta[c]}) t ( H , f θ [ c ] ) is an expectation that we estimate by Monte Carlo sampling. Our estimator is parameterised by a set S \mathcal{S} S of permutations of [ v ( H ) ] [v(H)] [ v ( H )] . It draws ( N ⋅ v ( H ) ) (N \cdot v(H)) ( N ⋅ v ( H )) i.i.d. samples x i ( k ) ∼ i i d Unif [ 0 , 1 ] x_i^{(k)} \overset{\mathrm{iid}}{\sim} \operatorname{Unif}[0,1] x i ( k ) ∼ iid Unif [ 0 , 1 ] for ( k , i ) ∈ [ N ] × [ v ( H ) ] (k,i) \in[N] \times[v(H)] ( k , i ) ∈ [ N ] × [ v ( H )] , and then computes
t ^ ( H , f θ [ c ] ) : = 1 N ∣ S ∣ ∑ k ∈ [ N ] , π ∈ S ∏ { i , j } ∈ E ( H ) f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) . (8) \widehat{t}(H, f_{\theta[c]}) := \frac{1}{N|\mathcal{S}|} \sum_{k\in[N],\pi\in\mathcal{S}} \prod_{\{i,j\}\in E(H)} f_{\theta[c]}(x_{\pi(i)}^{(k)},x_{\pi(j)}^{(k)}). \tag*{(8)} t ( H , f θ [ c ] ) := N ∣ S ∣ 1 k ∈ [ N ] , π ∈ S ∑ { i , j } ∈ E ( H ) ∏ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) . (8)
The estimator is unbiased for any choice of S \mathcal{S} S (Lemma E.1 ); the choice of S \mathcal{S} S controls variance and computational cost. When S = { i d } \mathcal{S} = \{\mathrm{id}\} S = { id } , our estimator in (8) is the standard Monte Carlo estimator using N N N independent samples of ( x 1 , … , x v ( H ) ) (x_1,\ldots,x_{v(H)}) ( x 1 , … , x v ( H ) ) . With multiple permutations, the same N N N tuples are reused across the ∣ S ∣ |\mathcal{S}| ∣ S ∣ permuted copies, often producing lower variance for the same number of independent tuples. Different permutations also induce repeated evaluations of the network f θ [ c ] f_{\theta[c]} f θ [ c ] on the same unordered pair ( x i ( k ) , x j ( k ) ) (x_i^{(k)},x_j^{(k)}) ( x i ( k ) , x j ( k ) ) across summands, so caching the evaluations reduces the number of network evaluations from N ⋅ ∣ S ∣ ⋅ e ( H ) N \cdot|\mathcal{S}| \cdot e(H) N ⋅ ∣ S ∣ ⋅ e ( H ) to N ⋅ C ⋅ e ( H ) N \cdot C \cdot e(H) N ⋅ C ⋅ e ( H ) for some C ≤ ∣ S ∣ C \leq|\mathcal{S}| C ≤ ∣ S ∣ that depends on S \mathcal{S} S and H H H . We exploit this for larger graphs (e.g., the Petersen graph in §G).
Training algorithm. For (P1), fix a graph H H H on [ v ( H ) ] [v(H)] [ v ( H )] and p ∈ ( 0 , 1 ) p \in(0,1) p ∈ ( 0 , 1 ) . At each iteration, we sample ( N ⋅ v ( H ) ) (N \cdot v(H)) ( N ⋅ v ( H )) i.i.d. uniform values { x i ( k ) } ( i , k ) ∈ [ N ] × [ v ( H ) ] \{x_i^{(k)}\}_{(i,k)\in[N]\times[v(H)]} { x i ( k ) } ( i , k ) ∈ [ N ] × [ v ( H )] on [ 0 , 1 ] [0,1] [ 0 , 1 ] , and form D = { ( x 1 ( k ) , … , x v ( H ) ( k ) ) : k ∈ [ N ] } \mathcal{D} = \{(x_1^{(k)},\ldots,x_{v(H)}^{(k)}): k \in[N]\} D = {( x 1 ( k ) , … , x v ( H ) ( k ) ) : k ∈ [ N ]} and the unordered-pair set E = { ( x i ( k ) , x j ( k ) ) : k ∈ [ N ] , 1 ≤ i < j ≤ v ( H ) } \mathcal{E} = \{(x_i^{(k)},x_j^{(k)}): k \in[N],\ 1 \leq i < j \leq v(H)\} E = {( x i ( k ) , x j ( k ) ) : k ∈ [ N ] , 1 ≤ i < j ≤ v ( H )} . Then, we set c θ : = Solve θ ( E , p ) c_\theta:= \operatorname{Solve}_\theta(\mathcal{E},p) c θ := Solve θ ( E , p ) to enforce the empirical constraint, and update
θ t + 1 ← θ t − η t ∇ θ t ^ D ( H , f θ [ c θ ] ) ∣ θ = θ t , \theta_{t+1} \leftarrow\theta_t - \eta_t \left.\nabla_\theta\widehat{t}_{\mathcal{D}}(H, f_{\theta[c_\theta]})\right|_{\theta=\theta_t}, θ t + 1 ← θ t − η t ∇ θ t D ( H , f θ [ c θ ] ) θ = θ t ,
where t ^ D \widehat{t}_{\mathcal{D}} t D denotes the estimator in (8) evaluated on the tuples in D \mathcal{D} D . Reusing the x i ( k ) x_i^{(k)} x i ( k ) across D \mathcal{D} D and E \mathcal{E} E saves forward evaluations of f θ [ c ] f_{\theta[c]} f θ [ c ] . We resample ( D , E ) (\mathcal{D},\mathcal{E}) ( D , E ) at every iteration to mitigate overfitting to particular Monte Carlo samples. We set η t \eta_t η t via a cosine-annealing schedule [23 ] , which alternates between discovering coarse structure (high learning rate) and refining sharp boundaries (low learning rate).
Computing ∇ θ t ^ D ( H , f θ [ c θ ] ) \nabla_\theta\widehat{t}_{\mathcal{D}}(H, f_{\theta[c_\theta]}) ∇ θ t D ( H , f θ [ c θ ] ) requires only the standard product rule once ∇ θ f θ [ c θ ] \nabla_\theta f_{\theta[c_\theta]} ∇ θ f θ [ c θ ] is known; the only non-routine ingredient is the gradient of the solver output c θ c_\theta c θ with respect to θ \theta θ , which we compute via implicit differentiation. A direct alternative is to differentiate through an unrolled Newton iteration with autodiff, but this requires storing every intermediate iterate and is substantially more expensive in time and memory; the same trade-off motivates implicit-differentiation methods in deep equilibrium models [3 ] and neural ODEs [9 ] . The closed-form gradient is given by:
Lemma 3.1. For all x ∈ [ 0 , 1 ] 2 \mathbf{x} \in[0,1]^2 x ∈ [ 0 , 1 ] 2 ,
∇ θ f θ [ c θ ] ( x ) = ∂ f θ [ c ] ( x ) ∂ θ ∣ c = c θ − s m ′ ( h θ ( x ) + c θ ) ∑ y ∈ E w θ ( y ) ∇ θ h θ ( y ) , \nabla_\theta f_{\theta[c_\theta]}(\mathbf{x}) = \left.\frac{\partial f_{\theta[c]}(\mathbf{x})}{\partial\theta}\right|_{c=c_\theta} - sm'(h_\theta(\mathbf{x})+c_\theta)\sum_{\mathbf{y}\in\mathcal{E}} w_\theta(\mathbf{y})\nabla_\theta h_\theta(\mathbf{y}), ∇ θ f θ [ c θ ] ( x ) = ∂ θ ∂ f θ [ c ] ( x ) c = c θ − s m ′ ( h θ ( x ) + c θ ) y ∈ E ∑ w θ ( y ) ∇ θ h θ ( y ) , where w θ ( y ) : = s m ′ ( h θ ( y ) + c θ ) ∑ z ∈ E s m ′ ( h θ ( z ) + c θ ) w_\theta(\mathbf{y}) := \frac{sm'(h_\theta(\mathbf{y})+c_\theta)}{\sum_{\mathbf{z}\in\mathcal{E}} sm'(h_\theta(\mathbf{z})+c_\theta)} w θ ( y ) := ∑ z ∈ E s m ′ ( h θ ( z ) + c θ ) s m ′ ( h θ ( y ) + c θ ) , \quad h θ ( x 1 , x 2 ) : = V g θ ( L ) ( min ( x 1 , x 2 ) , max ( x 1 , x 2 ) ) h_\theta(x_1,x_2) := V^{(L)}_{g_\theta}(\min(x_1,x_2),\max(x_1,x_2)) h θ ( x 1 , x 2 ) := V g θ ( L ) ( min ( x 1 , x 2 ) , max ( x 1 , x 2 )) .
:::`
Table 1. K 3 K_3 K 3 densities in graphons found by our method and optimal construction for K 3 K_3 K 3 density minimisation under t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p .
Table 2. K k K_k K k densities in graphons found by our method and the optimal construction for K k K_k K k density minimisation under t ( K 2 , W ) = 1 − 1 / k t(K_2,W)=1-1/k t ( K 2 , W ) = 1 − 1/ k .
For (P2), despite its different mathematical origins in large deviation theory, the same constrained loop applies with two substitutions: for a given pattern graph H H H and 0 < q < 1 0<q<1 0 < q < 1 with target r ≠ q r\ne q r = q , the edge-density solver is replaced by the H H H -density solver targeting t ( H , f θ [ c ] ) = r e ( H ) t(H,f_\theta[c])=r^{e(H)} t ( H , f θ [ c ]) = r e ( H ) , and the objective is replaced by the Monte Carlo estimate of h q ( f θ [ c θ ] ) = ∫ [ 0 , 1 ] 2 KL ( Bern ( f θ [ c θ ] ( x , y ) ) ∥ Bern ( q ) ) d x d y h_q(f_\theta[c_\theta])=\int_{[0,1]^2}\operatorname{KL}(\operatorname{Bern}(f_\theta[c_\theta](x,y))\mathbin{\|}\operatorname{Bern}(q))\,\mathrm{d}x\,\mathrm{d}y h q ( f θ [ c θ ]) = ∫ [ 0 , 1 ] 2 KL ( Bern ( f θ [ c θ ] ( x , y )) ∥ Bern ( q )) d x d y , obtained by averaging KL ( Bern ( f θ [ c θ ] ( x , y ) ) ∥ Bern ( q ) ) \operatorname{KL}(\operatorname{Bern}(f_\theta[c_\theta](x,y))\mathbin{\|}\operatorname{Bern}(q)) KL ( Bern ( f θ [ c θ ] ( x , y )) ∥ Bern ( q )) over a fresh batch of pairs ( x , y ) (x,y) ( x , y ) . The sigmoid output ensures the KL objective is differentiable in θ \theta θ , and an analogous implicit-differentiation formula applies to the H H H -density constraint.
Experimental results
We evaluate our framework on instances of (P1) and (P2) drawn from the extremal-graph-theory and large-deviation literatures. The same architecture, solver, and training loop are used throughout; the only changes between problem families are which constraint is enforced and how the objective is estimated. The experiments are organised to demonstrate two capabilities: (i) rediscovering classical optima that previously required substantial human effort, and (ii) producing mathematically interesting candidates for open instances. An ablation study at the end isolates the contribution of each architectural component.
We visualise graphons as Viridis heatmaps (blue = 0, yellow = 1) (Figure 1 ). Reported homomorphism densities are either numerically computed by discretising the learnt graphon into an M × M M\times M M × M weighted adjacency matrix, or estimated using 2 28 2^{28} 2 28 samples with a 95% bootstrap confidence interval (shown in italic font) when discretisation is infeasible. Across training runs over the 8 configurations of activation and learning rate ( ϕ , η ) ∈ { G E L U , sin } × { 10 − 3 , 5 × 10 − 4 , 10 − 4 , 5 × 10 − 5 } (\phi,\eta) \in\{\mathrm{GELU},\sin\} \times\{10^{-3}, 5 \times10^{-4}, 10^{-4}, 5 \times10^{-5}\} ( ϕ , η ) ∈ { GELU , sin } × { 1 0 − 3 , 5 × 1 0 − 4 , 1 0 − 4 , 5 × 1 0 − 5 } , we report the lowest-objective run; reported values should be read as best-found candidate upper bounds, and the bootstrap intervals quantify Monte Carlo estimation error rather than variability across runs. See §F for details.
Figure 1. Graphons found by our method for K 3 K_3 K 3 density minimisation under t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p .
Constrained homomorphism-density minimisation. We apply our method to (P1) across three classes of instances: clique densities (H = K n H=K_n H = K n , fully solved [40 , 42 ] ), odd-cycle densities (H = C 5 , C 7 H=C_5,C_7 H = C 5 , C 7 , partly open), and a systematic sweep over 117 non-bipartite graphs with v ( H ) ≤ 6 v(H) \le6 v ( H ) ≤ 6 . The clique experiments validate the method against known optima; the latter two produce new candidate minimisers and, through the exhaustive sweep, a previously unreported family of extremal structures. We describe each in turn.
Clique densities (H = K n H=K_n H = K n ). We begin with the case n = 3 n=3 n = 3 . When p = 1 − 1 / k p=1-1/k p = 1 − 1/ k for some integer k ≥ 2 k \ge2 k ≥ 2 , the optimal graphon is the complete k k k -partite graphon or any of its measure-preserving permutations. For i ∈ [ k ] i \in[k] i ∈ [ k ] , let X i = ( ( i − 1 ) / k , i / k ] X_i=((i-1)/k,i/k] X i = (( i − 1 ) / k , i / k ] . The complete k k k -partite graphon W k W_k W k is defined as follows: W k ( x 1 , x 2 ) = 1 W_k(x_1,x_2)=1 W k ( x 1 , x 2 ) = 1 if x 1 ∈ X i x_1 \in X_i x 1 ∈ X i and x 2 ∈ X j x_2 \in X_j x 2 ∈ X j with i ≠ j i \ne j i = j ; otherwise, W k ( x 1 , x 2 ) = 0 W_k(x_1,x_2)=0 W k ( x 1 , x 2 ) = 0 . For a measure-preserving ϕ \phi ϕ on [ 0 , 1 ] [0,1] [ 0 , 1 ] , its permutation is W k , ϕ ( x 1 , x 2 ) = W k ( ϕ ( x 1 ) , ϕ ( x 2 ) ) W_{k,\phi}(x_1,x_2)=W_k(\phi(x_1),\phi(x_2)) W k , ϕ ( x 1 , x 2 ) = W k ( ϕ ( x 1 ) , ϕ ( x 2 )) . Every optimum is of this form in this case of p = 1 − 1 / k p=1-1/k p = 1 − 1/ k . When 1 − 1 / k < p < 1 − 1 / ( k + 1 ) 1-1/k < p < 1-1/(k+1) 1 − 1/ k < p < 1 − 1/ ( k + 1 ) , the minimisation admits multiple types of optima. One example is a variant W p W_p W p of W k + 1 W_{k+1} W k + 1 , where the first k k k parts are equal in length but the last part X k + 1 X_{k+1} X k + 1 is shorter. Again, its permutations W p , ϕ W_{p,\phi} W p , ϕ by measure-preserving ϕ \phi ϕ on [ 0 , 1 ] [0,1] [ 0 , 1 ] are also optimal, though the W p , ϕ W_{p,\phi} W p , ϕ do not exhaust all optima.
Table 5. H 6 H_6 H 6 densities in graphons found by our method, the k k k -partite construction, and the constant graphon, for H 6 H_6 H 6 density minimisation under t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p .
We considered p ∈ { 1 / 2 , 2 / 3 , 4 / 5 , 4 / 7 , 5 / 8 , 5 / 7 } p \in\{1/2,2/3,4/5,4/7,5/8,5/7\} p ∈ { 1/2 , 2/3 , 4/5 , 4/7 , 5/8 , 5/7 } . For the three cases with p = 1 − 1 / k p=1-1/k p = 1 − 1/ k (p ∈ { 1 / 2 , 2 / 3 , 4 / 5 } p \in\{1/2,2/3,4/5\} p ∈ { 1/2 , 2/3 , 4/5 } ), our method produced near-optimal graphons (top row of Figure 1 ) within 0.1% of the theoretical optima, closely matching the complete k k k -partite graphons W k W_k W k ; among the equivalent measure-preserving permutations, our method consistently converged to these simpler representatives. For p ∈ { 4 / 7 , 5 / 8 } p \in\{4/7,5/8\} p ∈ { 4/7 , 5/8 } , which satisfy 1 − 1 / k < p < 1 − 1 / ( k + 1 ) 1-1/k<p<1-1/(k+1) 1 − 1/ k < p < 1 − 1/ ( k + 1 ) , the learnt graphons (Figure 1 d and Figure 1 e) capture the core structure of the known optimal W p W_p W p . For p = 5 / 7 p=5/7 p = 5/7 , the learnt graphon (Figure 1 f) does not match W p W_p W p , but its bipartite middle-block structure matches the characterisation of all optimal graphons in [37 ] .
Turning to larger cliques (k > 3 k>3 k > 3 ), we ran min W t ( K k , W ) \min_W t(K_k,W) min W t ( K k , W ) s.t. t ( K 2 , W ) = 1 − 1 / k t(K_2,W)=1-1/k t ( K 2 , W ) = 1 − 1/ k for k ∈ { 4 , 5 , 6 } k \in\{4,5,6\} k ∈ { 4 , 5 , 6 } . Even though the larger motif size increases the variance of our estimator and the optimal graphon involves more blocks, our method recovers the complete k k k -partite structure (Figure 2 ).
Figure 2. Graphons found by our method for K k K_k K k density minimisation under t ( K 2 , W ) = 1 − 1 / k t(K_2,W)=1-1/k t ( K 2 , W ) = 1 − 1/ k .
Open problems: C 5 C_5 C 5 and C 7 C_7 C 7 . We next apply our method to two graphon optimisation problems that, to the best of our knowledge, remain open in the tested regimes: minimising the homomorphism densities of C 5 C_5 C 5 and C 7 C_7 C 7 , each under a fixed edge density p p p . In §G, we also report results for the Petersen graph, for which no prior optima or conjectured optima are known to us.
For C 5 C_5 C 5 , Bennett et al. [ [4 ] characterised the minimisers when p = 1 − 1 / k p=1-1/k p = 1 − 1/ k and conjectured them for other p p p . We applied our method for p ∈ { 1 / 2 , 2 / 3 , 4 / 5 , 4 / 7 , 5 / 8 , 5 / 7 } p \in\{1/2,2/3,4/5,4/7,5/8,5/7\} p ∈ { 1/2 , 2/3 , 4/5 , 4/7 , 5/8 , 5/7 } (Figure 3 ); the resulting values agree with the conjectured optima within 0.1% (Table 3 ). When p = 1 − 1 / k p=1-1/k p = 1 − 1/ k , the learnt graphon recovers the complete k k k -partite structure (top row); for other p p p , it exhibits pronounced diagonal (banded) structure (bottom row), suggesting a qualitatively different extremal configuration away from the breakpoints p = 1 − 1 / k p=1-1/k p = 1 − 1/ k . For C 7 C_7 C 7 , no prior results are known to us. Motivated by the C 5 C_5 C 5 results of Bennett et al. [ [4 ] , we propose a conjecture for the structure and optimum value of C 7 C_7 C 7 -minimising graphons under a fixed edge density; see §C. Empirically, our learnt graphons match our conjectured optima within 0.1% across all tested p p p (Table 4 ). For p ∈ { 1 / 2 , 2 / 3 , 4 / 5 } p \in\{1/2,2/3,4/5\} p ∈ { 1/2 , 2/3 , 4/5 } (p = 1 − 1 / k p=1-1/k p = 1 − 1/ k ), they recover the complete k k k -partite structure (top row of Figure 4 ); for p ∈ { 4 / 7 , 5 / 8 } p \in\{4/7,5/8\} p ∈ { 4/7 , 5/8 } , they show diagonal patterns similar to C 5 C_5 C 5 , suggesting that this is a common feature of odd-cycle minimisation; for p = 5 / 7 p=5/7 p = 5/7 , the structure is qualitatively different, with block-like rather than diagonal patterns (bottom-right of Figure 4 ).
Table 3. C 5 C_5 C 5 densities in graphons found by the known or conjectured optimal construction and our method for C 5 C_5 C 5 density minimisation under t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p .
Figure 3. Graphons found by our method for C 5 C_5 C 5 density minimisation under t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p . (a) p = 1 / 2 p=1/2 p = 1/2 . (b) p = 2 / 3 p=2/3 p = 2/3 . (c) p = 4 / 5 p=4/5 p = 4/5 . (d) p = 4 / 7 p=4/7 p = 4/7 . (e) p = 5 / 8 p=5/8 p = 5/8 . (f) p = 5 / 7 p=5/7 p = 5/7 .
Table 4. C 7 C_7 C 7 densities in graphons found by the conjectured optimal construction and our method for C 7 C_7 C 7 density minimisation under t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p .
Figure 4. Graphons found by our method for C 7 C_7 C 7 density minimisation under t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p . (a) p = 1 / 2 p=1/2 p = 1/2 . (b) p = 2 / 3 p=2/3 p = 2/3 . (c) p = 4 / 5 p=4/5 p = 4/5 . (d) p = 4 / 7 p=4/7 p = 4/7 . (e) p = 5 / 8 p=5/8 p = 5/8 . (f) p = 5 / 7 p=5/7 p = 5/7 .
Exhaustive study over small graphs. We now describe a systematic study enabled by our method. We applied our method to the problem (P1) in (6) for all non-bipartite graphs H H H with v ( H ) ≤ 6 v(H)\le6 v ( H ) ≤ 6 and with no isolated vertices or isolated edges, for a total of 117 graphs; isolated vertices and isolated edges are excluded because they only multiply t ( H , W ) t(H,W) t ( H , W ) by 1 and p p p , respectively. For each H H H , we trained our network under a single fixed hyperparameter configuration (GELU activation, learning rate 10 − 3 10^{-3} 1 0 − 3 ) with three random seeds to minimise t ( H , W ) t(H,W) t ( H , W ) subject to t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p , for the six densities p = 1 − 1 / ( k − 1 + j ) p=1-1/(k-1+j) p = 1 − 1/ ( k − 1 + j ) with j ∈ { 1 / 3 , 1 / 2 , 2 / 3 , 1 , 2 , 3 } j\in\{1/3,1/2,2/3,1,2,3\} j ∈ { 1/3 , 1/2 , 2/3 , 1 , 2 , 3 } , where k k k is the chromatic number of H H H . These values of p p p are chosen to probe the structure of the curve x ↦ min W : t ( K 2 , W ) = x t ( H , W ) x\mapsto\min_{W:t(K_2,W)=x}t(H,W) x ↦ min W : t ( K 2 , W ) = x t ( H , W ) : the values with j ∈ { 1 , 2 , 3 } j\in\{1,2,3\} j ∈ { 1 , 2 , 3 } correspond to breakpoints of piecewise-defined curves established for several classes of graphs [40 , 42 , 4 ] , while those with j < 1 j<1 j < 1 lie inside the segment ( k − 2 ) / ( k − 1 ) < p < ( k − 1 ) / k (k-2)/(k-1)<p<(k-1)/k ( k − 2 ) / ( k − 1 ) < p < ( k − 1 ) / k . To assess the optimality of our solutions, we computed lower bounds on the minimum H H H -density using flag algebras [39 ] on 7-vertex graphs.
Taking the best of the three seeds, the H H H -density of the learnt graphon is within 1% of the flag-algebra lower bound in 72.6% of the 702 ( H , p ) (H,p) ( H , p ) instances, and a graphon whose H H H -density is more than 1% smaller is known in 20.8% of them; neither holds for the remaining 6.6%.
Using the lower bounds, we also examined whether the minimum is convex or concave on the segment containing the three densities with j < 1 j<1 j < 1 . For 104 of the 117 graphs, including every graph with k = 3 k=3 k = 3 except K 3 K_3 K 3 , the minimum appears to be convex on this segment, as conjectured for odd cycles [4 ] ; for 7 graphs, it appears to be concave, as for cliques [42 ] ; and for 5 graphs, including K 6 K_6 K 6 minus an edge, it is neither convex nor concave. Our experiments also suggest a novel family of extremal graphon structures. When p = 1 − 1 / k p=1-1/k p = 1 − 1/ k , the minimisers for cliques and C 5 C_5 C 5 are known to be complete k k k -partite [42 , 4 ] , and we conjecture the same for C 7 C_7 C 7 ; in all three cases, our method recovers this structure (Figure 1 , Figure 3 and Figure 4 ). However, this is not universal: for the graph H 6 H_6 H 6 in Figure 5a at the same p p p , our method finds a candidate minimiser that is neither complete k k k -partite nor constant (Figure 5 ); the learnt graphons exhibit a geometric pattern in which edge probabilities appear to depend on the circular distance when [ 0 , 1 ] [0,1] [ 0 , 1 ] is interpreted as a circle.
(a) H 6 H_6 H 6 .
(b) p = 2 / 3 p=2/3 p = 2/3 .
(c) p = 3 / 4 p=3/4 p = 3/4 .
(d) p = 4 / 5 p=4/5 p = 4/5 .
Figure 5. The graph H 6 H_6 H 6 (six vertices, nine edges) and graphons found by our method for H 6 H_6 H 6 density minimisation under t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p .
Variational problem from large deviation theory. We apply our framework to (P2), the variational problem of Chatterjee and Varadhan [ [8 ] . We test ( q , r ) ∈ { 0.05 , 0.1 } × { 0.4 , 0.5 , 0.6 } (q,r)\in\{0.05,0.1\}\times\{0.4,0.5,0.6\} ( q , r ) ∈ { 0.05 , 0.1 } × { 0.4 , 0.5 , 0.6 } for upper-tail variational problems with H ∈ { K 3 , C 4 , C 5 , K 1 , 3 } H\in\{K_3,C_4,C_5,K_{1,3}\} H ∈ { K 3 , C 4 , C 5 , K 1 , 3 } , and ( q , r ) ∈ { 0.7 , 0.8 , 0.9 } × { 0.05 , 0.1 } (q,r)\in\{0.7,0.8,0.9\}\times\{0.05,0.1\} ( q , r ) ∈ { 0.7 , 0.8 , 0.9 } × { 0.05 , 0.1 } for lower-tail variational problems with H = K 3 H=K_3 H = K 3 ; in all these regimes, the structure of optimisers is, to our knowledge, not fully understood. As a reference for H = K 3 H=K_3 H = K 3 , we use the tripartite construction W L Z W_{\mathrm{LZ}} W LZ proposed by Lemma 3.4 of Lubetzky and Zhao [ [27 ] ; Table 6 compares h q ( W L Z ) h_q(W_{\mathrm{LZ}}) h q ( W LZ ) to h q ( W o u r s ) h_q(W_{\mathrm{ours}}) h q ( W ours ) at our learnt graphon W o u r s W_{\mathrm{ours}} W ours in the upper-tail regime. Qualitatively, our method consistently finds two-block structures for all graphs and in both upper- and lower-tail regimes. For the upper-tail problems, the 2-regular graphs K 3 K_3 K 3 , C 4 C_4 C 4 , C 5 C_5 C 5 share close edge densities and block sizes in their respective learnt graphons, while the non-2-regular graph K 1 , 3 K_{1,3} K 1 , 3 shows a qualitatively different structure with a much smaller block size; see Figure 6 for the learnt graphons with q = 0.1 , r = 0.5 q=0.1,r=0.5 q = 0.1 , r = 0.5 and §G for all upper-tail regimes. For the lower-tail problems, we obtain a qualitatively different structure of nearly-bipartite graphons. Quantitatively, in the upper-tail problems for H = K 3 H = K_3 H = K 3 , our method consistently finds graphons with lower relative entropy than the tripartite construction W L Z W_{\mathrm{LZ}} W LZ , showing that the latter is suboptimal in these regimes; see §G for details.
Figure 6. Learnt graphons for upper-tail variational problems with q = 0.1 , r = 0.5 q=0.1,r=0.5 q = 0.1 , r = 0.5 for H = K 3 , C 4 , C 5 , K 1 , 3 H=K_3,C_4,C_5,K_{1,3} H = K 3 , C 4 , C 5 , K 1 , 3 (left to right).
Table 6. Relative-entropy h q ( W ) h_q(W) h q ( W ) at our learnt graphon (W o u r s W_{\mathrm{ours}} W ours ) and at the tripartite construction W L Z W_{\mathrm{LZ}} W LZ of Lubetzky and Zhao [ [27 ] , for (P2) with H = K 3 H=K_3 H = K 3 on ( q , r ) ∈ { 0.05 , 0.1 } × { 0.4 , 0.5 , 0.6 } (q,r)\in\{0.05,0.1\}\times\{0.4,0.5,0.6\} ( q , r ) ∈ { 0.05 , 0.1 } × { 0.4 , 0.5 , 0.6 } , together with a lower bound on the optimum (§G). Lower is better.
Ablation study, baselines, and multi-task variant. To assess the contribution of each architectural component and to compare the neural approach with simpler alternatives, we ran an ablation study and four non-neural baselines on triangle-density minimisation under t ( K 2 , W ) = 7 / 9 t(K_2,W) = 7/9 t ( K 2 , W ) = 7/9 . Replacing the sinusoidal features with GELU features, the constraint solver with a regulariser, or the cosine-annealing schedule with a constant learning rate increases the triangle density, and using the sinusoidal encoding only in the first layer degrades the recovered block structure; the best constant encoding scale reaches a similar density. The four non-neural baselines tailored to step graphons (a fixed-block SBM with 256 blocks; SBMs with trainable block sizes; a decision tree; a tree ensemble) all reach higher triangle densities than our method. To explore whether a single model can handle multiple problem instances simultaneously, we also trained a FiLM-conditioned multi-task variant over p ∈ [ 1 / 2 , 2 / 3 ] p \in[1/2, 2/3] p ∈ [ 1/2 , 2/3 ] for H = K 3 H = K_3 H = K 3 [36 ] , which demonstrates that the architecture extends naturally to this setting. Full details are deferred to §I.
Acknowledgements
We thank Sangho Lim, Gyeongwon Jung, Seonghun Park, Seonghyuk Im, and Kyeongsik Nam for helpful discussions. T. Kim and H. Yang were supported by the National Research Foundation of Korea (NRF) grant funded by the Korean Government (MSIT) (No. RS-2023-00279680). H. Yang was also supported by a KIAS Individual Grant (CG109601) at the Korea Institute for Advanced Study. J. Lee was supported by Samsung STF Grant (SSTF-BA2201-02) and the National Research Foundation of Korea (NRF) grant funded by the Korean Government (MSIT) (No. NRF-2022R1C1C1010300). J. Baek was supported by KIAS Individual Grant (HP105001).
Related work
Implicit neural representations of graphons were introduced by Xia et al. [ [50 ] for graphon learning , and Azizpour et al. [ [2 ] proposed a scalable variant. In graphon learning, one observes a collection of graphs assumed to be sampled from a common unknown graphon and estimates this graphon from the samples. Recovering sharp details of the true graphon is not the focus of these methods, and such details are often lost in the learnt graphons; see, e.g., Azizpour et al. [ [2 ] , Figure 3 (b) and Figure 9 . Our setting is different: there is neither a graph dataset nor a target graphon, and we search directly over graphons to minimise a homomorphism-density or relative-entropy functional under a density constraint. Applying graphon learning to these problems would first require near-optimal finite graphs, which is itself a hard discrete optimisation problem.
Figure 9. Found graphon for lower tail variational problems for K 3 K_3 K 3 , for r = 0.05 r = 0.05 r = 0.05 (top) and r = 0.1 r = 0.1 r = 0.1 (bottom) and q = 0.7 , 0.8 , 0.9 q = 0.7, 0.8, 0.9 q = 0.7 , 0.8 , 0.9 (left to right).
Razborov’s flag algebra framework [39 ] enables proofs of inequalities between graph homomorphism densities by means of sums of squares (ultimately, applications of the Cauchy–Schwarz inequality) in an algebra of graphs, where each finite graph can be interpreted as a functional on the space of graphons. This viewpoint also enables the automation of Cauchy–Schwarz-style arguments via semidefinite programming (SDP), and has been implemented in the FLAGMATIC package [14 ] . Flag algebras and Flagmatic have resolved many open problems in extremal combinatorics over the past decade (for a survey, see Razborov [ [41 ] ), but their computational cost can be prohibitive.2 This limits applicability to some instances we consider, such as problems involving the Petersen graph. We view our method as complementary to flag algebras rather than a replacement: flag algebras provide rigorous lower bounds together with certificates, whereas our method searches directly for candidate graphons and yields candidate upper bounds and concrete candidate minimisers. When an upper bound from our method nearly matches a rigorous lower bound, this gives strong evidence for the correct optimum and produces a graphon whose structure can be inspected and turned into mathematical conjectures (as in our exhaustive sweep in § 4 ).
For fixed values of n n n (i.e., without taking the limit in Eq. (4) or related formulations), one may instead attempt to solve the discrete optimisation problem directly. A classical approach is local (e.g., Tabu) search, which remains useful in combination with reinforcement learning; see, e.g., [34 , 29 ] . As a direct reinforcement-learning approach, Mehrabian et al. [ [29 ] used AlphaZero to search for n n n -vertex graphs with as many edges as possible and no copies of K 3 K_{3} K 3 and C 4 C_{4} C 4 . The so-called deep cross entropy method was used by Wagner [ [48 ] for analysing discrete problems in combinatorics. It iteratively trains a neural network to learn a policy that promotes the generation of high-quality examples, which succeeded in disproving conjectures regarding the largest eigenvalue of the adjacency matrix and the matching number. Finally, PatternBoost [7 ] takes a hybrid approach that combines local search with a learned generative model; one illustrative example is generating lower-bound examples related to Mantel’s theorem by solving finite-n n n instances of Eq. (4) for H = K 3 H = K_{3} H = K 3 (for small n n n ) up to edge density p ≤ 1 / 2 p \le1/2 p ≤ 1/2 . For discrete objectives, these approaches can be more versatile than our method because they can optimise non-differentiable quantities (e.g., the matching number). In contrast, they operate at a fixed graph size, whereas our method targets asymptotic problems in the dense-graph limit. Because many combinatorial objects are highly symmetric, solutions produced by such discrete approaches can be difficult to interpret or distil into human-understandable structure. In contrast, as demonstrated by visualisations of learnt graphons, our method often captures structure that is amenable to inspection and interpretation.
From the perspective of implicit neural representations, the work most closely related to ours is Mundinger et al. [ [31 ] , which applies implicit neural representations to the Hadwiger–Nelson problem: colouring the plane R 2 \mathbb{R}^{2} R 2 with the minimum number of colours such that no two points at unit distance share a colour. Analogously to our approach, they represent a colouring by a neural network and recover a 6-colouring by minimising a monochromatic edge-density objective. With human post-processing, they construct two new 6-colourings that expand the known range of realisable distances from [0.415, 0.447] to [0.354, 0.657]. In contrast, we focus on asymptotic extremal problems in graph theory that can be phrased as constrained optimisation over graphons. Moreover, our approach integrates problem structure into the learning procedure, including an architectural bias toward discontinuous, step-like solutions, explicit constraint enforcement via an embedded solver, and variance reduction in homomorphism density estimation, with the aim of supporting systematic conjecture generation and exploration across diverse extremal problems in graph theory.
Societal impacts and limitations
Our work presents a method for finding structured candidate optima of graphon variational problems, which is of interest to mathematicians working on extremal graph theory and the large deviation theory of dense random graphs. Compared with existing baselines, our method produces candidate optima that are markedly more interpretable, offering insight into the structure of optimal graphons and thereby supporting mathematical conjecture generation and discovery. We do not foresee any major negative societal impacts arising from this work.
Our method has several limitations. First, it is tailored to graphon optimisation and therefore does not apply to combinatorial problems on sparse graphs, for which the graphon limit is degenerate. Second, although the candidate optima it produces are highly interpretable, the method itself does not provide rigorous guarantees of optimality; it should therefore be used in conjunction with rigorous lower-bound techniques such as flag algebras [39 , 14 ] to verify optimality and provide certificates. Third, evaluating our method requires estimating homomorphism densities, for which we use either discretisation-based computation or Monte Carlo estimation; both can be computationally expensive for large motifs. Discretisation-based computation of t ( H , W ) t(H, W) t ( H , W ) on an M × M M \times M M × M grid becomes infeasible for motifs with many vertices, such as the Petersen graph; Monte Carlo estimation can suffer from large relative error when the motif density is very small.
Background on graphons, odd cycles, and large deviations
In this section, we give an informal introduction to the graphon formulation of § 2 and state the conjectured optima for odd cycles used in § 4 .
Graphons as limits of graphs. Extremal graph theory and the large deviation theory of random graphs ask questions about very large graphs, such as how few triangles a graph with a given edge density can have. Graphons replace a sequence of growing graphs by a single function on the unit square, and our method optimises over these functions.
A graph G G G with vertex set [ n ] [n] [ n ] can be drawn as an image on the unit square through its adjacency matrix:
W G ( x , y ) : = { 1 if x ∈ ( i − 1 n , i n ] , y ∈ ( j − 1 n , j n ] , and { i , j } ∈ E ( G ) , 0 otherwise. W_G(x,y) := \begin{cases} 1 & \text{if } x \in\left(\frac{i-1}{n}, \frac{i}{n}\right],\ y \in\left(\frac{j-1}{n}, \frac{j}{n}\right],\ \text{and } \{i,j\} \in E(G), \\ 0 & \text{otherwise.} \end{cases} W G ( x , y ) := { 1 0 if x ∈ ( n i − 1 , n i ] , y ∈ ( n j − 1 , n j ] , and { i , j } ∈ E ( G ) , otherwise.
Note that isomorphic graphs give images that differ only by a relabelling, i.e., a permutation of rows and columns. The heatmaps in our figures show graphs in the same way.
Consider the limit of such images when the number of vertices grows. For the complete graph K n K_n K n , the image takes the value 1 except on the n n n diagonal squares, whose total area is 1 / n 1/n 1/ n , so it converges to the constant function 1 as n → ∞ n \to\infty n → ∞ . For the Erdős–Rényi random graph G ( n , q ) G(n,q) G ( n , q ) , the image is noise with entries 0 and 1, which never approaches the constant function q q q pointwise. Nevertheless, the constant graphon W ≡ q W \equiv q W ≡ q is the natural limit of G ( n , q ) G(n,q) G ( n , q ) . This limit is characterised by the so-called cut distance. For a symmetric measurable function W : [ 0 , 1 ] 2 → [ 0 , 1 ] W : [0,1]^2 \to[0,1] W : [ 0 , 1 ] 2 → [ 0 , 1 ] , we consider a measure-preserving bijection σ : [ 0 , 1 ] → [ 0 , 1 ] \sigma: [0,1] \to[0,1] σ : [ 0 , 1 ] → [ 0 , 1 ] , which is a continuous counterpart of a relabelling of vertices, and write W σ ( x , y ) : = W ( σ ( x ) , σ ( y ) ) W^\sigma(x,y) := W(\sigma(x),\sigma(y)) W σ ( x , y ) := W ( σ ( x ) , σ ( y )) . Then the cut distance is the infimum of the difference between two graphons at a cut S × T S \times T S × T over such transformed graphons:
δ □ ( U , W ) : = inf σ sup S , T ⊆ [ 0 , 1 ] ∣ ∫ S × T ( U ( x , y ) − W σ ( x , y ) ) d x d y ∣ . \delta_\square(U,W) := \inf_\sigma\sup_{S,T \subseteq[0,1]} \left| \int_{S \times T} (U(x,y)-W^\sigma(x,y))\,\mathrm{d}x\,\mathrm{d}y \right|. δ □ ( U , W ) := σ inf S , T ⊆ [ 0 , 1 ] sup ∫ S × T ( U ( x , y ) − W σ ( x , y )) d x d y .
A sequence of graphs ( G n ) (G_n) ( G n ) converges to a graphon W W W if δ □ ( W G n , W ) → 0 \delta_\square(W_{G_n},W) \to0 δ □ ( W G n , W ) → 0 . The space of graphons, considered up to measure-preserving transformations (more precisely, with graphons at cut distance zero identified), is compact in the cut distance, and the images W G W_G W G of graphs are dense in it [24 ] . In particular, every sequence of graphs has a subsequence that converges to a graphon.
Homomorphism densities are compatible with this limit. For every graph H H H and graphons U U U and W W W , we have
∣ t ( H , U ) − t ( H , W ) ∣ ≤ e ( H ) δ □ ( U , W ) , |t(H,U)-t(H,W)| \le e(H)\delta_\square(U,W), ∣ t ( H , U ) − t ( H , W ) ∣ ≤ e ( H ) δ □ ( U , W ) ,
so the H H H -density of a large graph is close to that of any graphon near it in the cut distance. Conversely, for a sequence of graphs ( G n ) (G_n) ( G n ) , if t ( H , W G n ) → t ( H , W ) t(H,W_{G_n}) \to t(H,W) t ( H , W G n ) → t ( H , W ) for every graph H H H , then W G n → W W_{G_n} \to W W G n → W in the cut distance [24 ] . By the continuity of homomorphism densities and the compactness of the space of graphons, an optimisation problem over large graphs whose objective and constraints are continuous in the cut distance, such as homomorphism densities, becomes an optimisation problem over graphons: the asymptotic optimum over graph sequences equals the optimum over graphons, and the latter is attained. For example, the asymptotic minimum in (4) equals the minimum in (P1). The optimum is also attained for objectives that are only lower semicontinuous in the cut distance, such as the relative entropy h q h_q h q in (P2) [8 ] .
Conjectured optima for odd cycles. In Bennett et al. [ [4 ] , the conjectured optimal graphon is constructed as follows. Let k k k be the integer satisfying 1 − 1 k < p < 1 − 1 k + 1 1-\frac{1}{k} < p < 1-\frac{1}{k+1} 1 − k 1 < p < 1 − k + 1 1 . First, we partition the interval [ 0 , 1 ] [0,1] [ 0 , 1 ] into ( k + 1 ) (k+1) ( k + 1 ) sets, X 1 , … , X k − 1 , Y 1 , Y 2 X_1,\ldots,X_{k-1},Y_1,Y_2 X 1 , … , X k − 1 , Y 1 , Y 2 . We set the lengths of X 1 , … , X k − 1 X_1,\ldots,X_{k-1} X 1 , … , X k − 1 to be x x x , and the lengths of Y 1 Y_1 Y 1 and Y 2 Y_2 Y 2 to be y 2 \frac{y}{2} 2 y , where y = 1 − ( k − 1 ) x y=1-(k-1)x y = 1 − ( k − 1 ) x . We then define the graphon by
W ( x 1 , x 2 ) = { 1 if x 1 ∈ X m , x 2 ∈ X n , m ≠ n , 1 if x 1 ∈ X m , x 2 ∈ Y n , or vice versa , 0 if x 1 ∈ X m , x 2 ∈ X m , ρ if x 1 ∈ Y 1 , x 2 ∈ Y 2 , or vice versa , 0 if x 1 ∈ Y m , x 2 ∈ Y m . W(x_1,x_2)=
\begin{cases}
1 & \text{if } x_1 \in X_m,\ x_2 \in X_n,\ m \ne n,\\
1 & \text{if } x_1 \in X_m,\ x_2 \in Y_n,\ \text{or vice versa},\\
0 & \text{if } x_1 \in X_m,\ x_2 \in X_m,\\
\rho& \text{if } x_1 \in Y_1,\ x_2 \in Y_2,\ \text{or vice versa},\\
0 & \text{if } x_1 \in Y_m,\ x_2 \in Y_m.
\end{cases} W ( x 1 , x 2 ) = ⎩ ⎨ ⎧ 1 1 0 ρ 0 if x 1 ∈ X m , x 2 ∈ X n , m = n , if x 1 ∈ X m , x 2 ∈ Y n , or vice versa , if x 1 ∈ X m , x 2 ∈ X m , if x 1 ∈ Y 1 , x 2 ∈ Y 2 , or vice versa , if x 1 ∈ Y m , x 2 ∈ Y m .
where ρ \rho ρ is chosen to satisfy the edge-density constraint. One can compute the C 5 C_5 C 5 density of this graphon, which can be written as a polynomial f 5 ( x , y , ρ ) f_5(x,y,\rho) f 5 ( x , y , ρ ) given by
f 5 ( x , y , ρ ) = ( ( k − 1 ) 5 10 + ( k − 1 ) 4 2 + ( k − 1 ) 3 2 ) x 5 + ( ( k − 1 ) 4 2 + 3 ( k − 1 ) 3 2 + ( k − 1 ) 2 2 ) x 4 y + ( ( 1 2 + ρ 2 ) ( k − 1 ) 3 + ( 1 + ρ 2 ) ( k − 1 ) 2 ) x 3 y 2 + ( ( ρ 2 + ρ 2 2 ) ( k − 1 ) 2 + ρ 2 ( k − 1 ) ) x 2 y 3 + ρ 3 2 ( k − 1 ) x y 4 , \begin{aligned}
f_5(x,y,\rho)
={}&\left(\frac{(k-1)_5}{10}+\frac{(k-1)_4}{2}+\frac{(k-1)_3}{2}\right)x^5\\
&+\left(\frac{(k-1)_4}{2}+\frac{3(k-1)_3}{2}+\frac{(k-1)_2}{2}\right)x^4y\\
&+\left(\left(\frac{1}{2}+\frac{\rho}{2}\right)(k-1)_3+\left(1+\frac{\rho}{2}\right)(k-1)_2\right)x^3y^2\\
&+\left(\left(\frac{\rho}{2}+\frac{\rho^2}{2}\right)(k-1)_2+\frac{\rho}{2}(k-1)\right)x^2y^3\\
&+\frac{\rho^3}{2}(k-1)xy^4,
\end{aligned} f 5 ( x , y , ρ ) = ( 10 ( k − 1 ) 5 + 2 ( k − 1 ) 4 + 2 ( k − 1 ) 3 ) x 5 + ( 2 ( k − 1 ) 4 + 2 3 ( k − 1 ) 3 + 2 ( k − 1 ) 2 ) x 4 y + ( ( 2 1 + 2 ρ ) ( k − 1 ) 3 + ( 1 + 2 ρ ) ( k − 1 ) 2 ) x 3 y 2 + ( ( 2 ρ + 2 ρ 2 ) ( k − 1 ) 2 + 2 ρ ( k − 1 ) ) x 2 y 3 + 2 ρ 3 ( k − 1 ) x y 4 ,
where ( k − 1 ) r (k-1)_r ( k − 1 ) r is a falling factorial, ( k − 1 ) r = ( k − 1 ) ⋅ ( k − 2 ) ⋯ ( k − r ) (k-1)_r=(k-1)\cdot(k-2)\cdots(k-r) ( k − 1 ) r = ( k − 1 ) ⋅ ( k − 2 ) ⋯ ( k − r ) . With these definitions, the conjectured optimal value is obtained by optimising over x x x and ρ \rho ρ subject to the constraints below (with y y y determined by x x x via ( k − 1 ) x + y = 1 (k-1)x+y=1 ( k − 1 ) x + y = 1 ). The contribution of the Y 1 Y_1 Y 1 –Y 2 Y_2 Y 2 rectangles to the ordered edge density is ρ y 2 / 2 \rho y^2/2 ρ y 2 /2 , since the two off-diagonal rectangles have total area y 2 / 2 y^2/2 y 2 /2 . Equivalently, one can compute the conjectured optimum by solving
min f 5 ( x , y , ρ ) subject to ( k − 1 ) x + y = 1 , ( k − 1 ) 2 x 2 + 2 ( k − 1 ) x y + ρ y 2 2 = p , x , y ≥ 0 , 0 ≤ ρ ≤ 1. \begin{aligned}
\min\ &f_5(x,y,\rho)\\
\text{subject to } &(k-1)x+y=1,\\
&(k-1)_2x^2+2(k-1)xy+\frac{\rho y^2}{2}=p,\\
&x,y\ge0,\qquad0\le\rho\le1.
\end{aligned} min subject to f 5 ( x , y , ρ ) ( k − 1 ) x + y = 1 , ( k − 1 ) 2 x 2 + 2 ( k − 1 ) x y + 2 ρ y 2 = p , x , y ≥ 0 , 0 ≤ ρ ≤ 1.
Using the same structure, we can generalise the conjecture to arbitrary odd cycles C 2 ℓ + 1 C_{2\ell+1} C 2 ℓ + 1 by replacing f 5 f_5 f 5 with the corresponding f 2 ℓ + 1 f_{2\ell+1} f 2 ℓ + 1 . For instance, f 7 f_7 f 7 is given as follows.
f 7 ( x , y , ρ ) = ( ( k − 1 ) 7 14 + ( k − 1 ) 6 + 4 ( k − 1 ) 5 + 5 ( k − 1 ) 4 + 3 ( k − 1 ) 3 2 ) x 7 + ( ( k − 1 ) 6 2 + 5 ( k − 1 ) 5 + 25 ( k − 1 ) 4 2 + 15 ( k − 1 ) 3 2 + ( k − 1 ) 2 2 ) x 6 y + ( ( k − 1 ) 5 + ( 3 ρ + 7 ) ( k − 1 ) 4 + ( 7 ρ 2 + 10 ) ( k − 1 ) 3 + ( ρ 2 + 2 ) ( k − 1 ) 2 ) x 5 y 2 + ( ( 3 ρ 2 + 1 2 ) ( k − 1 ) 4 + ( 3 ρ 2 2 + 6 ρ + 5 2 ) ( k − 1 ) 3 + ( ρ 2 2 + 3 ρ + 2 ) ( k − 1 ) 2 ) x 4 y 3 + ( ( ρ 3 2 + 3 ρ 2 2 + ρ 2 ) ( k − 1 ) 3 + ( ρ 3 2 + 3 ρ 2 + 3 ρ 2 ) ( k − 1 ) 2 + ρ 2 ( k − 1 ) ) x 3 y 4 + ( ( ρ 4 2 + ρ 3 ) ( k − 1 ) 2 + ρ 3 ( k − 1 ) ) x 2 y 5 + ρ 5 2 ( k − 1 ) x y 6 . \begin{aligned}
f_7(x,y,\rho)
={}&\left(\frac{(k-1)_7}{14}+(k-1)_6+4(k-1)_5+5(k-1)_4+\frac{3(k-1)_3}{2}\right)x^7\\
&+\left(\frac{(k-1)_6}{2}+5(k-1)_5+\frac{25(k-1)_4}{2}+\frac{15(k-1)_3}{2}+\frac{(k-1)_2}{2}\right)x^6y\\
&+\left((k-1)_5+(3\rho+7)(k-1)_4+\left(\frac{7\rho}{2}+10\right)(k-1)_3+\left(\frac{\rho}{2}+2\right)(k-1)_2\right)x^5y^2\\
&+\left(\left(\frac{3\rho}{2}+\frac{1}{2}\right)(k-1)_4+\left(\frac{3\rho^2}{2}+6\rho+\frac{5}{2}\right)(k-1)_3+\left(\frac{\rho^2}{2}+3\rho+2\right)(k-1)_2\right)x^4y^3\\
&+\left(\left(\frac{\rho^3}{2}+\frac{3\rho^2}{2}+\frac{\rho}{2}\right)(k-1)_3+\left(\frac{\rho^3}{2}+3\rho^2+\frac{3\rho}{2}\right)(k-1)_2+\frac{\rho}{2}(k-1)\right)x^3y^4\\
&+\left(\left(\frac{\rho^4}{2}+\rho^3\right)(k-1)_2+\rho^3(k-1)\right)x^2y^5\\
&+\frac{\rho^5}{2}(k-1)xy^6.
\end{aligned} f 7 ( x , y , ρ ) = ( 14 ( k − 1 ) 7 + ( k − 1 ) 6 + 4 ( k − 1 ) 5 + 5 ( k − 1 ) 4 + 2 3 ( k − 1 ) 3 ) x 7 + ( 2 ( k − 1 ) 6 + 5 ( k − 1 ) 5 + 2 25 ( k − 1 ) 4 + 2 15 ( k − 1 ) 3 + 2 ( k − 1 ) 2 ) x 6 y + ( ( k − 1 ) 5 + ( 3 ρ + 7 ) ( k − 1 ) 4 + ( 2 7 ρ + 10 ) ( k − 1 ) 3 + ( 2 ρ + 2 ) ( k − 1 ) 2 ) x 5 y 2 + ( ( 2 3 ρ + 2 1 ) ( k − 1 ) 4 + ( 2 3 ρ 2 + 6 ρ + 2 5 ) ( k − 1 ) 3 + ( 2 ρ 2 + 3 ρ + 2 ) ( k − 1 ) 2 ) x 4 y 3 + ( ( 2 ρ 3 + 2 3 ρ 2 + 2 ρ ) ( k − 1 ) 3 + ( 2 ρ 3 + 3 ρ 2 + 2 3 ρ ) ( k − 1 ) 2 + 2 ρ ( k − 1 ) ) x 3 y 4 + ( ( 2 ρ 4 + ρ 3 ) ( k − 1 ) 2 + ρ 3 ( k − 1 ) ) x 2 y 5 + 2 ρ 5 ( k − 1 ) x y 6 .
Large deviations and the relative entropy. For a , q ∈ ( 0 , 1 ) a,q\in(0,1) a , q ∈ ( 0 , 1 ) , write
KL ( a ∥ q ) : = KL ( Bern ( a ) ∥ Bern ( q ) ) = a log a q + ( 1 − a ) log 1 − a 1 − q . \operatorname{KL}(a\mathbin\Vert q):=\operatorname{KL}(\operatorname{Bern}(a)\mathbin\Vert\operatorname{Bern}(q))=a\log\frac{a}{q}+(1-a)\log\frac{1-a}{1-q}. KL ( a ∥ q ) := KL ( Bern ( a ) ∥ Bern ( q )) = a log q a + ( 1 − a ) log 1 − q 1 − a .
In G ( n , q ) G(n,q) G ( n , q ) , for each of the N = ( n 2 ) N = \binom{n}{2} N = ( 2 n ) vertex pairs, the two vertices are adjacent independently with probability q q q . If a N aN a N is an integer, Stirling’s formula gives log ( N a N ) = − N ( a log a + ( 1 − a ) log ( 1 − a ) ) + o ( N ) \log\binom{N}{aN} = -N\bigl(a\log a + (1-a)\log(1-a)\bigr) + o(N) log ( a N N ) = − N ( a log a + ( 1 − a ) log ( 1 − a ) ) + o ( N ) . Hence,
log Pr G ∼ G ( n , q ) [ e ( G ) = a N ] = log ( ( N a N ) q a N ( 1 − q ) ( 1 − a ) N ) = − N ( a log a q + ( 1 − a ) log 1 − a 1 − q ) + o ( N ) = − N KL ( a ∥ q ) + o ( N ) . \begin{aligned}
\log\Pr_{G\sim G(n,q)}[e(G)=aN]
&= \log\left(\binom{N}{aN}q^{aN}(1-q)^{(1-a)N}\right) \\
&= -N\left(a\log\frac{a}{q}+(1-a)\log\frac{1-a}{1-q}\right)+o(N) \\
&= -N\operatorname{KL}(a\mathbin\Vert q)+o(N).
\end{aligned} log G ∼ G ( n , q ) Pr [ e ( G ) = a N ] = log ( ( a N N ) q a N ( 1 − q ) ( 1 − a ) N ) = − N ( a log q a + ( 1 − a ) log 1 − q 1 − a ) + o ( N ) = − N KL ( a ∥ q ) + o ( N ) .
Thus the probability that G ( n , q ) G(n,q) G ( n , q ) has edge density a a a rather than the typical value q q q decays exponentially in N N N , at rate KL ( a ∥ q ) \operatorname{KL}(a\mathbin\Vert q) KL ( a ∥ q ) . The large deviation principle of Chatterjee and Varadhan [ [8 ] extends this from a single edge density to the whole profile of edge probabilities: informally, the probability that G ( n , q ) G(n,q) G ( n , q ) is close in cut distance to a graphon W W W is exp ( − N h q ( W ) + o ( n 2 ) ) \exp(-Nh_q(W)+o(n^2)) exp ( − N h q ( W ) + o ( n 2 )) , where h q ( W ) = ∫ [ 0 , 1 ] 2 KL ( W ( x , y ) ∥ q ) d x d y h_q(W)=\int_{[0,1]^2}\operatorname{KL}(W(x,y)\mathbin\Vert q)\,dx\,dy h q ( W ) = ∫ [ 0 , 1 ] 2 KL ( W ( x , y ) ∥ q ) d x d y as in § 2 . The probability of an event such as t ( H , G ( n , q ) ) ≥ r e ( H ) t(H,G(n,q))\ge r^{e(H)} t ( H , G ( n , q )) ≥ r e ( H ) is dominated by the graphons that satisfy this constraint with the smallest relative entropy, which gives the variational formulas in § 2 , and conditioned on the event, G ( n , q ) G(n,q) G ( n , q ) is close to these minimisers [[27 ] ].
Optimal solutions of large deviation problems. Consider the upper-tail problem in (P2) , where q < r q<r q < r :
min W h q ( W ) s.t. t ( H , W ) = r e ( H ) . \min_W h_q(W) \quad\text{s.t.}\quad t(H,W)=r^{e(H)}. W min h q ( W ) s.t. t ( H , W ) = r e ( H ) .
The constant graphon W ≡ r W\equiv r W ≡ r satisfies the constraint t ( H , W ) = r e ( H ) t(H,W)=r^{e(H)} t ( H , W ) = r e ( H ) , so it is a feasible solution, with objective value h q ( W ) = KL ( r ∥ q ) h_q(W)=\operatorname{KL}(r\mathbin\Vert q) h q ( W ) = KL ( r ∥ q ) . For a d d d -regular graph H H H with d ≥ 2 d\ge2 d ≥ 2 , Lubetzky and Zhao [ [27 ] characterised when this constant graphon is optimal: there is a curve q c ( r ) q_c(r) q c ( r ) such that W ≡ r W\equiv r W ≡ r is the unique optimum of (P2) if q > q c ( r ) q>q_c(r) q > q c ( r ) , and some graphon has a smaller objective value than W ≡ r W\equiv r W ≡ r if q < q c ( r ) q<q_c(r) q < q c ( r ) . The region where the constant graphon W ≡ r W\equiv r W ≡ r is optimal is called the replica-symmetric phase , and the region where it is not optimal is called the symmetry-breaking phase .
Proven results on the learnt structures
The graphons found by our method motivated the following three theorems. We state them in the notation of this paper and explain how each relates to our experiments. Recall the balanced complete k k k -partite graphon W k W_k W k from § 4 .
Theorem D.1 (Im et al., [20 ] ). Let m ≥ 3 m\ge3 m ≥ 3 be odd, and let W W W be a graphon with t ( K 2 , W ) = p ≥ 2 / 3 t(K_2,W)=p\ge2/3 t ( K 2 , W ) = p ≥ 2/3 . Then
t ( C m , W ) ≥ p m − p ( 1 − p ) m − 1 . t(C_m,W)\ge p^m-p(1-p)^{m-1}. t ( C m , W ) ≥ p m − p ( 1 − p ) m − 1 . In particular, when p = 1 − 1 / k p=1-1/k p = 1 − 1/ k for some integer k ≥ 3 k\ge3 k ≥ 3 , the balanced complete k k k -partite graphon W k W_k W k minimises the density of every odd cycle.
The second statement holds because t ( C m , W k ) = p m − p ( 1 − p ) m − 1 t(C_m,W_k)=p^m-p(1-p)^{m-1} t ( C m , W k ) = p m − p ( 1 − p ) m − 1 at p = 1 − 1 / k p=1-1/k p = 1 − 1/ k . Hence the learnt C 7 C_7 C 7 graphons at p ∈ { 2 / 3 , 4 / 5 } p\in\{2/3,4/5\} p ∈ { 2/3 , 4/5 } (top row of Figure 4 ), which recover the complete k k k -partite structure, are optimal.
A graph is chordal if no cycle of length greater than 3 appears as an induced subgraph of it.
Theorem D.2. *Let H H H be a connected chordal graph whose maximal cliques all have the same size $r\ge 3. Then, for every integer k ≥ r k\ge r k ≥ r , the graphon W k W_k W k minimises t ( H , W ) t(H,W) t ( H , W ) subject to t ( K 2 , W ) = 1 − 1 / k t(K_2,W)=1-1/k t ( K 2 , W ) = 1 − 1/ k .
A proof of Theorem D.2 , formalised in Lean 4, is available at https://github.com/mekty2012/PureChordalGoodman . Theorem D.2 applies to 16 graphs of our exhaustive study in § 4 other than cliques, and settles 48 of its instances.
A graphon W W W is bipodal if there is a measurable set A ⊆ [ 0 , 1 ] A \subseteq[0,1] A ⊆ [ 0 , 1 ] such that, with B = [ 0 , 1 ] ∖ A B = [0,1] \setminus A B = [ 0 , 1 ] ∖ A , the graphon W W W is almost everywhere constant on each of A × A A \times A A × A , ( A × B ) ∪ ( B × A ) (A \times B) \cup(B \times A) ( A × B ) ∪ ( B × A ) , and B × B B \times B B × B . Recall the curve q c ( r ) q_c(r) q c ( r ) of Lubetzky and Zhao [ [27 ] from §C.
Theorem D.3 (Lim et al. [22 ] ). Let H H H be a d d d -regular graph with d ≥ 2 d \ge2 d ≥ 2 , and let r 0 ∈ ( 0 , 1 ) ∖ { ( d − 1 ) / d } r_0 \in(0,1) \setminus\{(d-1)/d\} r 0 ∈ ( 0 , 1 ) ∖ {( d − 1 ) / d } . There is an open neighbourhood U U U of ( q c ( r 0 ) , r 0 ) (q_c(r_0), r_0) ( q c ( r 0 ) , r 0 ) such that, for every ( q , r ) ∈ U (q,r) \in U ( q , r ) ∈ U with q < q c ( r ) q < q_c(r) q < q c ( r ) , the minimiser of h q ( W ) h_q(W) h q ( W ) subject to t ( H , W ) ≥ r e ( H ) t(H,W) \ge r^{e(H)} t ( H , W ) ≥ r e ( H ) is unique up to relabelling, nonconstant, and bipodal.
This partially resolves the conjecture that the upper-tail large deviation problem for regular graphs has bipodal graphons as optimal solutions. The learnt upper-tail graphons for the 2-regular graphs K 3 K_3 K 3 , C 4 C_4 C 4 , and C 5 C_5 C 5 have this two-block form (Figure 6 and §G).
Properties of the density estimator and the implicit gradient
Lemma E.1. The estimator in Eq. (8) is unbiased, i.e., E [ t ^ ( H , f θ [ c ] ) ] = t ( H , f θ [ c ] ) \mathbb{E}[\widehat{t}(H,f_\theta[c])] = t(H,f_\theta[c]) E [ t ( H , f θ [ c ])] = t ( H , f θ [ c ]) .
Proof. We compute the claimed equality as follows:
E [ t ^ ( H , f θ [ c ] ) ] = E [ 1 N ∣ S ∣ ∑ k ∈ [ N ] , π ∈ S ( ∏ { i , j } ∈ E ( H ) f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) ) ] = 1 N ∣ S ∣ ∑ k ∈ [ N ] , π ∈ S E [ ∏ { i , j } ∈ E ( H ) f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) ] = 1 N ∣ S ∣ ∑ k ∈ [ N ] , π ∈ S E x 1 , … , x v ( H ) ∼ i i d Unif [ 0 , 1 ] [ ∏ { i , j } ∈ E ( H ) f θ [ c ] ( x i , x j ) ] = 1 N ∣ S ∣ ∑ k ∈ [ N ] , π ∈ S t ( H , f θ [ c ] ) = t ( H , f θ [ c ] ) . \begin{aligned}
\mathbb{E}\left[\widehat{t}(H,f_\theta[c])\right]
&= \mathbb{E}\left[\frac{1}{N|S|}\sum_{k\in[N],\pi\in S}\left(\prod_{\{i,j\}\in E(H)}f_\theta[c]\left(x_{\pi(i)}^{(k)},x_{\pi(j)}^{(k)}\right)\right)\right]\\
&= \frac{1}{N|S|}\sum_{k\in[N],\pi\in S}\mathbb{E}\left[\prod_{\{i,j\}\in E(H)}f_\theta[c]\left(x_{\pi(i)}^{(k)},x_{\pi(j)}^{(k)}\right)\right]\\
&= \frac{1}{N|S|}\sum_{k\in[N],\pi\in S}\mathbb{E}_{x_1,\ldots,x_{v(H)}\mathrel{\overset{\mathrm{iid}}{\sim}\operatorname{Unif}[0,1]}}\left[\prod_{\{i,j\}\in E(H)}f_\theta[c](x_i,x_j)\right]\\
&= \frac{1}{N|S|}\sum_{k\in[N],\pi\in S}t(H,f_\theta[c])=t(H,f_\theta[c]).
\end{aligned} E [ t ( H , f θ [ c ]) ] = E N ∣ S ∣ 1 k ∈ [ N ] , π ∈ S ∑ { i , j } ∈ E ( H ) ∏ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) = N ∣ S ∣ 1 k ∈ [ N ] , π ∈ S ∑ E { i , j } ∈ E ( H ) ∏ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) = N ∣ S ∣ 1 k ∈ [ N ] , π ∈ S ∑ E x 1 , … , x v ( H ) ∼ iid Unif [ 0 , 1 ] { i , j } ∈ E ( H ) ∏ f θ [ c ] ( x i , x j ) = N ∣ S ∣ 1 k ∈ [ N ] , π ∈ S ∑ t ( H , f θ [ c ]) = t ( H , f θ [ c ]) .
Lemma E.2 (Restatement of Lemma 3.1 ). For all x ∈ [ 0 , 1 ] 2 \mathbf{x} \in[0,1]^2 x ∈ [ 0 , 1 ] 2 ,
∇ θ f θ [ c θ ] ( x ) = ∂ f θ [ c ] ( x ) ∂ θ ∣ c = c θ − s m ′ ( h θ ( x ) + c θ ) ∑ y ∈ E w θ ( y ) ∇ θ h θ ( y ) , \nabla_\theta f_\theta[c_\theta](\mathbf{x})=\left.\frac{\partial f_\theta[c](\mathbf{x})}{\partial\theta}\right|_{c=c_\theta}-sm'(h_\theta(\mathbf{x})+c_\theta)\sum_{\mathbf{y}\in\mathcal{E}}w_\theta(\mathbf{y})\nabla_\theta h_\theta(\mathbf{y}), ∇ θ f θ [ c θ ] ( x ) = ∂ θ ∂ f θ [ c ] ( x ) c = c θ − s m ′ ( h θ ( x ) + c θ ) y ∈ E ∑ w θ ( y ) ∇ θ h θ ( y ) , where
w θ ( y ) : = s m ′ ( h θ ( y ) + c θ ) ∑ z ∈ E s m ′ ( h θ ( z ) + c θ ) . w_\theta(\mathbf{y}):=\frac{sm'(h_\theta(\mathbf{y})+c_\theta)}{\sum_{\mathbf{z}\in\mathcal{E}}sm'(h_\theta(\mathbf{z})+c_\theta)}. w θ ( y ) := ∑ z ∈ E s m ′ ( h θ ( z ) + c θ ) s m ′ ( h θ ( y ) + c θ ) .
Proof. Let x ∈ [ 0 , 1 ] 2 \mathbf{x}\in[0,1]^2 x ∈ [ 0 , 1 ] 2 . Note that
∇ θ f θ [ c θ ] ( x ) = ∂ f θ [ c ] ( x ) ∂ θ ∣ c = c θ + ∂ f θ [ c ] ( x ) ∂ c ∣ c = c θ ∇ θ c θ = ∂ f θ [ c ] ( x ) ∂ θ ∣ c = c θ + s m ′ ( h θ ( x ) + c θ ) ∇ θ c θ . \begin{aligned}
\nabla_\theta f_\theta[c_\theta](\mathbf{x})=\left.\frac{\partial f_\theta[c](\mathbf{x})}{\partial\theta}\right|_{c=c_\theta}+\left.\frac{\partial f_\theta[c](\mathbf{x})}{\partial c}\right|_{c=c_\theta}\nabla_\theta c_\theta\\
&=\left.\frac{\partial f_\theta[c](\mathbf{x})}{\partial\theta}\right|_{c=c_\theta}+sm'(h_\theta(\mathbf{x})+c_\theta)\nabla_\theta c_\theta.
\end{aligned} ∇ θ f θ [ c θ ] ( x ) = ∂ θ ∂ f θ [ c ] ( x ) c = c θ + ∂ c ∂ f θ [ c ] ( x ) c = c θ ∇ θ c θ = ∂ θ ∂ f θ [ c ] ( x ) c = c θ + s m ′ ( h θ ( x ) + c θ ) ∇ θ c θ .
Thus, it suffices to show that
∇ θ c θ = − ∑ y ∈ E s m ′ ( h θ ( y ) + c θ ) ∑ z ∈ E s m ′ ( h θ ( z ) + c θ ) ∇ θ h θ ( y ) . \nabla_\theta c_\theta=-\sum_{\mathbf{y}\in\mathcal{E}}\frac{sm'(h_\theta(\mathbf{y})+c_\theta)}{\sum_{\mathbf{z}\in\mathcal{E}}sm'(h_\theta(\mathbf{z})+c_\theta)}\nabla_\theta h_\theta(\mathbf{y}). ∇ θ c θ = − y ∈ E ∑ ∑ z ∈ E s m ′ ( h θ ( z ) + c θ ) s m ′ ( h θ ( y ) + c θ ) ∇ θ h θ ( y ) .
We prove the above equality by applying implicit differentiation to the following equation about c θ c_\theta c θ , which holds by the choice of c θ c_\theta c θ :
1 ∣ E ∣ ∑ y ∈ E f θ [ c θ ] ( y ) = p . \frac{1}{|\mathcal{E}|}\sum_{y\in\mathcal{E}} f_\theta[c_\theta](y)=p. ∣ E ∣ 1 y ∈ E ∑ f θ [ c θ ] ( y ) = p .
First, we multiply both sides of the equation by ∣ E ∣ |\mathcal{E}| ∣ E ∣ , and differentiate them with respect to θ \theta θ :
( ∑ y ∈ E ∂ f θ [ c ] ( y ) ∂ θ ∣ c = c θ ) + ( ∑ z ∈ E ∂ f θ [ c ] ( z ) ∂ c ∣ c = c θ ∇ θ c θ ) = 0 \left(\sum_{y\in\mathcal{E}}\left.\frac{\partial f_\theta[c](y)}{\partial\theta}\right|_{c=c_\theta}\right)+\left(\sum_{z\in\mathcal{E}}\left.\frac{\partial f_\theta[c](z)}{\partial c}\right|_{c=c_\theta}\nabla_\theta c_\theta\right)=0 y ∈ E ∑ ∂ θ ∂ f θ [ c ] ( y ) c = c θ + ( z ∈ E ∑ ∂ c ∂ f θ [ c ] ( z ) c = c θ ∇ θ c θ ) = 0
Thus,
∇ θ c θ = − ( ∑ y ∈ E ∂ f θ [ c ] ( y ) ∂ θ ∣ c = c θ ) / ( ∑ z ∈ E ∂ f θ [ c ] ( z ) ∂ c ∣ c = c θ ) = − ∑ y ∈ E s m ′ ( h θ ( y ) + c θ ) ∑ z ∈ E s m ′ ( h θ ( z ) + c θ ) ∇ θ h θ ( y ) , \begin{aligned}
\nabla_\theta c_\theta=-\left(\sum_{y\in\mathcal{E}}\left.\frac{\partial f_\theta[c](y)}{\partial\theta}\right|_{c=c_\theta}\right)\bigg/\left(\sum_{z\in\mathcal{E}}\left.\frac{\partial f_\theta[c](z)}{\partial c}\right|_{c=c_\theta}\right) \\
&=-\sum_{y\in\mathcal{E}}\frac{sm'(h_\theta(y)+c_\theta)}{\sum_{z\in\mathcal{E}}sm'(h_\theta(z)+c_\theta)}\nabla_\theta h_\theta(y),
\end{aligned} ∇ θ c θ = − y ∈ E ∑ ∂ θ ∂ f θ [ c ] ( y ) c = c θ / ( z ∈ E ∑ ∂ c ∂ f θ [ c ] ( z ) c = c θ ) = − y ∈ E ∑ ∑ z ∈ E s m ′ ( h θ ( z ) + c θ ) s m ′ ( h θ ( y ) + c θ ) ∇ θ h θ ( y ) ,
as desired.
The gradient in Lemma 3.1 is the exact gradient for the empirical constraint (7) . Since ∇ θ c θ \nabla_\theta c_\theta ∇ θ c θ is a ratio of two sample averages, it is in general a biased estimator of the gradient of the offset that enforces the population constraint t ( K 2 , f θ [ c ] ) = p t(K_2,f_\theta[c])=p t ( K 2 , f θ [ c ]) = p . It is, however, a consistent estimator, i.e., it converges to this gradient in the limit of infinitely many samples.
Lemma E.3 (Consistency of the implicit gradient). Assume that h θ ( y ) h_\theta(\mathbf{y}) h θ ( y ) and ∇ θ h θ ( y ) \nabla_\theta h_\theta(\mathbf{y}) ∇ θ h θ ( y ) are continuous in ( θ , y ) (\theta,\mathbf{y}) ( θ , y ) . Fix θ \theta θ and p ∈ ( 0 , 1 ) p\in(0,1) p ∈ ( 0 , 1 ) , and let c θ ∗ c_\theta^* c θ ∗ be the unique c ∈ R c\in\mathbb{R} c ∈ R with t ( K 2 , f θ [ c ] ) = p t(K_2,f_\theta[c])=p t ( K 2 , f θ [ c ]) = p . Let y 1 , y 2 , … ∼ i i d Unif ( [ 0 , 1 ] 2 ) \mathbf{y}_1,\mathbf{y}_2,\ldots\mathrel{\overset{\mathrm{iid}}{\sim}}\operatorname{Unif}([0,1]^2) y 1 , y 2 , … ∼ iid Unif ([ 0 , 1 ] 2 ) , and for K ≥ 1 K\geq1 K ≥ 1 let c θ , K : = Solve θ ( { y 1 , … , y K } , p ) c_{\theta,K}:=\operatorname{Solve}_\theta(\{\mathbf{y}_1,\ldots,\mathbf{y}_K\},p) c θ , K := Solve θ ({ y 1 , … , y K } , p ) . Then, almost surely, c θ , K → c θ ∗ c_{\theta,K}\to c_\theta^* c θ , K → c θ ∗ and
∇ θ c θ , K = − ∑ k = 1 K s m ′ ( h θ ( y k ) + c θ , K ) ∇ θ h θ ( y k ) ∑ k = 1 K s m ′ ( h θ ( y k ) + c θ , K ) \nabla_\theta c_{\theta,K}=-\frac{\sum_{k=1}^{K}sm'(h_\theta(\mathbf{y}_k)+c_{\theta,K})\nabla_\theta h_\theta(\mathbf{y}_k)}{\sum_{k=1}^{K}sm'(h_\theta(\mathbf{y}_k)+c_{\theta,K})} ∇ θ c θ , K = − ∑ k = 1 K s m ′ ( h θ ( y k ) + c θ , K ) ∑ k = 1 K s m ′ ( h θ ( y k ) + c θ , K ) ∇ θ h θ ( y k ) ⟶ ∇ θ c θ ∗ = − E [ s m ′ ( h θ ( y ) + c θ ∗ ) ∇ θ h θ ( y ) ] E [ s m ′ ( h θ ( y ) + c θ ∗ ) ] \longrightarrow\nabla_\theta c_\theta^*=-\frac{\mathbb{E}\left[sm'(h_\theta(\mathbf{y})+c_\theta^*)\nabla_\theta h_\theta(\mathbf{y})\right]}{\mathbb{E}\left[sm'(h_\theta(\mathbf{y})+c_\theta^*)\right]} ⟶ ∇ θ c θ ∗ = − E [ s m ′ ( h θ ( y ) + c θ ∗ ) ] E [ s m ′ ( h θ ( y ) + c θ ∗ ) ∇ θ h θ ( y ) ] as K → ∞ K\to\infty K → ∞ , where y ∼ Unif ( [ 0 , 1 ] 2 ) \mathbf{y}\sim\operatorname{Unif}([0,1]^2) y ∼ Unif ([ 0 , 1 ] 2 ) .
Proof. Let M : = max y ∈ [ 0 , 1 ] 2 ∣ h θ ( y ) ∣ M:=\max_{\mathbf{y}\in[0,1]^2}|h_\theta(\mathbf{y})| M := max y ∈ [ 0 , 1 ] 2 ∣ h θ ( y ) ∣ , which is finite because h θ h_\theta h θ is continuous on the compact set [ 0 , 1 ] 2 [0,1]^2 [ 0 , 1 ] 2 , and let ℓ : = s m − 1 ( p ) \ell:=sm^{-1}(p) ℓ := s m − 1 ( p ) . For c ∈ R c\in\mathbb{R} c ∈ R , define
F K ( c ) : = 1 K ∑ k = 1 K s m ( h θ ( y k ) + c ) , F ( c ) : = E [ s m ( h θ ( y ) + c ) ] = t ( K 2 , f θ [ c ] ) . F_K(c):=\frac{1}{K}\sum_{k=1}^{K}sm(h_\theta(\mathbf{y}_k)+c),\qquad F(c):=\mathbb{E}[sm(h_\theta(\mathbf{y})+c)]=t(K_2,f_\theta[c]). F K ( c ) := K 1 k = 1 ∑ K s m ( h θ ( y k ) + c ) , F ( c ) := E [ s m ( h θ ( y ) + c )] = t ( K 2 , f θ [ c ]) .
Both functions are continuous and strictly increasing in c c c . If c < ℓ − M c<\ell-M c < ℓ − M , then s m ( h θ ( y ) + c ) < s m ( ℓ ) = p sm(h_\theta(\mathbf{y})+c)<sm(\ell)=p s m ( h θ ( y ) + c ) < s m ( ℓ ) = p for every y \mathbf{y} y , and if c > ℓ + M c>\ell+M c > ℓ + M , then s m ( h θ ( y ) + c ) > p sm(h_\theta(\mathbf{y})+c)>p s m ( h θ ( y ) + c ) > p for every y \mathbf{y} y . Hence c θ , K c_{\theta,K} c θ , K and c θ ∗ c_\theta^* c θ ∗ lie in [ ℓ − M , ℓ + M ] [\ell-M,\ell+M] [ ℓ − M , ℓ + M ] .
Convergence of the offsets. Let ε > 0 \varepsilon>0 ε > 0 . Since F F F is strictly increasing, F ( c θ ∗ − ε ) < p < F ( c θ ∗ + ε ) F(c_\theta^*-\varepsilon)<p<F(c_\theta^*+\varepsilon) F ( c θ ∗ − ε ) < p < F ( c θ ∗ + ε ) . By the strong law of large numbers, F K ( c θ ∗ ± ε ) → F ( c θ ∗ ± ε ) F_K(c_\theta^*\pm\varepsilon)\to F(c_\theta^*\pm\varepsilon) F K ( c θ ∗ ± ε ) → F ( c θ ∗ ± ε ) almost surely, so almost surely F K ( c θ ∗ − ε ) < p < F K ( c θ ∗ + ε ) F_K(c_\theta^*-\varepsilon)<p<F_K(c_\theta^*+\varepsilon) F K ( c θ ∗ − ε ) < p < F K ( c θ ∗ + ε ) for all sufficiently large K K K , and then ∣ c θ , K − c θ ∗ ∣ < ε |c_{\theta,K}-c_\theta^*|<\varepsilon ∣ c θ , K − c θ ∗ ∣ < ε because F K F_K F K is increasing. Taking ε = 1 / m \varepsilon=1/m ε = 1/ m for every m ∈ N m\in\mathbb{N} m ∈ N gives c θ , K → c θ ∗ c_{\theta,K}\to c_\theta^* c θ , K → c θ ∗ almost surely.
Convergence of the gradients. The formula for ∇ θ c θ , K \nabla_\theta c_{\theta,K} ∇ θ c θ , K is the one derived in the proof of Lemma 3.1 . Let g : [ 0 , 1 ] 2 → R m g : [0,1]^2 \to\mathbb{R}^m g : [ 0 , 1 ] 2 → R m be bounded and measurable. Since ∣ s m ′ ′ ∣ ≤ 1 |sm''| \le1 ∣ s m ′′ ∣ ≤ 1 , the function s m ′ sm' s m ′ is 1-Lipschitz, so
∥ 1 K ∑ k = 1 K s m ′ ( h θ ( y k ) + c θ , K ) g ( y k ) − E [ s m ′ ( h θ ( y ) + c θ ∗ ) g ( y ) ] ∥ ≤ ∥ g ∥ ∞ ∣ c θ , K − c θ ∗ ∣ + ∥ 1 K ∑ k = 1 K s m ′ ( h θ ( y k ) + c θ ∗ ) g ( y k ) − E [ s m ′ ( h θ ( y ) + c θ ∗ ) g ( y ) ] ∥ . \begin{aligned}
\left\| \frac{1}{K}\sum_{k=1}^{K} sm'\left(h_\theta(y_k)+c_{\theta,K}\right)g(y_k)-\mathbb{E}\left[sm'\left(h_\theta(y)+c_\theta^*\right)g(y)\right]\right\| \\
&\leq\|g\|_\infty\left|c_{\theta,K}-c_\theta^*\right|+\left\|\frac{1}{K}\sum_{k=1}^{K}sm'\left(h_\theta(y_k)+c_\theta^*\right)g(y_k)-\mathbb{E}\left[sm'\left(h_\theta(y)+c_\theta^*\right)g(y)\right]\right\|.
\end{aligned} K 1 k = 1 ∑ K s m ′ ( h θ ( y k ) + c θ , K ) g ( y k ) − E [ s m ′ ( h θ ( y ) + c θ ∗ ) g ( y ) ] ≤ ∥ g ∥ ∞ ∣ c θ , K − c θ ∗ ∣ + K 1 k = 1 ∑ K s m ′ ( h θ ( y k ) + c θ ∗ ) g ( y k ) − E [ s m ′ ( h θ ( y ) + c θ ∗ ) g ( y ) ] .
The first term tends to 0 almost surely by the convergence of the offsets, and the second by the strong law of large numbers. We apply this with g ≡ 1 g \equiv1 g ≡ 1 and with g = ∇ θ h θ g=\nabla_\theta h_\theta g = ∇ θ h θ , which is bounded because it is continuous on [ 0 , 1 ] 2 [0,1]^2 [ 0 , 1 ] 2 . The limit of the denominator is positive: since h θ ( y ) + c θ ∗ ∈ [ ℓ − 2 M , ℓ + 2 M ] h_\theta(y)+c_\theta^* \in[\ell-2M,\ell+2M] h θ ( y ) + c θ ∗ ∈ [ ℓ − 2 M , ℓ + 2 M ] and s m ′ ( z ) sm'(z) s m ′ ( z ) decreases in ∣ z ∣ |z| ∣ z ∣ ,
E [ s m ′ ( h θ ( y ) + c θ ∗ ) ] ≥ min { s m ′ ( ℓ − 2 M ) , s m ′ ( ℓ + 2 M ) } > 0. \mathbb{E}\left[sm'\left(h_\theta(y)+c_\theta^*\right)\right]\geq\min\left\{sm'(\ell-2M),sm'(\ell+2M)\right\}>0. E [ s m ′ ( h θ ( y ) + c θ ∗ ) ] ≥ min { s m ′ ( ℓ − 2 M ) , s m ′ ( ℓ + 2 M ) } > 0.
Hence the ratio converges almost surely to − E [ s m ′ ( h θ ( y ) + c θ ∗ ) ∇ θ h θ ( y ) ] / E [ s m ′ ( h θ ( y ) + c θ ∗ ) ] -\mathbb{E}[sm'(h_\theta(y)+c_\theta^*)\nabla_\theta h_\theta(y)]/\mathbb{E}[sm'(h_\theta(y)+c_\theta^*)] − E [ s m ′ ( h θ ( y ) + c θ ∗ ) ∇ θ h θ ( y )] / E [ s m ′ ( h θ ( y ) + c θ ∗ )] . Finally, this limit equals ∇ θ c θ ∗ \nabla_\theta c_\theta^* ∇ θ c θ ∗ . The map ( θ , c ) ↦ E [ s m ( h θ ( y ) + c ) ] (\theta,c)\mapsto\mathbb{E}[sm(h_\theta(y)+c)] ( θ , c ) ↦ E [ s m ( h θ ( y ) + c )] is continuously differentiable, since its partial derivatives are expectations of functions continuous in ( θ , c , y ) (\theta,c,y) ( θ , c , y ) over a compact domain, and its derivative in c c c is the positive denominator above. The implicit function theorem applied to E [ s m ( h θ ( y ) + c θ ∗ ) ] = p \mathbb{E}[sm(h_\theta(y)+c_\theta^*)]=p E [ s m ( h θ ( y ) + c θ ∗ )] = p then gives the stated formula for ∇ θ c θ ∗ \nabla_\theta c_\theta^* ∇ θ c θ ∗ . □
When we extend our constraint solver beyond edge-density constraints to H H H -density constraints, we sample x i ( k ) x_i^{(k)} x i ( k ) for k ∈ [ N ] k\in[N] k ∈ [ N ] and i ∈ [ v ( H ) ] i\in[v(H)] i ∈ [ v ( H )] independently from Unif [ 0 , 1 ] \operatorname{Unif}[0,1] Unif [ 0 , 1 ] , and estimate the H H H -density constraint by the Monte Carlo estimator
t ^ ( H , f θ [ c ] ) = 1 N ∣ S ∣ ∑ k ∈ [ N ] ∑ π ∈ S ∏ { i , j } ∈ E ( H ) f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) , \widehat{t}(H,f_\theta[c])=\frac{1}{N|\mathcal{S}|}\sum_{k\in[N]}\sum_{\pi\in\mathcal{S}}\prod_{\{i,j\}\in E(H)}f_\theta[c]\left(x_{\pi(i)}^{(k)},x_{\pi(j)}^{(k)}\right), t ( H , f θ [ c ]) = N ∣ S ∣ 1 k ∈ [ N ] ∑ π ∈ S ∑ { i , j } ∈ E ( H ) ∏ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) ,
where S \mathcal{S} S is a set of permutations of V ( H ) V(H) V ( H ) .
Lemma E.4 (Implicit differentiation for the H H H -density estimator). Fix the samples { x i ( k ) : k ∈ [ N ] , i ∈ [ v ( H ) ] } \{x_i^{(k)}: k\in[N],\,i\in[v(H)]\} { x i ( k ) : k ∈ [ N ] , i ∈ [ v ( H )]} and permutation set S \mathcal{S} S . Suppose c θ c_\theta c θ is chosen so that t ^ ( H , f θ [ c θ ] ) = p \widehat{t}(H,f_\theta[c_\theta])=p t ( H , f θ [ c θ ]) = p , and that ∂ c t ^ ( H , f θ [ c ] ) ∣ c = c θ ≠ 0 \left.\partial_c\widehat{t}(H,f_\theta[c])\right|_{c=c_\theta}\ne0 ∂ c t ( H , f θ [ c ]) c = c θ = 0 . Then for all x ∈ [ 0 , 1 ] 2 x\in[0,1]^2 x ∈ [ 0 , 1 ] 2 ,
∇ θ f θ [ c θ ] ( x ) = ∂ f θ [ c ] ( x ) ∂ θ ∣ c = c θ − ∂ f θ [ c ] ( x ) ∂ c ∣ c = c θ ∇ θ t ^ ( H , f θ [ c ] ) ∣ c = c θ ∂ c t ^ ( H , f θ [ c ] ) ∣ c = c θ , \nabla_\theta f_\theta[c_\theta](x)=\left.\frac{\partial f_\theta[c](x)}{\partial\theta}\right|_{c=c_\theta}-\left.\frac{\partial f_\theta[c](x)}{\partial c}\right|_{c=c_\theta}\frac{\left.\nabla_\theta\widehat{t}(H,f_\theta[c])\right|_{c=c_\theta}}{\left.\partial_c\widehat{t}(H,f_\theta[c])\right|_{c=c_\theta}}, ∇ θ f θ [ c θ ] ( x ) = ∂ θ ∂ f θ [ c ] ( x ) c = c θ − ∂ c ∂ f θ [ c ] ( x ) c = c θ ∂ c t ( H , f θ [ c ]) c = c θ ∇ θ t ( H , f θ [ c ]) c = c θ , where
∇ θ t ^ ( H , f θ [ c ] ) = 1 N ∣ S ∣ ∑ k ∈ [ N ] , π ∈ S ∑ { i , j } ∈ E ( H ) ( ∏ { i ′ , j ′ } ∈ E ( H ) { i ′ , j ′ } ≠ { i , j } f θ [ c ] ( x π ( i ′ ) ( k ) , x π ( j ′ ) ( k ) ) ) ∇ θ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) , \nabla_\theta\widehat{t}(H,f_\theta[c])=\frac{1}{N|\mathcal{S}|}\sum_{k\in[N],\,\pi\in\mathcal{S}}\sum_{\{i,j\}\in E(H)}
\left(\prod_{\substack{\{i',j'\}\in E(H)\\\{i',j'\}\ne\{i,j\}}}f_\theta[c]\left(x_{\pi(i')}^{(k)},x_{\pi(j')}^{(k)}\right)\right)\nabla_\theta f_\theta[c]\left(x_{\pi(i)}^{(k)},x_{\pi(j)}^{(k)}\right), ∇ θ t ( H , f θ [ c ]) = N ∣ S ∣ 1 k ∈ [ N ] , π ∈ S ∑ { i , j } ∈ E ( H ) ∑ { i ′ , j ′ } ∈ E ( H ) { i ′ , j ′ } = { i , j } ∏ f θ [ c ] ( x π ( i ′ ) ( k ) , x π ( j ′ ) ( k ) ) ∇ θ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) , ∂ c t ^ ( H , f θ [ c ] ) = 1 N ∣ S ∣ ∑ k ∈ [ N ] , π ∈ S ∑ { i , j } ∈ E ( H ) ( ∏ { i ′ , j ′ } ∈ E ( H ) { i ′ , j ′ } ≠ { i , j } f θ [ c ] ( x π ( i ′ ) ( k ) , x π ( j ′ ) ( k ) ) ) ∂ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) ∂ c . \partial_c\widehat{t}(H,f_\theta[c])=\frac{1}{N|\mathcal{S}|}\sum_{k\in[N],\,\pi\in\mathcal{S}}\sum_{\{i,j\}\in E(H)}
\left(\prod_{\substack{\{i',j'\}\in E(H)\\\{i',j'\}\ne\{i,j\}}}f_\theta[c]\left(x_{\pi(i')}^{(k)},x_{\pi(j')}^{(k)}\right)\right)\frac{\partial f_\theta[c]\left(x_{\pi(i)}^{(k)},x_{\pi(j)}^{(k)}\right)}{\partial c}. ∂ c t ( H , f θ [ c ]) = N ∣ S ∣ 1 k ∈ [ N ] , π ∈ S ∑ { i , j } ∈ E ( H ) ∑ { i ′ , j ′ } ∈ E ( H ) { i ′ , j ′ } = { i , j } ∏ f θ [ c ] ( x π ( i ′ ) ( k ) , x π ( j ′ ) ( k ) ) ∂ c ∂ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) .
Proof. Let x ∈ [ 0 , 1 ] 2 x \in[0,1]^2 x ∈ [ 0 , 1 ] 2 . By the chain rule,
∇ θ f θ [ c θ ] ( x ) = ∂ f θ [ c ] ( x ) ∂ θ ∣ c = c θ + ∂ f θ [ c ] ( x ) ∂ c ∣ c = c θ ∇ θ c θ . \nabla_\theta f_\theta[c_\theta](x) = \left.\frac{\partial f_\theta[c](x)}{\partial\theta}\right|_{c=c_\theta} + \left.\frac{\partial f_\theta[c](x)}{\partial c}\right|_{c=c_\theta} \nabla_\theta c_\theta. ∇ θ f θ [ c θ ] ( x ) = ∂ θ ∂ f θ [ c ] ( x ) c = c θ + ∂ c ∂ f θ [ c ] ( x ) c = c θ ∇ θ c θ .
Thus, it suffices to derive an expression for ∇ θ c θ \nabla_\theta c_\theta ∇ θ c θ .
By assumption, c θ c_\theta c θ is chosen so that t ^ ( H , f θ [ c θ ] ) = p \hat{t}(H, f_\theta[c_\theta]) = p t ^ ( H , f θ [ c θ ]) = p . Differentiating both sides with respect to θ \theta θ yields
∇ θ t ^ ( H , f θ [ c θ ] ) = ∇ θ p = 0. \nabla_\theta\hat{t}(H, f_\theta[c_\theta]) = \nabla_\theta p = 0. ∇ θ t ^ ( H , f θ [ c θ ]) = ∇ θ p = 0.
Viewing t ^ ( H , f θ [ c ] ) \hat{t}(H, f_\theta[c]) t ^ ( H , f θ [ c ]) as a function of ( θ , c ) (\theta,c) ( θ , c ) , another application of the chain rule gives
0 = ∇ θ t ^ ( H , f θ [ c ] ) ∣ c = c θ + ∂ c t ^ ( H , f θ [ c ] ) ∣ c = c θ ∇ θ c θ . 0 = \left.\nabla_\theta\hat{t}(H, f_\theta[c])\right|_{c=c_\theta} + \left.\partial_c \hat{t}(H, f_\theta[c])\right|_{c=c_\theta} \nabla_\theta c_\theta. 0 = ∇ θ t ^ ( H , f θ [ c ]) c = c θ + ∂ c t ^ ( H , f θ [ c ]) c = c θ ∇ θ c θ .
Since ∂ c t ^ ( H , f θ [ c ] ) ∣ c = c θ ≠ 0 \left.\partial_c \hat{t}(H, f_\theta[c])\right|_{c=c_\theta} \ne0 ∂ c t ^ ( H , f θ [ c ]) c = c θ = 0 , we can solve for
∇ θ c θ = − ∇ θ t ^ ( H , f θ [ c ] ) ∣ c = c θ ∂ c t ^ ( H , f θ [ c ] ) ∣ c = c θ . \nabla_\theta c_\theta= -\frac{\left.\nabla_\theta\hat{t}(H, f_\theta[c])\right|_{c=c_\theta}}{\left.\partial_c \hat{t}(H, f_\theta[c])\right|_{c=c_\theta}}. ∇ θ c θ = − ∂ c t ^ ( H , f θ [ c ]) c = c θ ∇ θ t ^ ( H , f θ [ c ]) c = c θ .
Substituting this into the first display gives the claimed expression for ∇ θ f θ [ c θ ] ( x ) \nabla_\theta f_\theta[c_\theta](x) ∇ θ f θ [ c θ ] ( x ) .
Finally, we derive the displayed expressions for ∇ θ t ^ ( H , f θ [ c ] ) \nabla_\theta\hat{t}(H, f_\theta[c]) ∇ θ t ^ ( H , f θ [ c ]) and ∂ c t ^ ( H , f θ [ c ] ) \partial_c\hat{t}(H, f_\theta[c]) ∂ c t ^ ( H , f θ [ c ]) . For fixed k ∈ [ N ] k \in[N] k ∈ [ N ] and π ∈ S \pi\in S π ∈ S , write
P k , π ( c ) : = ∏ { i , j } ∈ E ( H ) f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) . P_{k,\pi}(c) := \prod_{\{i,j\}\in E(H)} f_\theta[c]\left(x_{\pi(i)}^{(k)},x_{\pi(j)}^{(k)}\right). P k , π ( c ) := { i , j } ∈ E ( H ) ∏ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) .
Then t ^ ( H , f θ [ c ] ) = 1 N ∣ S ∣ ∑ k , π P k , π ( c ) \hat{t}(H, f_\theta[c]) = \frac{1}{N|S|}\sum_{k,\pi} P_{k,\pi}(c) t ^ ( H , f θ [ c ]) = N ∣ S ∣ 1 ∑ k , π P k , π ( c ) , and hence
∇ θ t ^ ( H , f θ [ c ] ) = 1 N ∣ S ∣ ∑ k ∈ [ N ] , π ∈ S ∇ θ P k , π ( c ) = 1 N ∣ S ∣ ∑ k ∈ [ N ] , π ∈ S ∑ { i , j } ∈ E ( H ) ( ∏ { i ′ , j ′ } ∈ E ( H ) { i ′ , j ′ } ≠ { i , j } f θ [ c ] ( x π ( i ′ ) ( k ) , x π ( j ′ ) ( k ) ) ) ∇ θ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) , \begin{aligned}
\nabla_\theta\hat{t}(H, f_\theta[c])
= \frac{1}{N|S|}\sum_{k\in[N],\,\pi\in S}\nabla_\theta P_{k,\pi}(c) \\
&= \frac{1}{N|S|}\sum_{k\in[N],\,\pi\in S}\sum_{\{i,j\}\in E(H)}
\left(\prod_{\substack{\{i',j'\}\in E(H)\\\{i',j'\}\ne\{i,j\}}}
f_\theta[c]\left(x_{\pi(i')}^{(k)},x_{\pi(j')}^{(k)}\right)\right)
\nabla_\theta f_\theta[c]\left(x_{\pi(i)}^{(k)},x_{\pi(j)}^{(k)}\right),
\end{aligned} ∇ θ t ^ ( H , f θ [ c ]) = N ∣ S ∣ 1 k ∈ [ N ] , π ∈ S ∑ ∇ θ P k , π ( c ) = N ∣ S ∣ 1 k ∈ [ N ] , π ∈ S ∑ { i , j } ∈ E ( H ) ∑ { i ′ , j ′ } ∈ E ( H ) { i ′ , j ′ } = { i , j } ∏ f θ [ c ] ( x π ( i ′ ) ( k ) , x π ( j ′ ) ( k ) ) ∇ θ f θ [ c ] ( x π ( i ) ( k ) , x π ( j ) ( k ) ) ,
where the second line is the product rule. The expression for ∂ c t ^ ( H , f θ [ c ] ) \partial_c\hat{t}(H, f_\theta[c]) ∂ c t ^ ( H , f θ [ c ]) is identical, replacing ∇ θ f θ [ c ] ( ⋅ ) \nabla_\theta f_\theta[c](\cdot) ∇ θ f θ [ c ] ( ⋅ ) by ∂ c f θ [ c ] ( ⋅ ) \partial_c f_\theta[c](\cdot) ∂ c f θ [ c ] ( ⋅ ) .
Details of experiments
All experiments were conducted on a single NVIDIA RTX A5000 GPU. The execution time depends on the size of the graph, from 30 minutes for a triangle to a few hours for the Petersen graph.
In all experiments, we used a network of width d = 256 d = 256 d = 256 and depth L = 6 L = 6 L = 6 , which was sufficient to represent sharp boundaries and structural properties. The activation function ϕ \phi ϕ was either sin or the GELU nonlinearity; we did not observe a consistent advantage of one over the other.
In all experiments, we used the increasing input-encoding scale s ( ℓ ) = 2 ℓ − 1 s(\ell) = 2^{\ell-1} s ( ℓ ) = 2 ℓ − 1 . The constant-scale schedules in the ablation study are described in §I.
The set S S S in Eq. (8) was chosen according to the graph. For example, for complete graphs we used S = { i d } S = \{\mathrm{id}\} S = { id } , since any permutation yields the same summand. For cycles, we used a set of representatives for the cosets S V ( C k ) / Aut ( C k ) S_{V(C_k)}/\operatorname{Aut}(C_k) S V ( C k ) / Aut ( C k ) , where Aut ( C k ) \operatorname{Aut}(C_k) Aut ( C k ) is the automorphism group of C k C_k C k , which gives ∣ S ∣ = ( k − 1 ) ! / 2 |S|=(k-1)!/2 ∣ S ∣ = ( k − 1 )! /2 . For the other graphs, we used a set S = { π j : j = 0 , 1 , … , m − 1 } S=\{\pi^j:j=0,1,\ldots,m-1\} S = { π j : j = 0 , 1 , … , m − 1 } generated by a permutation π ∈ S V ( H ) \pi\in S_{V(H)} π ∈ S V ( H ) , where π \pi π and m m m are chosen so that the set
{ { π j ( v ) , π j ( w ) } : { v , w } ∈ E ( H ) and j = 0 , 1 , … , m − 1 } \left\{\{\pi^j(v),\pi^j(w)\}:\{v,w\}\in E(H)\text{ and }j=0,1,\ldots,m-1\right\} { { π j ( v ) , π j ( w )} : { v , w } ∈ E ( H ) and j = 0 , 1 , … , m − 1 }
equals the set of all unordered pairs of distinct vertices { { v , w } : v , w ∈ V ( H ) and v ≠ w } \{\{v,w\}:v,w\in V(H)\text{ and }v\ne w\} {{ v , w } : v , w ∈ V ( H ) and v = w } .
For training, we used the largest number of samples that fit in GPU memory, ranging from 2 12 2^{12} 2 12 to 2 16 2^{16} 2 16 . For large graphs such as the Petersen graph, we repeated multiple forward passes to accumulate gradients, yielding an effective sample size of 2 16 2^{16} 2 16 . For evaluation, we used 2 28 2^{28} 2 28 evaluation samples. With caching of pairwise network evaluations, one training iteration takes O ( N V ( H ) 2 L d 2 + N ∣ S ∣ e ( H ) ) O(N_{V(H)}^2Ld^2+N|S|e(H)) O ( N V ( H ) 2 L d 2 + N ∣ S ∣ e ( H )) time and O ( N V ( H ) 2 L d ) O(N_{V(H)}^2Ld) O ( N V ( H ) 2 L d ) memory. Larger motifs therefore reduce the feasible batch size under a fixed memory budget. The Monte Carlo estimator retains the usual O ( N − 1 / 2 ) O(N^{-1/2}) O ( N − 1/2 ) absolute-error rate for bounded integrands, but relative error becomes much harder to control when the true density is extremely small.
For optimisation, we used the Adam optimiser with β 1 = 0.9 \beta_1=0.9 β 1 = 0.9 and β 2 = 0.999 \beta_2=0.999 β 2 = 0.999 . We repeated the experiments with learning rates η ∈ { 10 − 3 , 5 × 10 − 4 , 10 − 4 , 5 × 10 − 5 } \eta\in\{10^{-3},5\times10^{-4},10^{-4},5\times10^{-5}\} η ∈ { 1 0 − 3 , 5 × 1 0 − 4 , 1 0 − 4 , 5 × 1 0 − 5 } , and set the minimum learning rate in the scheduler to 1 % 1\% 1% of the initial learning rate. We trained for 20,000 epochs, corresponding to five cosine-annealing cycles.
For the constraint solver, we found that applying Newton’s method directly (without modification) can be unstable, owing to vanishing derivatives in many regimes. In particular, since many optimal graphons take values close to 0 or 1, the sigmoid derivative s m ( x ) ( 1 − s m ( x ) ) sm(x)(1-sm(x)) s m ( x ) ( 1 − s m ( x )) is close to zero over much of the domain. Consequently, the denominator in the Newton update can become very small, leading to excessively large updates and unstable convergence. To address this, we use a clipped variant of Newton’s method. To set the clipping range, we compute upper and lower bounds on the solution c ∗ c^* c ∗ and use their difference as the initial clipping range. We then gradually decrease the clipping range as the iteration proceeds, which improves stability. The detailed algorithms are described in Algorithm 1 (edge-density constraint) and Algorithm 2 (homomorphism-density constraint).
Algorithm 1 Edge-Density Constraint Solver
Require: p ∈ ( 0 , 1 ) , y ∈ R N p\in(0,1),y\in\mathbb{R}^N p ∈ ( 0 , 1 ) , y ∈ R N
Ensure: 1 N ∑ i = 1 N s m ( y i + c ∗ ) ≈ p \frac{1}{N}\sum_{i=1}^{N}sm(y_i+c^*)\approx p N 1 ∑ i = 1 N s m ( y i + c ∗ ) ≈ p
c 1 ← s m − 1 ( p ) − 1 N ∑ i = 1 N y i c_1\leftarrow sm^{-1}(p)-\frac{1}{N}\sum_{i=1}^{N}y_i c 1 ← s m − 1 ( p ) − N 1 ∑ i = 1 N y i \hfill {Initialise with guess}
D ← max i { y i } − min i { y i } D\leftarrow\max_i\{y_i\}-\min_i\{y_i\} D ← max i { y i } − min i { y i } \hfill {Compute range of y y y values for clipping}
for t = 1 , 2 , … , T max t=1,2,\ldots,T_{\max} t = 1 , 2 , … , T m a x do
f ( c t ) ← 1 N ∑ i = 1 N s m ( y i + c t ) − p f(c_t)\leftarrow\frac{1}{N}\sum_{i=1}^{N}sm(y_i+c_t)-p f ( c t ) ← N 1 ∑ i = 1 N s m ( y i + c t ) − p
if ∣ f ( c t ) ∣ < ϵ |f(c_t)|<\epsilon ∣ f ( c t ) ∣ < ϵ then
break
end if
f ′ ( c t ) ← 1 N ∑ i = 1 N s m ( y i + c t ) ( 1 − s m ( y i + c t ) ) f'(c_t)\leftarrow\frac{1}{N}\sum_{i=1}^{N}sm(y_i+c_t)(1-sm(y_i+c_t)) f ′ ( c t ) ← N 1 ∑ i = 1 N s m ( y i + c t ) ( 1 − s m ( y i + c t ))
c t + 1 ← c t − Clip [ − D / t , D / t ] ( f ( c t ) f ′ ( c t ) ) c_{t+1}\leftarrow c_t-\operatorname{Clip}_{[-D/t,D/t]}\left(\frac{f(c_t)}{f'(c_t)}\right) c t + 1 ← c t − Clip [ − D / t , D / t ] ( f ′ ( c t ) f ( c t ) ) \hfill {Clipping range D / t D/t D / t shrinks with the iteration index t t t .}
end for
Return c t c_t c t
For the variants in the ablation study, we performed hyperparameter searches for each variant. When using constant per-layer input encoding scale s s s , we searched over s ( ℓ ) ∈ { 1 , 2 , 4 , 8 } s(\ell)\in\{1,2,4,8\} s ( ℓ ) ∈ { 1 , 2 , 4 , 8 } . For the strength of the regulariser, we searched over λ ∈ { 0.01 , 0.1 , 1 , 10 , 100 } \lambda\in\{0.01,0.1,1,10,100\} λ ∈ { 0.01 , 0.1 , 1 , 10 , 100 } . For the constant learning rate, we used two values, 10 − 4 10^{-4} 1 0 − 4 (low) and 10 − 3 10^{-3} 1 0 − 3 (high).
When reporting the homomorphism density computed by discretisation, we use a ( 2 14 × 2 14 ) (2^{14}\times2^{14}) ( 2 14 × 2 14 ) grid for K 3 K_3 K 3 , C 5 C_5 C 5 , C 7 C_7 C 7 and a ( 2 10 × 2 10 ) (2^{10}\times2^{10}) ( 2 10 × 2 10 ) grid for H 6 H_6 H 6 , and 64-bit floating point precision.
Algorithm 2 Homomorphism-Density Constraint Solver
Require: $p \in (0,1)$, $y \in \mathbb{R}^{B \times m}$
Ensure: $\frac{1}{B}\sum_{b=1}^{B}\prod_{j=1}^{m} sm(y_{b,j}+c^{*}) \approx p$
$c_1 \leftarrow sm^{-1}(p^{1/m})-\frac{1}{Bm}\sum_{b=1}^{B}\sum_{j=1}^{m}y_{b,j}$ {Initialise with guess}
$D \leftarrow \max_{b,j}\{y_{b,j}\}-\min_{b,j}\{y_{b,j}\}$ {Compute range of $y$ values for clipping}
for $t=1,2,\ldots,T_{\max}$ do
$S \leftarrow (sm(y_{b,j}+c_t))_{b\in[B],j\in[m]}$
$P \leftarrow \left(\prod_{j=1}^{m}S_{b,j}\right)_{b\in[B]}$
$f(c_t)\leftarrow \frac{1}{B}\sum_{b=1}^{B}P_b-p$
if $|f(c_t)|<\epsilon$ then
break
end if
$f'(c_t)\leftarrow \frac{1}{B}\sum_{b=1}^{B}P_b\sum_{j=1}^{m}(1-S_{b,j})$
$c_{t+1}\leftarrow c_t-\operatorname{Clip}[-D/t,D/t]\left(\frac{f(c_t)}{f'(c_t)}\right)$
end for
Return $c_t$
Table 7: Homomorphism densities of the Petersen graph in graphons under the edge-density constraint t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p , found by our method and by a hand-crafted construction.
Table 7.
The code to replicate our experiments is available at https://github.com/mekty2012/ INR4GraphonVariationalProblem .
Additional experimental results
We consider the problem of minimising the homomorphism density of the Petersen graph under the edge-density constraint t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p for various values of p p p . For minimising the Petersen homomorphism density, there are (to the best of our knowledge) no known results or conjectures, likely due to the graph size and the lack of an obvious extremal structure. We applied our method for p ∈ { 1 / 2 , 2 / 3 , 4 / 5 , 4 / 7 , 5 / 8 , 5 / 7 } p \in\{1/2,2/3,4/5,4/7,5/8,5/7\} p ∈ { 1/2 , 2/3 , 4/5 , 4/7 , 5/8 , 5/7 } ; the learnt graphons are shown in Figure 7 . As there is no known conjectured optimum, we compare our results to those obtained by a hand-crafted graphon motivated by Razborov [ [40 ] ; see §H for details.
Figure 7. Graphons found for the Petersen graph density minimisation under the edge-density constraint t ( K 2 , W ) = p t(K_2,W)=p t ( K 2 , W ) = p .
We also report the complete results of the variational problem discussed in § 4 ; see Figure 8 to Figure 12 for the found graphons. We compute the results by solving the constraint after the discretisation of the learnt graphon, which gives a step graphon that satisfies the constraint exactly. For the quantitative comparison, we include the tripartite construction W L Z W_{\mathrm{LZ}} W LZ of Lubetzky and Zhao [ [27 ] only in the cases where this construction is available in the literature, namely the upper-tail problem for regular graphs. Accordingly, Table 8 compares h q ( W o u r s ) h_q(W_{\mathrm{ours}}) h q ( W ours ) with h q ( W L Z ) h_q(W_{\mathrm{LZ}}) h q ( W LZ ) for H ∈ { C 4 , C 5 } H \in\{C_4,C_5\} H ∈ { C 4 , C 5 } under constraints t ( C k , W ) ≥ r k t(C_k,W)\ge r^k t ( C k , W ) ≥ r k . For the K 1 , 3 K_{1,3} K 1 , 3 upper-tail problem, Table 8 reports only our learnt solutions (no corresponding W L Z W_{\mathrm{LZ}} W LZ construction is available in the literature for this case). For the lower-tail problem for K 3 K_3 K 3 , we likewise report only our learnt solutions; see Table 9 .
Figure 8. Found graphon for upper tail variational problems for K 3 K_3 K 3 , for q = 0.05 q = 0.05 q = 0.05 (top) and q = 0.1 q = 0.1 q = 0.1 (bottom) and r = 0.4 , 0.5 , 0.6 r = 0.4, 0.5, 0.6 r = 0.4 , 0.5 , 0.6 (left to right).
Table 8. Relative-entropy h q ( W ) h_q(W) h q ( W ) at our learnt graphon (W o u r s W_{\mathrm{ours}} W ours ) and, for H ∈ { C 4 , C 5 } H \in\{C_4,C_5\} H ∈ { C 4 , C 5 } , at the tripartite construction W L Z W_{\mathrm{LZ}} W LZ of Lubetzky and Zhao [2015], for (P2) on ( q , r ) ∈ { 0.05 , 0.1 } × { 0.4 , 0.5 , 0.6 } (q,r) \in\{0.05,0.1\} \times\{0.4,0.5,0.6\} ( q , r ) ∈ { 0.05 , 0.1 } × { 0.4 , 0.5 , 0.6 } . We also report a lower bound on the optimum for H ∈ { C 4 , C 5 } H \in\{C_4,C_5\} H ∈ { C 4 , C 5 } , and W o u r s W_{\mathrm{ours}} W ours for H = K 1 , 3 H=K_{1,3} H = K 1 , 3 (no corresponding W L Z W_{\mathrm{LZ}} W LZ construction is available in the literature for this case). Lower is better.
Table 9. Relative-entropy h q ( W ) h_q(W) h q ( W ) at our learnt graphon (W o u r s W_{\mathrm{ours}} W ours ) for (P2) with H = K 3 H=K_3 H = K 3 on ( q , r ) ∈ { 0.7 , 0.8 , 0.9 } × { 0.05 , 0.1 } (q,r) \in\{0.7,0.8,0.9\} \times\{0.05,0.1\} ( q , r ) ∈ { 0.7 , 0.8 , 0.9 } × { 0.05 , 0.1 } . Lower is better.
Figure 12. Found graphon for upper tail variational problems for K 1 , 3 K_{1,3} K 1 , 3 , for q = 0.05 q = 0.05 q = 0.05 (top) and q = 0.1 q = 0.1 q = 0.1 (bottom) and r = 0.4 , 0.5 , 0.6 r = 0.4, 0.5, 0.6 r = 0.4 , 0.5 , 0.6 (left to right).
When H H H is d d d -regular, Lubetzky and Zhao [ [27 ] also prove a lower bound on the optimum of the upper-tail problem. Three graphs in our experiments, K 3 K_3 K 3 , C 4 C_4 C 4 , and C 5 C_5 C 5 , satisfy this assumption, and the computed lower bound is reported in Table 6 and Table 8 ; its values are the same for the three graphs, as the bound is determined by d d d .
Details of hand-crafted graphons
We consider edge densities satisfying 1 − 1 / k < p < 1 − 1 / ( k + 1 ) 1-1/k < p < 1-1/(k+1) 1 − 1/ k < p < 1 − 1/ ( k + 1 ) , where k k k is a positive integer.
The first two instances are graphons arising from the optimal solution to edge-density-constrained K 3 K_3 K 3 homomorphism-density minimisation. We construct a complete ( k + 1 ) (k+1) ( k + 1 ) -partite graphon by partitioning [ 0 , 1 ] [0,1] [ 0 , 1 ] into ( k + 1 ) (k+1) ( k + 1 ) groups, X 1 , … , X k + 1 X_1,\ldots,X_{k+1} X 1 , … , X k + 1 , and defining
W i ( x 1 , x 2 ) = { 1 if x 1 ∈ X m , x 2 ∈ X n , m ≠ n , 0 if x 1 ∈ X m , x 2 ∈ X m . W_i(x_1,x_2)=
\begin{cases}
1 & \text{if } x_1\in X_m,\ x_2\in X_n,\ m\ne n,\\
0 & \text{if } x_1\in X_m,\ x_2\in X_m.
\end{cases} W i ( x 1 , x 2 ) = { 1 0 if x 1 ∈ X m , x 2 ∈ X n , m = n , if x 1 ∈ X m , x 2 ∈ X m .
We set ∣ X 1 ∣ = ⋯ = ∣ X k ∣ = x \lvert X_1\rvert=\cdots=\lvert X_k\rvert=x ∣ X 1 ∣ = ⋯ = ∣ X k ∣ = x and ∣ X k + 1 ∣ = 1 − k x \lvert X_{k+1}\rvert=1-kx ∣ X k + 1 ∣ = 1 − k x , and choose x x x to satisfy the edge-density constraint. This amounts to solving the quadratic equation
k ( k − 1 ) x 2 + 2 k x ( 1 − k x ) = p . k(k-1)x^2+2kx(1-kx)=p. k ( k − 1 ) x 2 + 2 k x ( 1 − k x ) = p .
This quadratic has two solutions: one with x > 1 − k x x>1-kx x > 1 − k x (denoted W 1 W_1 W 1 ) and one with x < 1 − k x x<1-kx x < 1 − k x (denoted W 2 W_2 W 2 ). The first corresponds to the optimum for K 3 K_3 K 3 density minimisation.
The next too instance is constructed by deleting edges from the complete ( k + 1 ) (k+1) ( k + 1 ) -partite graphon. We partition the interval [ 0 , 1 ] [0,1] [ 0 , 1 ] into k + 1 k+1 k + 1 groups X 1 , … , X k , X k + 1 X_1,\ldots,X_k,X_{k+1} X 1 , … , X k , X k + 1 with ∣ X 1 ∣ = ⋯ = \lvert X_1\rvert=\cdots= ∣ X 1 ∣ = ⋯ =
Figure 10. Found graphon for upper tail variational problems for C 4 C_4 C 4 , for q = 0.05 q = 0.05 q = 0.05 (top) and q = 0.1 q = 0.1 q = 0.1 (bottom) and r = 0.4 , 0.5 , 0.6 r = 0.4, 0.5, 0.6 r = 0.4 , 0.5 , 0.6 (left to right).
Figure 11. Found graphon for upper tail variational problems for C 5 C_5 C 5 , for q = 0.05 q = 0.05 q = 0.05 (top) and q = 0.1 q = 0.1 q = 0.1 (bottom) and r = 0.4 , 0.5 , 0.6 r = 0.4, 0.5, 0.6 r = 0.4 , 0.5 , 0.6 (left to right).
Table 8: Relative-entropy h q ( W ) h_q(W) h q ( W ) at our learnt graphon (W o u r s W_{\mathrm{ours}} W ours ) and, for H ∈ { C 4 , C 5 } H \in\{C_4,C_5\} H ∈ { C 4 , C 5 } , at the tripartite construction W L Z W_{\mathrm{LZ}} W LZ of Lubetzky and Zhao [ [27 ] , for (P2) on ( q , r ) ∈ { 0.05 , 0.1 } × { 0.4 , 0.5 , 0.6 } (q,r) \in\{0.05,0.1\} \times\{0.4,0.5,0.6\} ( q , r ) ∈ { 0.05 , 0.1 } × { 0.4 , 0.5 , 0.6 } . We also report a lower bound on the optimum for H ∈ { C 4 , C 5 } H \in\{C_4,C_5\} H ∈ { C 4 , C 5 } , and W o u r s W_{\mathrm{ours}} W ours for H = K 1 , 3 H=K_{1,3} H = K 1 , 3 (no corresponding W L Z W_{\mathrm{LZ}} W LZ construction is available in the literature for this case). Lower is better.
Table 9: Relative-entropy h q ( W ) h_q(W) h q ( W ) at our learnt graphon (W o u r s W_{\mathrm{ours}} W ours ) for (P2) with H = K 3 H=K_3 H = K 3 on ( q , r ) ∈ { 0.7 , 0.8 , 0.9 } × { 0.05 , 0.1 } (q,r) \in\{0.7,0.8,0.9\} \times\{0.05,0.1\} ( q , r ) ∈ { 0.7 , 0.8 , 0.9 } × { 0.05 , 0.1 } . Lower is better.
∣ X k ∣ = ∣ X k + 1 ∣ = 1 / ( k + 1 ) |X_k|=|X_{k+1}|=1/(k+1) ∣ X k ∣ = ∣ X k + 1 ∣ = 1/ ( k + 1 ) , and define
W 3 ( x 1 , x 2 ) = { ( k + 1 ) p k if x 1 ∈ X m , x 2 ∈ X n , m ≠ n , 0 if x 1 ∈ X m , x 2 ∈ X m . W_3(x_1,x_2)=
\begin{cases}
\frac{(k+1)p}{k} & \text{if } x_1\in X_m,\ x_2\in X_n,\ m\ne n,\\
0 & \text{if } x_1\in X_m,\ x_2\in X_m.
\end{cases} W 3 ( x 1 , x 2 ) = { k ( k + 1 ) p 0 if x 1 ∈ X m , x 2 ∈ X n , m = n , if x 1 ∈ X m , x 2 ∈ X m .
W 4 ( x 1 , x 2 ) = { p ( k + 1 ) 2 − k 2 − k + 2 2 if x 1 ∈ X 1 , x 2 ∈ X 2 or vice versa , 0 if x 1 ∈ X m , x 2 ∈ X m , 1 otherwise . W_4(x_1,x_2)=
\begin{cases}
\frac{p(k+1)^2-k^2-k+2}{2} & \text{if } x_1\in X_1,\ x_2\in X_2\text{ or vice versa},\\
0 & \text{if } x_1\in X_m,\ x_2\in X_m,\\
1 & \text{otherwise}.
\end{cases} W 4 ( x 1 , x 2 ) = ⎩ ⎨ ⎧ 2 p ( k + 1 ) 2 − k 2 − k + 2 0 1 if x 1 ∈ X 1 , x 2 ∈ X 2 or vice versa , if x 1 ∈ X m , x 2 ∈ X m , otherwise .
For 1 − 1 / k < p < 1 − 1 / ( k + 1 ) 1-1/k<p<1-1/(k+1) 1 − 1/ k < p < 1 − 1/ ( k + 1 ) , both nontrivial edge probabilities above lie in [ 0 , 1 ] [0,1] [ 0 , 1 ] : their nonnegativity follows from the lower bound on p p p , while ( k + 1 ) p / k < 1 (k+1)p/k<1 ( k + 1 ) p / k < 1 and ( p ( k + 1 ) 2 − k 2 − k + 2 ) / 2 < 1 (p(k+1)^2-k^2-k+2)/2<1 ( p ( k + 1 ) 2 − k 2 − k + 2 ) /2 < 1 follow from the upper bound.
Finally, the last graphon is the constant graphon W ( x 1 , x 2 ) = p W(x_1,x_2)=p W ( x 1 , x 2 ) = p .
We visualised W 1 , … , W 4 W_1,\ldots,W_4 W 1 , … , W 4 for p = 0.7 p=0.7 p = 0.7 in Figure 13 .
Figure 13. Hand-crafted graphons W 1 W_1 W 1 , W 2 W_2 W 2 , W 3 W_3 W 3 , W 4 W_4 W 4 (left to right) with edge density t ( K 2 , W ) = 0.7 t(K_2, W) = 0.7 t ( K 2 , W ) = 0.7 .
Ablation study, robustness, non-neural baselines, and multi-task variant
Ablation Study. We perform an ablation study on triangle-density minimisation under the constraint t ( K 2 , W ) = 7 / 9 t(K_2,W)=7/9 t ( K 2 , W ) = 7/9 , which is not of the form 1 − 1 / k 1-1/k 1 − 1/ k and admits multiple types of optima. We consider four variants: (1) replacing our architecture with a ResNet that uses sinusoidal input encoding only in the first layer; (2) using a constant per-layer input encoding scale s s s ; (3) enforcing the constraint via a regulariser; and (4) using a constant learning rate instead of cosine-annealing scheduling. For fair comparison, we performed hyperparameter searches for the constant value of s s s in (2) and the strength of the regulariser in (3), and report the best run for each variant; for (4), we report the runs with a low and a high learning rate. To separate the effect of the sinusoidal features from that of their per-layer injection, we also repeat our method and every variant with
GELU in place of every sine function, keeping the per-layer injection; in the ResNet variant, the sinusoidal encoding of the first layer is kept. As in §G, all values are computed after solving for the scalar bias c c c on the discretised graphon. The graphons found by these variants are shown in Figure 14 and quantitative results in Table 10 . With sinusoidal features, every variant reaches a lower K 3 K_3 K 3 density than with GELU. Since the GELU column also changes the activation ϕ \phi ϕ , we also compare with the ten runs in the robustness study below, which use sinusoidal features with ϕ = G E L U \phi=\mathrm{GELU} ϕ = GELU : their mean 0.435661 is also below the 0.436066 of our method with GELU features. The ResNet variant (1) and the constant-scale variant (2) often fail to recover sharp, straight boundaries, consistent with a bias toward smooth functions in (1) and toward high frequencies in (2). With the penalty-based constraint (3), the learnt graphon often violates fine structural details (e.g., the size of the smallest block). Without cosine-annealing scheduling (4), the learnt graphon either fails to capture the multi-block structure (low learning rates) or exhibits less stable boundaries (high learning rates), highlighting the benefit of alternating between higher and lower learning rates.
Table 10. K 3 K_3 K 3 densities in graphons found by our method, ablations, and non-neural baselines for K 3 K_3 K 3 density minimisation under t ( K 2 , W ) = 7 / 9 t(K_2,W)=7/9 t ( K 2 , W ) = 7/9 , with sinusoidal features or with GELU features in the per-layer encoding and activation. The optimum is 98 / 225 ≈ 0.435556 98/225\approx0.435556 98/225 ≈ 0.435556 .
Figure 14. Graphons found by our method and its ablations, for K 3 K_3 K 3 density minimisation under the constraint t ( K 2 , W ) = 7 / 9 t(K_2,W)=7/9 t ( K 2 , W ) = 7/9 .
Multi-scale encoding. The increasing scale s ( ℓ ) s(\ell) s ( ℓ ) is motivated by the step-like structure of the optima: approximating a step boundary requires increasingly high spatial frequencies. Early layers, whose encodings have low frequencies, provide the coarse block geometry, while later layers, whose encodings have higher frequencies, refine the boundaries through the residual connections, so that earlier layers do not need to carry high-frequency information. The scale enters only through the initialisation of U ( ℓ ) U^{(\ell)} U ( ℓ ) , whose entries are drawn from Unif [ − s ( ℓ ) / 2 , s ( ℓ ) / 2 ] \operatorname{Unif}[-s(\ell)/\sqrt{2},s(\ell)/\sqrt{2}] Unif [ − s ( ℓ ) / 2 , s ( ℓ ) / 2 ] , so s ( ℓ ) s(\ell) s ( ℓ ) sets the initial spatial frequency of the encoding sin ( U ( ℓ ) x ) \sin(U^{(\ell)}x) sin ( U ( ℓ ) x ) in layer ℓ \ell ℓ . Since sin \sin sin is bounded and the remaining weights are initialised with scale 1 / 2 d 1/\sqrt{2d} 1/ 2 d , increasing s ( ℓ ) s(\ell) s ( ℓ ) gives later layers access to finer scales without increasing the magnitude of the hidden states. The constant-scale variant (2) above isolates the effect of increasing the scale. To see the contribution of each layer, Figure 15 applies the output layer to the hidden state g θ ( ℓ ) g_{\theta}^{(\ell)} g θ ( ℓ ) after each layer ℓ \ell ℓ of a trained network. The first layer gives only a smooth gradient, the next layers form a band along the diagonal and split it into blocks, and the last layers sharpen the block boundaries into the five-block structure of the learnt graphon.
Figure 15. Graphons obtained by applying the output layer to the hidden state g θ ( ℓ ) g_\theta^{(\ell)} g θ ( ℓ ) after layer ℓ \ell ℓ of a trained network, for K 3 K_3 K 3 density minimisation under t ( K 2 , W ) = 7 / 9 t(K_2,W)=7/9 t ( K 2 , W ) = 7/9 , with the scalar bias c c c solved separately for each ℓ \ell ℓ so that t ( K 2 , W ) = 7 / 9 t(K_2,W)=7/9 t ( K 2 , W ) = 7/9 ; ℓ = 1 , … , 6 \ell=1,\ldots,6 ℓ = 1 , … , 6 from left to right, and ℓ = 6 \ell=6 ℓ = 6 is the learnt graphon.
Robustness. Except for the exhaustive study, the results in the main text are the best of eight training runs over the activation and the learning rate (§ 4 ). To measure the variability across random initialisations separately, we repeated five instances ten times each under a single fixed configuration (GELU activation, learning rate 10 − 3 10^{-3} 1 0 − 3 ), varying only the random initialisation, and report the mean with a 95% confidence interval:
K 3 K_3 K 3 at p = 7 / 9 p=7/9 p = 7/9 : 0.435661, [0.435656, 0.435667], against the optimum 98 / 225 ≈ 0.435556 98/225 \approx0.435556 98/225 ≈ 0.435556 .
C 5 C_5 C 5 at p = 3 / 5 p=3/5 p = 3/5 : 0.066731, [0.066706, 0.066756], against the conjectured optimum 0.066616.
C 7 C_7 C 7 at p = 3 / 5 p=3/5 p = 3/5 : 0.026467, [0.026134, 0.026800], against our conjectured optimum 0.026261. One run converged to the constant graphon, with density p 7 p^7 p 7 ; the other nine give 0.026297, [0.026279, 0.026315].
H 6 H_6 H 6 at p = 4 / 5 p=4/5 p = 4/5 : 0.129877, [0.129851, 0.129902], against 0.13056 for the k k k -partite graphon and 0.134218 for the constant graphon.
The upper-tail problem for K 3 K_3 K 3 at ( q , r ) = ( 0.05 , 0.5 ) (q,r)=(0.05,0.5) ( q , r ) = ( 0.05 , 0.5 ) : 0.727215, [0.727210, 0.727220], against the lower bound 0.725284 (Table 6 ).
The learnt structures are also consistent across seeds. For K 3 K_3 K 3 , seven runs recover the clean five-block partition, and the other three produce five parts whose smallest part is not an exact block, with comparable objective values; since the optimum is not unique, this does not indicate suboptimality. For C 5 C_5 C 5 , all ten runs recover the two-block structure of the bottom row of Figure 3 , and for C 7 C_7 C 7 , the nine nonconstant runs recover that of Figure 4 . For H 6 H_6 H 6 , eight runs recover the pattern of Figure 5 , and the other two show the same band with an oscillating boundary, at objectives 0.04% and 0.10% above the average of the eight. For the upper-tail problem, all ten runs recover the two-block structure of Figure 8 . Across the 702 instances of the exhaustive study in § 4 , the three seeds have a median relative standard deviation of 1.4 × 10 − 4 1.4 \times10^{-4} 1.4 × 1 0 − 4 and differ by more than 1% in 5.8% of the instances.
We also checked the sensitivity to the other sources of randomness. For C 5 C_5 C 5 , training with permutation sets S S S of size 1, 2, and 12 in (8) gives objectives that agree within 1.6 × 10 − 4 1.6 \times10^{-4} 1.6 × 1 0 − 4 at each of the six densities of Table 3 . Finally, for the learnt graphon for K 3 K_3 K 3 at p = 7 / 9 p=7/9 p = 7/9 , solving for the scalar bias c c c on 1000 independent batches of 2 16 2^{16} 2 16 samples, as in training, gives a constraint violation with standard deviation 1.1 × 10 − 3 1.1 \times10^{-3} 1.1 × 1 0 − 3 and maximum 3.4 × 10 − 3 3.4 \times10^{-3} 3.4 × 1 0 − 3 ; this error does not affect the reported values, which solve for c c c on the discretised graphon, and refining the discretisation from 256 2 256^2 25 6 2 to 512 2 512^2 51 2 2 points changes t ( K 3 , W ) t(K_3,W) t ( K 3 , W ) by 9.7 × 10 − 5 9.7 \times10^{-5} 9.7 × 1 0 − 5 .
Non-neural Baselines. On the same triangle-density-minimisation task we evaluated four non-neural baselines tailored to step graphons: (a) a stochastic block model (SBM) with 256 equal-sized blocks and trainable edge densities; (b) SBMs with 5 blocks and 64 blocks, with trainable edge densities and trainable block sizes; (c) a decision tree; and (d) a tree ensemble. Each baseline was run four times from independent random initialisations, and we report the best objective value across runs in Table 10 . The SBMs with trainable block sizes collapsed to nearly constant graphons, suggesting a difficult optimisation landscape; the fixed-block SBM recovered a noisy multi-block structure; the tree-based baselines produced structured but qualitatively different graphons. See Figure 16 for visualisations of the found graphons.
Figure 16. Graphons found by non-neural baselines, fixed-block SBM, trainable-block SBM with 5 / 64 blocks, decision tree, and tree ensemble (left to right), for K 3 K_3 K 3 density minimisation under the constraint t ( K 2 , W ) = 7 / 9 t(K_2,W)=7/9 t ( K 2 , W ) = 7/9 .
These baselines can represent the optimal graphon, at least approximately; the difference lies in optimisation. For the fixed-block SBM and the tree-based baselines, moving a block boundary is hard, since almost every configuration with values in { 0 , 1 } \{0,1\} { 0 , 1 } is a local optimum, so these methods rarely leave the geometry of their initialisation. Making the block sizes trainable does not help, as these SBMs collapse to nearly constant graphons. In contrast, the neural graphon adjusts the values and the boundaries of its regions jointly and continuously, and it does not require choosing in advance between multipartite, banded, circular-distance, or two-block structures.
Multi-task Variant. The main paper trains one network per ( H , p ) (H,p) ( H , p ) . To probe whether shared training across related tasks is viable, we trained a single conditional network jointly over p ∈ [ 1 / 2 , 2 / 3 ] p \in[1/2,2/3] p ∈ [ 1/2 , 2/3 ] for H = K 3 H=K_3 H = K 3 . Concretely, we condition the network on p p p using FiLM-style feature-wise affine modulation of hidden activations [36 ] . The resulting conditional network achieves absolute error at most 2.09 × 10 − 4 2.09 \times10^{-4} 2.09 × 1 0 − 4 and average absolute error 3.12 × 10 − 5 3.12 \times10^{-5} 3.12 × 1 0 − 5 relative to the known optimum, for p p p on a uniform grid of 100 points in [ 1 / 2 , 2 / 3 ] [1/2,2/3] [ 1/2 , 2/3 ] . See Figure 17 for the learnt density curve and its error, and Figure 18 for the learnt graphons. While limited to a single graph, this experiment indicates that shared training across related tasks can substantially reduce the per-instance burden of our framework, and we view a fuller multi-task / multi-graph treatment as a natural extension.
Figure 17. (Left) Triangle density as a function of p p p for the conditional network, compared to the known optimum. (Right) Absolute error of the conditional network’s triangle density relative to the known optimum.
Figure 18. Learnt graphons for the conditional network at p ∈ { 1 / 2 , 4 / 7 , 3 / 5 , 5 / 8 , 2 / 3 } p \in\{1/2, 4/7, 3/5, 5/8, 2/3\} p ∈ { 1/2 , 4/7 , 3/5 , 5/8 , 2/3 } (left to right).