{'fraction_non_alphanumeric': 0.05466225719390276, 'fraction_numerical': 0.009237085186452275, 'mean_word_length': 3.816550714024167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Optimal Cooperation and Submodularity for Computing Potts' Partition Functions with a Large Number of State

The partition function of the q-state Potts model with random ferromagnetic couplings in the large-q limit is generally dominated by the contribution of a single diagram of the high temperature expansion. Computing this dominant diagram amounts to minimizing a particular submodular function. We provide a combinatorial optimization algorithm, the optimal cooperation algorithm, which works in polynomial time for any lattice. Practical implementation and the speed of the method is also discussed.


Introduction
Spin models with discrete symmetry are often used to describe order-disorder transitions, such as in magnetic systems or in absorbed monolayers, etc, for a review see in [1]. In two-dimensional regular lattices and with homogeneous couplings there are some models (Ising model, critical Potts model, eightvertex model, etc.) with an asymptotically exact solution for the partition function in the thermodynamic limit [2]. In the presence of quenched, that is time independent, disorder this type of exact solutions are scarce which has greatly hampered our understanding about collective phenomena in disordered systems, for example about the properties of spin glasses.
For disordered systems, such as for spin models with random couplings and/or fields one usually performs an exact computation on finite lattices and the results are then extrapolated. An important limitation of this finite lattice method is the available sizes, which can be treated by different computational methods. For most of the discrete spin models a computation of the ground state represents a hard optimization problem when there is frustration and it is even much more complex to compute the partition function.
In this respect the Ising model, which is equivalent to the Potts model with q = 2 states, is an exceptional problem since the ground (minimum energy) states can be found in polynomial time using the solution of max cut problems in planar graphs that involves matching theory [3] [4] [5]. The full partition function of the Ising problem can also be computed for lattices of bounded genus [6]. Another example of application of optimization theory to lattice statistical mechanics is the Random Field Ising Model where the ground state can be found in polynomial time in any dimension [7] [8]. A discussion about optimal cuts in statistical mechanics can be found in [9] and a general review about the application of combinatorial optimization methods in statistical physics can be found in [10].
For the q = 3-state Potts model, when the number of states is three, the computation of the minimum energy of the system involves (NP-)hard combinatorial problems such as minimizing the 3-cut in a graph, and no efficient procedure is known for computing the partition function.
If the number of states can be arbitrary large (and given as part of the input) the partition function has an exponential number of terms, and the problem may look hopeless. In this paper we show that this is not the case: when the number of states tends to infinity, the partition function can be determined up to an integer multiplicative factor, and some average properties of the system can be inferred. This evaluation goes trough the minimization of a submodular function. Note that in [11] a simulated annealing method and an approximate combinatorial method have been used. The solution we give here is both exact and much more efficient.
Even though there are ready-made algorithms for general submodular function minimization [12] [13] [14] [15], the resources they require are far beyond the possibilities of the present application. While the existing first implementations of general submodular function minimization may require too much time already to solve the optimization problem on a lattice containing a dozen of sites (vertices of the input graph corresponding to the variables of the general problem), we want and will solve problems involving more than two hundred thousand 'sites'. For this we use methods inspired by [16] [17] [18] [19] that fit the particularity of the application and develop an algorithm which is tailored to graphic submodular functions. Besides the computational advantages of this approach, we are also aiming at conceptual simplicity and elegance. Readers who seek for more mathematical background and connections can consulte [20].
In Section 1 we describe the problem of physics and show how it reduces to a function maximization. In Section 2 we formulate the mathematical problem, the preliminaries and the broader context of our algorithm; in Section 3 and 4 we show how to construct an optimal solution and in Section 5 we state the algorithm. Finally, in Section 6 we analyze the practical implementation of the method and display a few computational results. The paper is self-contained, the algorithms and their correctness will be fully proved.
1 The problem in terms of physics.
For a review of the huge amount of work devoted to the Potts model see [21]. In this section we recall the Potts model and show why its partition function (up to an integer multiplicative factor) is determined, if the number of 'states' tends to infinity by the minimum value of a submodular function.
A lattice of spins is given at each site of which is a variable. We denote the number of sites by n. Each variable σ 1 , . . . , σ n can take values in {0, 1 . . . , q − 1} for a given integer q. Pairs of neighboring sites on the lattice are called bonds, the number of bonds by m.
Each configuration σ = (σ 1 , . . . , σ n ) has an energy where σ i ∈ {0, . . . , q − 1} the sum runs over all bonds ij, K ij ∈ IR + is a given non-negative weight of bond ij, and δ ab is the Kronecker symbol (1 if a = b and 0 otherwise). For mathematicians: a lattice is a graph, sites are vertices, bonds are edges. The aim is to compute or approximate the partition function where the summation runs over all assignments of values σ = (σ 1 , . . . , σ n ), and the product over all bonds ij (the inverse temperature has been included in the couplings K ij ). We follow [11]. Note that e Kδ = 1 + (e K − 1)δ for δ ∈ {0, 1} ; introduce ν ij = e K ij − 1 and expand the product of sums: where the summation runs over all subsets of bonds F . Substituting this to (2) we get: where the sum runs over all subsets F of bonds, and where c(F ) is the number of connected components of F on the set of all sites, counting also the isolated sites among the components. (By convention if F is empty then ij∈F ν ij = 1.) We got the last equality by counting the number of different σ = (σ 1 , . . . , σ n ) for which the product is nonzero; since it is nonzero if and only if σ(i) = σ(j) for every ij ∈ F , that is, if and only if σ is constant on every connected component of F , all possible σ can be enumerated by choosing an element of Z q for every connected component of F independently. Therefore we have exactly q c(F ) such σ.
Note that this sum has 2 m terms, and that in (3) q does not need to have an integer value. (This provides a way of defining Potts' model for non-integer values [22].) Clearly, K ij ≥ 0 is equivalent to ν ij ≥ 0, and we can introduce a new set of variables α ij with ν ij = q α ij , and the partition function becomes Finally one introduces the function As pointed out in ref [11], while q tends to infinity the sum in (6) is ..,n} f (F ) and N is the number of optimal sets. Note that if the weights w ij are arbitrary reals, the degeneracy N is likely to be 1.
We will analyze the combinatorial optimization problem of finding this maximum. The problem of finding the degeneracy of the optimal set will not be addressed. In the analysis of the Potts model magnetic properties are related to geometrical properties of the optimal sets A, and specifically to their fractal dimension (if any). We assume that, on average and for large enough lattice, this fractal dimension is the same for all sets, and therefore finding a single optimal set is sufficient for our purpose. We will present methods which apply to any set of weights {α ij } in an arbitrary lattice (graph) and provide a simply stated and efficient algorithm.

The problem in terms of graphs.
For basic graph theoretic notions, terminology and notation we refer to [23]. Given a graph G = (V, E) on n vertices with weight function w : E(G) −→ IR, we want to solve the following problem: where c G (A) is the number of connected components of the graph G(A) = (V, A). Note a slight change of notation with Eq. 5 where an edge is denoted by ij the two corresponding adjacent vertices. We can suppose 0 < w(e) < 1 for all e ∈ E(G), because if w(e) = 0, then deleting the edge, if w(e) ≥ 1, then contracting it (identifying its two endpoints) we get an equivalent problem. When no confusion is possible we will simply use f or f G for f G,w , c for c G . This function that has to be maximized in order to solve (POTTS) has a crucial and well-known property (see for instance [23], Exercise 6.2). For any two subsets A and B of edges of G : By now several polynomial algorithms [12] [13] [14] [15] are known to minimize a submodular function, therefore we can already claim that there exists a polynomial algorithm solving our problem (POTTS). However, these general algorithms are not efficient enough for our instances. Fortunately, the specific properties of our problem make possible the use of a considerably simpler and quicker algorithm. Several more specialized algorithms were already known (see [20] for an extended presentation) and in particular Cunningham [17] worked out a specialized algorithm to the "optimal attack problem" :"The weight of an edge represents the effort required by an attacker to destroy the edge, and the attacker derives a benefit for each new component created by destroying edges . . .". (POTTS) is equivalent to the "optimal attack problem" but with a 'complementary' viewpoint : the weight of an edge represents the benefits of cooperation between two vertices (say, researchers), furthermore there is a unit support for each component (say, for each research project). So there is a loss of support when two components unite. Cooperate optimally!
The algorithm described below has its roots in [17] and is similar to [18], [19]. It has the best asymptotic worst case complexity, the same as [19], and is probably the simplest, both conceptually and in the use of computational resources of the implementation. Sophisticated ingredients were necessary for finding this solution, but we don't need to make explicit use of them. The interested reader may find more details on that subject in [20].
We return now to the (POTTS) problem. An important observation is the following: if A is a set of edges, and X is the vertex set of a connected component of G(A), then adding to A edges induced by X, that is with both endpoints in X, increases the value of f . Thus in an optimal solution A * of (POTTS) each connected component of A * contains all the edges of G it induces. Let us call Potts partition any partition of the vertices such that each class induces a connected subgraph of G.
All we have to determine is : a Potts partition maximizing the total weight of edges induced by the classes plus the number of classes.
As a consequence, following [19], during all the procedure it will be sufficient to consider subsets of vertices instead of subsets of edges.
A set F of edges optimizing (POTTS) will be called optimal, its associated Potts partition P G (F ) = {X 1 , . . . X k } will be called optimal as well. For any subset F of edges let w(F ) = e∈F w(e) and for any subset X of vertices let w(X) = e∈E(X) w(e) where E(X) is the set of edges with both extremities in X.

Extension of a solution
In this section we will see how any set of edges maximizing (POTTS) for a graph G minus a vertex, may be completed so that it maximizes (POTTS) for the graph G itself.
Let G be a graph with a weight function w on the edges, let x be a vertex of G and let G ′ be the subgraph of G obtained by deleting x. The edges of G ′ keep their weight. Let F ′ ⊆ E(G ′ ) be an optimal solution of (POTTS) for G ′ .
The following Lemma is an easy consequence of the (SUPER) property.
Lemma 1 There exists an optimal solution of (POTTS) for G which contains all edges of F ′ .
Proof: Let F be any optimal solution of (POTTS) for G. By the (SU-PER) property one has in G: Both F ′ and F ∩ F ′ are subsets of edges of G ′ and since F ′ is optimal in Since F is optimal in G by hypothesis, we get that F ∪ F ′ is optimal too, and the Lemma is proved. ✷ As a consequence of Lemma 1 we can obtain an optimal solution F * for G by adding edges to F ′ . Let X 1 , . . . , X k be the vertices of the connected components of G ′ (F ′ ), then P G (F ′ ) = {X 1 , . . . , X k , {x}}. Each connected component in G(F * ) will be either an element of P G (F ′ ) or the union of at least two elements of P G (F ′ ). The next Lemma shows how the value of a Potts partition is affected when a subset of connected components are put together.
Lemma 2 Let P and P ′ be two Potts partitions of G such that P = (P ′ \ W) ∪ {∪X i ; X i ∈ W} for some W ⊆ P. Then where E(W) denotes the set of edges of G joining vertices belonging to two different sets in W.
Proof: Replacing in P the sets of W by their union decreases the cardinality of P by |W| − 1, on the other hand let A and A ′ be the sets of edges induced by the classes respectively of P and P ′ , A = A ′ ∪ E(W) and so the weight of the edges augment by w(E(W)). The equality is then proved and the rest follows directly. ✷ We are now ready to prove the following theorem: Theorem 1 For any W ⊆ P G (F ′ ) containing {x} and minimizing |W| − 1 − w(E(W)), the set F * = F ′ ∪ E(W) is optimal for (POTTS) in G.
Proof: By Lemma 1 we know that there exists an optimal solution F * of (POTTS) for G which contains F ′ . Let W ⊆ P G (F ′ ) such that W = ∪ X i ∈W X i is an element of P G (F * ). If W doesn't contain {x} then, since F ′ is optimal in G ′ , we get by Lemma 2 that |W| − 1 − w(E(W)) ≥ 0 (this value is the same in G and G ′ ). On the other hand F * is optimal in G which implies that |W| − 1 − w(E(W)) = 0, but then F * \ E(W) is also optimal for G. Hence there exists an optimal solution F * of (POTTS) for G containing F ′ and such that any element of P G (F * ) not containing x is already in P G (F ′ ).
So any W ⊆ P G (F ′ ) containing {x}, such that W = ∪ X i ∈W X i induces a connected subgraph of G, and minimizing under these conditions |W| − 1 − w(E(W)), will provide an optimal solution F ′ ∪ E(W). (Notice that this minimum is ≤ 0 since for W = {{x}} we get 0.) In order to prove the theorem it remains only to show that we may skip the connectivity constraint : we show now that any subset W ⊆ P G (F ′ ), {x} ∈ W, minimizing |W| − 1 − w(E(W)) corresponds to a connected subgraph in G. Assume not, and let W 1 , . . . , W l (l ≥ 2) be the subsets of P G (F ′ ) corresponding to the vertices of the connected components induced by W = ∪ X i ∈W X i in G, W 1 being the one containing {x}. We have For i ≥ 2, {x} / ∈ W i and so as already noticed |W i | − w(E(W i )) ≥ 1, which implies |W| − 1 − w(E(W)) > |W 1 | − 1 − w(E(W 1 )) and so we get a contradiction to our assumption on W. ✷ At this point we see that any way to find W will provide a constructive algorithm for getting an optimal solution of (POTTS) : we start with a solution for a small subgraph (for example a one vertex subgraph) and then add the vertices one by one, computing at each step a new extended solution. Fortunately an optimal W can be computed and in the next section we are going to show how.
We remark that the value |W| − 1 − w(E(W)) doesn't depend on the subgraphs induced by the subsets X i in W, so we may ignore these and work in a possibly smaller graph. To be precise : the result of shrinking the pairwise disjoint sets X 1 , . . . , X k of P G (F ′ ) in G is the graph shr(G) = (shr(V ), shr(E)), where shr(V ) = {x, x 1 , . . . , x k } where x 1 , . . . , x k are distinct new vertices, and the function shr : V −→ {x, x 1 , . . . , x k } is defined with shr(v) := x i if v ∈ X i and shr(x) := x; the image of an edge e with extremities x and y is shr(e) with extremities shr(x)shr(y), moreover, if this is a loop (shr(x) = shr(y)), it is deleted; edges keep their weight, that is w shr (shr(e)) = w(e); sets of vertices or of edges are replaced by the image sets. There is a one to one correspondence between the subsets W of P G (F ′ ) containing {x} and subsets W of vertices of shr(G) containing x and for any such W = shr(W) one has |W| − 1 − w(E(W)) = |W | − 1 − w shr (W ) (as defined in the preceding chapter w shr (W ) is the sum of weights of the edges in the subgraph of shr(G) induced by W ). So W will be optimal if and only W = shr(W) minimizes |W | − 1 − w shr (W ).

A network flow model
Given a graph H with weight function w on the edges and W ⊆ V (H), let b(W ) = |W | − 1 − w(W ). From the previous chapter it is clear that any way of solving the following problem will provide an algorithm solving (POTTS) : given a vertex x in H, find W * a subset of vertices of H containing x such that b(W * ) = min(b(W ); W ⊂ V (H), x ∈ W ). This problem is solved both in Picard-Queyranne [24] and Padberg-Wolsey [25], using a network flow model that will be described below. (The work [24], [25] solve much more complex problems involving several network flow computations -the subroutine below is the adaptation of an auxiliary procedure.) We first give some definitions and wellknown facts. Given a directed graph and a subset X of its vertices, δ(X) will denote the set of arcs leaving X, and is called a cut; if s ∈ X, t / ∈ X it is an (s, t)-cut; δ(X, Y ) denotes the set of arcs oriented from X to Y . A function c with nonnegative value on the arcs is called a capacity function. If F is a set of arcs then c(F ) := e∈F c(e). A network is a directed graph with capacity function. By a well known theorem of Ford and Fulkerson [26] a minimum (s, t)-cut in a network may be found by computing a maximum flow in this network. Very efficient maximum flow algorithms are known [27].
We now describe in several steps a network (D, c) = N(H, w) that will be associated to H and w: where K := c(δ(s)) = (s,x)∈A c(s, x).
Indeed, let us see how the capacity of the cuts changes if we start with the set {s} inducing an (s, t)-cut of capacity c(δ(s)) = K and then 'add' to it the vertices of W one by one: The contribution of adding v to the side of s is 1 − p(v), for either it decreases from p(v) − 1 to 0 (this happens if p(v) > 1 see the first case of '2.' in the construction of N(H, w)), or it increases from 0 to 1 − p(v). Thus the contribution of these arcs is: On the other hand the contribution of the arcs between W and V (H) \ W is clear: at the beginning it is zero, and at the end it is: The change comparing to K is provided by the sum of the two contributions, which is |W | − w(W ), and so equation (CUT) has been proved.
From (CUT) we get that any (s, t)-cut C = {s}∪W containing the special vertex x and of minimum capacity will correspond to our goal : a subset W of vertices of H containing x and minimizing b. Such a cut is easy to obtain : shrink {s, x} or equivalently, add to N(H, w) an arc of infinite capacity from s to x, and compute in the new network a minimum (s, t)-cut : this cut will contain x and will be minimum among (s, t)-cuts containing x.
Let us note that this method can be easily generalized to minimize any modular shift of −w(W ). Adding |W | − 1 is just a particular choice of a modular function. That is, one can minimize ( w∈W m(w)) − w(W ), where m : V −→ IR. Indeed, for generalizing from |W | to m(W ) one only has to write m(x) instead of 1 in both cases of Step 2 in the construction of N(H,w).

The Algorithm
In this section we state the 'Optimal Cooperation Algorithm' whose validity is a consequence of the results of the two preceding chapters.
At each iteration a subset U ⊆ V and a partition P of U will be at hand. In Step 0 we give trivial initial values; in Step 1, we choose an arbitrary vertex u to be added to U and through the following steps we compute a subset W of P ∪ {u} providing a partition of U ∪ {u} consisting of the sets contained in P but not in W plus a new class containing all the other vertices (that is : the new class is the union of all sets in W). The set of edges corresponding to this new partition is the union of the set of edges corresponding to the previous one and the edges between the sets in W. 3. Construct N(H, w H ), add an arc of "infinite" capacity from s to u and using any maximum flow algorithm compute, in the so obtained network, a minimum (s, t)-cut defined by the set of vertices C = {s, u, x 1 , . . . , x k } where each x i is a vertex of H corresponding to a set X i ∈ P. Remarks:

OPTIMAL COOPERATION ALGORITHM
-"Infinite" means big enough to avoid a minimum cut containing this arc: for example the sum of the capacities of all arcs.
-Note that C can be equal to {s, u}.
-The graphs H can also be constructed iteratively with only one shrinking in each iteration, by adding u and then shrinking the set C \ {s}.
-The choice for u is completely free; this freedom could be used for making the computations easy.
Theorem 2 The output P * is an optimal partition for (G, w).
Proof: At step 0, P := ∅ is an optimal solution for the subgraph of G induced by U := ∅. Assume now that P is an optimal solution for the subgraph of G induced by U, and show that after applying steps 1 to 5 the new partition is optimal for U ∪ {u}. From the preceding chapter we know that W := C \ {t} = {u, x 1 , . . . , x k } is a subset of vertices of H containing u minimizing |W | − w H (W ) − 1. But H and w H are obtained by shrinking the classes of P in (G(U ∪ {u}), w), hence W = {u, X 1 , . . . , X k } is a subset of {u} ∪ P minimizing |W| − 1 − w(E(W)) and by Theorem 1 the partition (P \ {X 1 , . . . , X k }) ∪ {R} is then optimal ✷ Notice that the "Optimal Cooperation algorithm" consists merely of n−1 network flow computations and n − 1 shrinking.

Implementation and evaluation
In this section we discuss some aspects of the practical implementation of the optimal cooperation algorithm. Here we consider a two dimensional square lattice where the weights, w, follow a bimodal distribution: where δ(x) = 1 if x = 0 and δ(x) = 0 otherwise. We restrict ourself to the symmetric case p = 1/2. As explained in [11] in the infinite lattice limit there is a second-order phase transition in the model at w 1 + w 2 = 1. In the strongly disordered phase, w 1 + w 2 ≪ 1 the optimal set of edge is A = ∅, while in the strongly ordered phase, w 1 + w 2 ≫ 1 it is A = E. In between, the optimal set A has a non-trivial structure and at the transition point it is a fractal reflecting the critical properties of the system [11].
As explained in the previous section, for a graph with n vertices the algorithm consists in n − 1 steps. At each step a new site is incorporated to the current graph for which the optimization has already been performed. There is a freedom of the order of the added sites, which can be used to speed up the computation, as well as to obtain the optimal sets of intermediary lattices. For example from the computation of the optimal set for an L × L square lattice with free boundary conditions one can also obtain the optimal sets of L − 1 minors of size ranging from 1 to L − 1 with free boundary conditions, which is useful for finite size analysis.
The "engine" of the algorithm is the max flow solver, which is called at each step. We have used the Goldberg and Tarjan algorithm [28]. Another important point concerns the building of the network (point 3 in the Optimal Cooperation Algorithm). It is possible to build it explicitly as another data structure than the lattice. Alternatively one can increase up to a sufficiently large value all the capacities of the edges of a spanning tree of each connected component as mentioned in the previous paragraph. In general the cpu time required to explicitly shrink the connected components is larger than the cpu time needed to simply increase some capacities. On the other hand, keeping all vertices will increase the size of the network in which the max flow has to be found. If all the capacities are large (w 1 + w 2 > 1, that is we are in the ordered phase) the network will have only two sites at each step, and therefore the effort to build the network will be largely compensated by the speed at which the maximum flow is found. In the opposite extreme, when the optimal set tends to be empty, it is questionable which of the two strategies is the best. We have found that explicitly shrinking the connected components is always the most efficient. As a matter of fact the computation time is about L time 16 ∼ one second 32 ∼ half a minute 64 ∼ five minutes 128 ∼one hour and a half 256 ∼ one day 512 ∼ two weeks ten times larger at the critical point w 1 + w 2 = 1 than at the ordered phase (w 1 + w 2 > 1) and about three times larger than at the disordered phase (w 1 + w 2 < 1).
As an illustration we display in the table below some typical cpu times needed to find an optimal set on a periodic square lattice of various size, L, at the critical point w 1 + w 2 = 1. From these results one can extract the empirical rule that in our algorithm the computation time grows approximately as the fourth power of the linear size L, thus as the second power of the number of sites. These cpu times refer to a PC with a pentium III, 800 megahertz processor.
In conclusion in this paper we have presented and implemented a combinatorial optimization algorithm which solves the optimal cooperation problem in polynomial time. The procedure, which can be used to obtain the partition function of the q-state random bond Potts model in the large qlimit is, up to our knowledge, the first application of submodular function optimization in (statistical) physics. Detailed results about the q-state random bond Potts model, such as properties of phase transitions in two-and three-dimensional lattices will be presented in a separate publication [29].