{'fraction_non_alphanumeric': 0.06139435560193162, 'fraction_numerical': 0.014195928073964425, 'mean_word_length': 3.633981783425166, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Modularity of complex networks models

Modularity is designed to measure the strength of division of a network into clusters (known also as communities). Networks with high modularity have dense connections between the vertices within clusters but sparse connections between vertices of different clusters. As a result, modularity is often used in optimization methods for detecting community structure in networks, and so it is an important graph parameter from a practical point of view. Unfortunately, many existing non-spatial models of complex networks do not generate graphs with high modularity; on the other hand, spatial models naturally create clusters. We investigate this phenomenon by considering a few examples from both sub-classes. We prove precise theoretical results for the classical model of random d-regular graphs as well as the preferential attachment model, and contrast these results with the ones for the spatial preferential attachment (SPA) model that is a model for complex networks in which vertices are embedded in a metric space, and each vertex has a sphere of influence whose size increases if the vertex gains an in-link, and otherwise decreases with time. The results obtained in this paper can be used for developing statistical tests for models selection and to measure statistical significance of clusters observed in complex networks.


Introduction
Many social, biological, and information systems can be represented by networks, whose vertices are items and links are relations between these items [2,7,9,16]. That is why the evolution of complex networks attracted a lot of attention in recent years and there has been a great deal of interest in modelling of these networks [12,20,42]. The hyperlinked structure of the Web, citation patterns, friendship relationships, infectious disease spread are seemingly disparate linked data sets which have fundamentally very similar natures. Indeed, it turns out that many real-world networks have some typical properties: heavy tailed degree distribution, small diameter, high clustering coefficient, and others [39,41,47]. Such properties are well-studied both in real-world networks and in many theoretical models.
Another important property of complex networks is their community structure, that is, the organization of vertices in clusters, with many edges joining vertices of the same cluster and comparatively few edges joining vertices of different clusters [24,28]. In social networks communities may represent groups by interest, in citation networks they correspond to related papers, in the Web communities are formed by pages on related topics, etc. Being able to identify communities in a network could help us to exploit this network more effectively. For example, clusters in citation graphs may help to find similar scientific papers, discovering users with similar interests is important for targeted advertisement, clustering can also be used for network compression and visualization.
The key ingredient for many clustering algorithms is modularity, which is at the same time a global criterion to define communities, a quality function of community detection algorithms, and a way to measure the presence of community structure in a network. Modularity was introduced by Newman and Girvan [43] and it is based on the comparison between the actual density of edges inside a community and the density one would expect to have if the vertices of the graph were attached at random, regardless of community structure.
Unfortunately, modularity is not a well studied parameter for the existing random graph models, at least from a rigorous, theoretical point of view. We are only aware about results for binomial random graphs G(n, p) and random d-regular graphs (see Section 2.3 for more details). In this paper, we continue investigating random d-regular graphs and obtain new upper bounds for their modularity. Then we move to the preferential attachment model, introduced by Barabási and Albert [8], which is probably the most well-studied model of complex networks. For this model no results on modularity are known and we obtain both lower and upper bounds. In fact, one of the lower bound we present holds for all graphs with average degree d and sublinear maximum degree.
As expected, the models discussed above, as well as many others, have a common weakness of low modularity. One family of models which overcomes this deficiency is the family of spatial (or geometric) models, wherein the vertices are embedded in a metric space such that similar vertices are closer to each other than dissimilar ones. The underlying geometry of spatial models naturally leads to the emergence of clusters. We prove this statement rigorously for one example of a geometric model, the Spatial Preferential Attachment model introduced in [1]. This paper is a journal version of [44] and is structured as follows. In the next section, we formally define modularity, discuss several random graph models and present known results on modularity in these models. In Sections 3, 5 and 6 we analyze modularity in random d-regular graphs, preferential attachment and SPA models, respectively. In Section 4 we discuss lower bounds for modularity of forests and constant average degree graphs. Section 7 concludes the paper and outlines the directions for future research.

Modularity
The definition of modularity was first introduced by Newman and Girvan in [43]. Since then, many popular and applied algorithms used to find clusters in large data-sets are based on finding partitions with high modularity [18,34,40]. The modularity function favours partitions in which a large proportion of the edges fall entirely within the parts and biases against having too few or too unequally sized parts. Formally, for a given partition where e(A) = |{uv ∈ E(G) : u, v ∈ A}| is the number of edges in the graph induced by the set A. The first term, A∈A e(A) |E(G)| , is called the edge contribution, whereas the second one, , is called the degree tax. It is easy to see that q A is always smaller than one. Also, if A = {V (G)}, then q A = 0.
The modularity q * (G) is defined as the maximum of q A over all possible partitions A of V (G); that is, In order to maximize q A (G) one wants to find a partition with large edge contribution subject to small degree tax. If q * (G) approaches 1 (which is the maximum), we observe a strong community structure; conversely, if q * (G) is close to zero, we are given a graph with no community structure.
Modularity is known to have some weaknesses, as discussed in [24]. For example, [25] shows that this measure fails to detect communities if their sizes are too small. However, despite this, modularity still remains to be the most popular measure used by many well known clustering algorithms [18,34,40].

Random graph models
Random d-regular graphs. We consider the probability space of random d-regular graphs with uniform probability distribution. This space is denoted G n,d , and asymptotics are for n → ∞ with d ≥ 2 fixed, and n even if d is odd.
We say that an event in a probability space holds asymptotically almost surely (or a.a.s.) if the probability that it holds tends to 1 as n goes to infinity. Since we aim for results that hold a.a.s., we will always assume that n is large enough.
Preferential Attachment. The Preferential Attachment (PA) model [8] was an early stochastic model of complex networks. We will use the following precise definition of the model, as considered by Bollobás and Riordan in [13] as well as Bollobás, Riordan, Spencer, and Tusnády [14].
Let G 0 1 be the null graph with no vertices (or let G 1 1 be the graph with one vertex, v 1 , and one loop). The random graph process (G t 1 ) t≥0 is defined inductively as follows. Given G t−1 1 , we form G t 1 by adding a vertex v t together with a single edge between v t and v i , where i is selected randomly with the following probability distribution: where deg(v s , t − 1) denotes the degree of v s in G t−1 1 (loops are counted twice). In other words, at t-th step of the process we send an edge e from v t to a random vertex v i , where the probability that a vertex is chosen is proportional to its current degree, counting e as already contributing one to the degree of v t .
For m ∈ N \ {1}, the process (G t m ) t≥0 is defined similarly with the only difference that m edges are added to G t−1 m to form G t m (one at a time), counting previous edges as already contributing to the degree distribution. Equivalently, one can define the process (G t m ) t≥0 by considering the process to form v 2 , and so on. Note that in this model G t m is in general a multigraph, possibly with multiple edges between two vertices (if m ≥ 2) and self-loops.
It was shown in [14] that for any m ∈ N a.a.s. the degree distribution of G n m follows a power law: the number of vertices with degree at least k falls off as (1 + o(1))ck −2 n for some explicit constant c = c(m) and large k ≤ n 1/15 . Also, in the case m = 1, each vertex sends an edge either to itself or to an earlier vertex, so G n 1 is a forest with each component containing a single looped vertex. The expected number of components is then n t=1 1/(2t − 1) ∼ (1/2) log n and, since events are independent, we derive that a.a.s. there are (1/2 + o(1)) log n components in G n 1 by Chernoff's bound. In contrast, for the case m ≥ 2 it is known that a.a.s. G n m is connected and its diameter is (1 + o(1)) log n/ log log n [13].
Spatial Preferential Attachment. The Spatial Preferential Attachment (SPA) model [1], designed as a model for the World Wide Web, combines geometry and preferential attachment, as its name suggests. Setting the SPA model apart is the incorporation of 'spheres of influence' to accomplish preferential attachment: the greater the degree of a vertex, the larger its sphere of influence, and hence the higher the likelihood of the vertex gaining more neighbours.
We now give a precise description of the SPA model. Let S = [0, 1] m be the unit hypercube in R m , equipped with the torus metric derived from any of the L p norms. This means that for any two points x and y in S, The torus metric thus 'wraps around' the boundaries of the unit square; this metric was chosen to eliminate boundary effects. The parameters of the model consist of the link probability p ∈ [0, 1], and two positive constants A 1 and A 2 , which, in order to avoid the resulting graph becoming too dense, must be chosen so that pA 1 < 1. The SPA model generates stochastic sequences of directed graphs (G t : t ≥ 0), where G t = (V t , E t ), and V t ⊆ S. Let deg − (v, t) be the in-degree of the vertex v in G t , and deg + (v, t) its out-degree. We define the sphere of influence S(v, t) of the vertex v at time t ≥ 1 to be the ball centered at v with volume |S(v, t)| defined as follows: The process begins at t = 0, with G 0 being the null graph. Time step t, t ≥ 1, is defined to be the transition between G t−1 and G t . At the beginning of each time step t, a new vertex v t is chosen uniformly at random from S, and added to V t−1 to create V t . Next, independently, for each vertex u ∈ V t−1 such that v t ∈ S(u, t − 1), a directed link (v t , u) is created with probability p. Thus, the probability that a link (v t , u) is added in time-step t equals p |S(u, t − 1)|.
The SPA model produces scale-free networks, which exhibit many of the characteristics of reallife networks (see [1,19]). In [31], it was shown that the SPA model gave the best fit, in terms of graph structure, for a series of social networks derived from Facebook. In [32], some properties of common neighbors were used to explore the underlying geometry of the SPA model and quantify vertex similarity based on distance in the space. However, the distribution of vertices in space was assumed to be uniform [32] and so in [33] non-uniform distributions were investigated which is clearly a more realistic setting.

Previous results on modularity
In this section we discuss known bounds for modularity in different random graph models.
The isoperimetric number (known also as edge expansion) of a graph G is defined as where e(V 1 , V 2 ) = |{uv ∈ E(G) : u ∈ V 1 , v ∈ V 2 }| is the number of edges between the sets V 1 and V 2 .
The following result was shown by McDiarmid and Skerman in [35]. Let G be any d-regular graph on n vertices. Then, the following useful upper bound on the modularity is almost immediate: Turning to random d-regular graphs, Bollobás in [11] showed that a.a.s.
As a result, we get the first non-trivial upper bounds for q * (G n,d ) presented in Table 1 that hold a.a.s.
In [35], the bound (3) was slightly improved when the maximum size of parts in our partition is restricted. Formally, given δ > 0, for a graph G with n ≥ 1/δ vertices, they define q δ (G) to be the maximum modularity of all partitions for G such that each part has size at most δn. They show that for any ε > 0 there exists δ > 0 such any d-regular graph with at least 1/δ vertices satisfies Again, using the result of Bollobás we get that there exists δ > 0 such that serves as an upper bound that holds a.a.s. for q δ (G n,d ); again, see Table 1 for numerical values for small values of d. It is straightforward to see that (G) ≥ d/2− (log 2)d (see, for example, [11]) and so, in particular, U 2 can be made arbitrarily small by taking d large enough (and δ small enough). However, let us note that these upper bounds for q δ (G n,d ), while useful, cannot be directly translated into any bound for q * (G n,d ).
Investigating random d-regular graphs continues in [36], a very recent paper. In fact, the numerical upper bound presented in Section 3.3, as well as the result in Theorem 4, are obtained independently there. Moreover, [36] investigates the class of graphs whose product of treewidth and maximum degree is much less than the number of edges. Their result shows, for example, that random planar graphs typically have modularity close to 1, which is another indication that clusters naturally emerge where geometry is included. Also, a particular case of their theorem shows that trees with maximum degree o(n) have asymptotic modularity one.
3 Random d-regular graphs

Pairing model
Instead of working directly in the uniform probability space of random regular graphs on n vertices G n,d , we use the pairing model (also known as the configuration model) of random regular graphs, first introduced by Bollobás [10], which is described next. Suppose that dn is even, as in the case of random regular graphs, and consider dn points partitioned into n labelled buckets v 1 , v 2 , . . . , v n of d points each. A pairing of these points is a perfect matching into dn/2 pairs. Given a pairing P , we may construct a multigraph G(P ), with loops allowed, as follows: the vertices are the buckets v 1 , v 2 , . . . , v n , and a pair {x, y} in P corresponds to an edge v i v j in G(P ) if x and y are contained in the buckets v i and v j , respectively. It is an easy fact that the probability of a random pairing corresponding to a given simple graph G is independent of the graph, hence the restriction of the probability space of random pairings to simple graphs is precisely G n,d . Moreover, it is well known that a random pairing generates a simple graph with probability asymptotic to e −(d 2 −1)/4 depending on d, so that any event holding a.a.s. over the probability space of random pairings also holds a.a.s. over the corresponding space G n,d . For this reason, asymptotic results over random pairings suffice for our purposes. For more information on this model, see, for example, the survey of Wormald [48].

Lower bound
For completeness, let us briefly discuss the following known lower bound for the modularity of G n,d . It is known that a.a.s. for any d ∈ N \ {1, 2}, G n,d is Hamiltonian. As pointed out in [35], one can use this fact to partition the graph such that it breaks the cycle into ⌈ √ n⌉ paths of length at most ⌈ √ n⌉. For this particular partition the edge contribution is 2/d − O(1/ √ n) and the degree tax is It follows then that a.a.s.
(Our more general lower bound that holds for graphs with average degree d implies the same-see Theorem 6 for more.) Whereas this trivial lower bound could be sharp for d = 3 it is definitely not the case for large d. As pointed out in [36], there exists a universal constant c > 0 such that a.a.s.

Numerical upper bound
The following straightforward lemma is useful for obtaining upper bounds for modularity of random d-regular graphs.
Proof. For a given partition that is, set A i has x i n vertices and induces y i x i n/2 edges. Then, taking into account the fact that for any A ⊆ V (G) we have v∈A deg(v) = d|A|, we can rewrite (1) as As it is simply a weighted average, q A ≥ U would imply that there exists some set of size xn that induces yxn/2 edges, and y/d − x ≥ U . So, the proof of the lemma is finished.
To formulate the main theorem of this section, we need the following notation. For a given It will be clear once we establish the connection between function f and random d-regular graphs, but it is straightforward to see that for any x ∈ (0, 1) we have f (x, d, d) < 0 (more precisely, its limit value) and f (x, y, d) > 0 for some y ∈ (0, d).
As usual, see Table 1 for numerical values for small values of d. Proof. We prove below that the following property holds a.a.s. for G n,d . No set A of size xn (for any x = x(n) ∈ (0, 1)) induces a graph with yxn/2 edges, whereȳ(x, d) + ε ≤ y ≤ d andȳ(x, d) is defined as above. Then Theorem 2 follows directly from Lemma 1.
Consider G n,d for some d ∈ N \ {1, 2} and let ε > 0 be an arbitrarily small constant. Our goal is to show that the expected number of sets S such that |S| = xn and e(S) = yxn/2 with y ≥ȳ(x, d) + ε is o(n −2 ). (For simplicity, we do not round numbers that are supposed to be integers either up or down; this is justified since these rounding errors are negligible to the asymptomatic calculations we will make.) This, together with the first moment principle, implies that a.a.s. no such set exists for any x ∈ (0, 1) and y ∈ [ȳ(x, d) + ε, d] (as there are O(n) possible sizes of S and O(n) possible values of e(S) that we need to consider). Let x = x(n) and y = y(n) be any functions of n such that 0 < x < 1 andȳ(x, d) + ε < y < d. Let X(x, y) be the expected number of sets S such that |S| = xn and e(S) = yxn/2. Using the pairing model, it is clear that where M (i) is the number of pairings of i vertices, that is, (Each time we deal with pairings, i is assumed to be an even number.) After simplification we get Using Stirling's formula (i! ∼ √ 2πi(i/e) i ) and focusing on the exponential part we obtain where f (x, y, d) is defined in (5). It follows immediately from the definition ofȳ(x, d) that f (x, y, d) < 0 is bounded away from zero for any pairs of integers xn and yxn/2 under consideration, and so for any pair we get X(x, y) = o(n −2 ) and the proof is finished.

Explicit but weaker upper bound
Theorem 2 provides an upper bound that can be easily numerically computed for a given d ∈ N \ {1, 2}. Next, we present a slightly weaker but an explicit bound that can be obtained using the expansion properties of random d-regular graphs that follow from their eigenvalues. In particular, it will imply that a.a.s.
The adjacency matrix A = A(G) of a given d-regular graph G with n vertices, is an n × n real and symmetric matrix. Thus, the matrix A has n real eigenvalues which we denote by λ 1 ≥ λ 2 ≥ · · · ≥ λ n . It is known that certain properties of a d-regular graph are reflected in its spectrum but, since we focus on expansion properties, we are particularly interested in the following quantity: λ = λ(G) = max(|λ 2 |, |λ n |). In words, λ is the largest absolute value of an eigenvalue other than λ 1 = d (for more details, see the general survey [29] about expanders, or [6], Chapter 9).
The value of λ for random d-regular graphs has been studied extensively. A major result due to Friedman [26] is the following:
We prove the following theorem.
Theorem 4 Let d ∈ N \ {1, 2}. Then, for any d-regular graph G n,d we have In particular, for random d-regular graphs a.a.s.
Proof. The second part of the theorem follows from Lemma 3, as for a random d-regular graphs a.a.s.
√ d for sufficiently small ε > 0. Let us now show that q * (G n,d ) ≤ λ d . The number of edges |E(S, T )| between sets S and T is expected to be close to the expected number of edges between S and T in a random graph of edge density d/n, namely d|S||T |/n. A small λ (or large spectral gap) implies that this deviation is small. Namely, for our purpose here we will use the following lower estimate for |E(S, V \ S)| for all S ⊆ V . This is proved in [5], see also [6]. Using this inequality we get immediately that for any S of size xn we have So, a.a.s., in G n,d no set A of size xn induces a graph with more than yxn/2 edges, where y = dx + λ(1 − x). Now the desired upper bound follows from Lemma 1.
We have also tried several other ideas attempting to obtain a better upper bound. Unfortunately, they did not lead to improvements, therefore we place the discussion of these ideas to Appendix.

Lower bounds in terms of average degree
In this section, we obtain some general lower bounds for modularity. In particular, the obtained bounds are useful for graphs with bounded average degree. In Section 5, we apply these results to obtain a lower bound for the modularity of preferential attachment model (see Theorem 10).
Let us start with the analysis of trees. It was proven in [38] that trees with maximum degree ∆ = o( 5 √ n) have asymptotic modularity 1. We generalize this result in two ways: first, we relax the condition on maximum degree; second, we allow our graphs to be disconnected, that is, we consider forests instead of trees. We prove the following theorem.
Theorem 5 Let {F n } be a sequence of forests, where F n has n non-isolated vertices and the maximum degree ∆ = ∆(F n ). Then the following lower bound holds This theorem implies that if the maximum degree ∆(F n ) = o(n), then q * (F n ) = 1 − o(1). Note that it is also known that the asymptotic modularity of trees with maximum degree ∆ = Ω(n) is strictly less than 1 [38]. Hence, the assumption ∆ = o(n) cannot be eliminated.
We further generalize the above theorem to all connected graphs and prove the following result.
Theorem 6 Let {G n } be a sequence graphs, where G n is a connected graph on n vertices with the maximum degree ∆ = ∆(G n ) and the average degreed =d(G n ). Then The theorem implies that ifd(G n ) ≤ D for some constant D and ∆(G n ) = o(n), then q * (G n ) ≥ 2 D − o(1). Note that ford = 2 Theorem 6 looks similar to Theorem 5. However, there are two important differences: Theorem 6 is not restricted to forests, but requires graphs to be connected. Before we prove both theorems let us introduce some notation and the main lemma which we will use.
Proof. For a graph G let us consider its spanning tree T and decompose it, by removing some edges, into subtrees T 1 , . . . , T k such that h ∆ − 1 ≤ vol G (T i ) ≤ h for each 1 ≤ i ≤ k. The way we do this decomposition is in a sense similar to the algorithm greedy-decompose ≤h from [38]. Namely, we first redefine a notion of a centroid edge of a subtree T ′ of the initial tree T .

Definition 9
The removal of any edge from a tree T ′ splits T ′ into two parts T 1 and T 2 . A centroid edge of T is an edge chosen to maximize min{vol G (T 1 ), vol G (T 2 )}.
Our algorithm is the following: as long as our forest contains a tree T ′ with vol G (T ′ ) > h, it finds a centroid edge e of T ′ and removes it. After this decomposition, we obtain trees T 1 , . . . , T k and we set Obviously, for each i we have vol G (A i ) ≤ h. Let us show that we also have vol G (A i ) ≥ h ∆ − 1. Consider any step of our decomposition procedure. We take a tree T ′ with vol G (T ′ ) = h ′ > h, remove its centroid edge e, and obtain two trees T 1 and T 2 . Without loss of generality we may assume that vol G (T 1 ) ≤ vol G (T 2 ). Let s = vol G (T 1 ), s ≤ h ′ /2. Let x be the vertex incident with e and belonging to T 2 . For every edge e ′ incident with x, for the part T ′′ of T ′ − e ′ not containing x we have vol G (T ′′ ) ≤ s (otherwise e is not a centroid edge). As x has degree at most ∆, we have h ′ ≤ ∆s + ∆ (at most s for each of the ≤ ∆ parts plus the degree of x itself). So, . The number of intracluster edges in the spanning tree is n − k, and clearly this is the lower bound for A∈A e(A). Finally, It remains to estimate the degree tax. Recall that a vol Gn (A i ) ≤ h for all i and i vol Gn (A i ) = nd. Therefore, and so the proof is finished.
Proof. (Proof of Theorem 5.) This proof is similar to the previous one. Let us fix h = √ ∆n. The idea is to partition V (F n ) into A 1 , . . . , A k such that for each i: vol Fn (A i ) ≤ h and a subgraph induced by A i is a tree. Our forest F n may already contain trees T 1 , . . . , T ℓ with vol Fn (T i ) ≤ h. Let us denote the corresponding vertex sets by A 1 , . . . , A l . We decompose the remaining trees according to Lemma 8 (applied to each tree separately) into A l+1 , . . . , A k . Now we have the partition A = {A 1 , . . . , A k } of the vertex set V (F n ). In order to estimate q A we first consider the edge contribution. According to Lemma 8,vol Fn Therefore, it is easy to show that for each intercluster edge we can find at least h 2∆ − 1 inracluster edges. Hence, It remains to estimate the degree tax. Recall that vol Fn (A i ) ≤ h for 1 ≤ i ≤ k and i vol Fn (A i ) ≥ n. Therefore, and so the proof is finished.

Lower bound
The following theorem easily follows from the results of the previous section.
Proof. Let ε > 0. It is well-known that a.a.s. ∆(G n m ) = O n 1 2 +2ε (see, e.g., [22] and Theorem 17 in [12]). Also, clearly the average degree of G n m is at most 2m (it can be less due to the removal of loops and multiple edges). In addition, for m ≥ 2 a.a.s. G n m is connected [13]. So, the statement of Theorem 10 follows directly from Theorems 5 and 6.
We would like to remark that the obtained lower bound holds for many other models of complex networks. For example, it holds for the Random Apollonion Network [50] (in this case m = 3) or for the Buckley-Osthus model [17] (with slightly corrected error term).
As in the case of random d-regular graphs, it is natural to conjecture that the above lower bound is not sharp. Let c ∈ (0, 1) and consider the following partition: √ c (and so v∈A 2 deg(v, n) ∼ 2mn(1 − √ c)); see Lemma 11 below. Clearly, e(A 1 ) = mcn and so a.a.s. e(A 1 , The edge contribution and the degree tax are then both asymptotic to 1 + 2c − 2 √ c. Not surprisingly, such partition cannot be used to get a non-trivial lower bound for the modularity but, similarly to the situation for random d-regular graphs, we may try to use it as a starting point to get slightly better partition. The basic idea is very simple: one can start with a given partition (or partition the vertices randomly into two classes), and if a vertex has more neighbours in the other class than in its own, then we randomly decide whether to shift it to the other class or leave it where it is. This approach proved to be useful to get a bound for the bisection width in random d-regular graphs [3] which, in turn, yields a lower bound for the modularity [36]. In the proceeding version of this paper [44] we promised to investigate this approach. However, the following turns out to be slightly easier to do.
We will use the following standard martingale tool: the Hoeffding-Azuma inequality; for more details, see, for example, [30]. Let X 0 , X 1 , . . . be a martingale. Suppose that there exist c 1 , c 2 , . . . , c n > 0 such that |X k − X k−1 | ≤ c k for each 1 ≤ k ≤ n. Then, for every x > 0, The Hoeffding-Azuma inequality can be generalized to include random variables close to martingales. One of our proofs, proof of Lemma 11, will use the supermartingale method of Pittel et al. [46], as described in [49,Corollary 4.1]. Let X 0 , X 2 , . . . , X n be a sequence of random variables. Suppose that there exist c 1 , c 2 , . . . , c n > 0 and b 1 , b 2 , . . . , b n > 0 such that Let us now prove the following lemma.
In order to transform X t into something close to a martingale (to be able to apply the generalized Azuma-Hoeffding inequality (9)), we set for m⌊cn⌋ ≤ t ≤ mn cmn/k (note that Z m⌊cn⌋ = 0) and use the following stopping time T = min t > m⌊cn⌋ : X t > 2 √ tcmn + t 2/3 or t = mn .
Indeed, we have for m⌊cn⌋ < t ≤ mn provided t ≤ T , and |Z t − Z t−1 | ≤ 1 as t > cmn. Let t ∧ T denote min{t, T }. We apply the generalized Azuma-Hoeffding inequality (9) to the sequence (Z t∧T : m⌊cn⌋ ≤ t ≤ mn), with c t = 1, b t = 0.51t −1/3 and x = 0.1t 2/3 , to conclude that a.a.s. for all t such that m⌊cn⌋ ≤ t ≤ mn To complete the proof we need to show that a.a.s. T = mn. The events asserted by the equation hold a.a.s. up until time T , as shown above. Thus, in particular, a.a.s.
which implies that T = mn a.a.s. In particular, it follows that a.a.s., for any cn ≤ s ≤ n, Y s = X ms < 2mn cs/n + (mn) 2/3 = 2mn cs/n + o(n). The lower bound can be obtained by applying the same argument symmetrically to (−Z t∧T : m⌊cn⌋ ≤ t ≤ mn), and so the proof is finished.
Now, we are ready to prove the following, stronger, lower bound.
Before we prove the theorem, let us present numerical values for a few values of m: L 1 = L 1 (m) = 1/m is the lower bound following from Theorem 10 and L 2 = L 2 (m) is the lower bound from Theorem 12; see Table 2. Large degree tax hidden in L 2 makes this bound weaker for small values of m ≤ 6; for larger values L 2 is better than L 1 .  Proof. Let ε > 0 be any constant. Let us start with generating G εn m ; vertices from [εn/4] are coloured red and vertices from [εn] \ [εn/4] are coloured blue. We will continue generating G n m , colouring vertices red or blue (one by one, as they are introduced in the process), depending on how many of their neighbours are of each colour. We want to control the sum of degrees of vertices in each colour; that is, the following random variable The colouring process depends on the parity of m. If m is even, we colour vertex t ∈ [n] \ [εn] red if more than m/2 neighbours (in G t m ) are red. If the number of red neighbours is precisely m/2, we colour it red with probability 1/2 + p t , where p t = p t (Y t−1 ) = o(1) will be determined soon. Otherwise, t is coloured blue. If m is odd, the process is slightly different. If the number of red neighbours is more than (m + 1)/2, we colour it red. If it is (m + 1)/2 or (m − 1)/2, we colour it red with probability 1 − q t and, respectively r t , where q t + r t = q t (Y t−1 ) + r t (Y t−1 ) = o(1). Otherwise, t is coloured blue. The arguments for both cases are almost identical so we assume now that m is even; it will be clear what needs to be adjusted for odd value of m. In both situations, our hope is that the two graphs, induced by red and blue vertices, will be dense.
Arguing as in the previous lemma, we get that and P Bin m, Since P (Bin (m, 1/2) = m/2) = m m/2 2 −m = Θ(1), we can adjust ) is a martingale. It follows from the classic Hoeffding-Azuma inequality (8), applied to Z t with c t = m and x = (mn) 2/3 , that a.a.s., for each εn ≤ t ≤ n, The rest of the proof is straightforward. We partition the vertex set of G m n into red and blue vertices. The degree tax is a.a.s.
It remains to estimate the edge contribution. Clearly, the process guarantees that at least half of the edges are within the two clusters. However, we will do slightly better than that. For any i ∈ [m/2], with probability asymptotic to 2P(Bin(m, 1/2) = m/2 + i), at any point of the process we add m/2 + i edges to some cluster; m/2 edges are added with probability asymptotic to P(Bin(m, 1/2) = m/2). Hence, the expected number of edges added to some cluster is asymptotic to The expected edge contribution is then asymptotic to Finally, one can bound the edge contribution (independently, from above and from below) by the sum of independent random variables, and use Chernoff bound to get a concentration. It follows that a.a.s. see, for example, [15]. (More general and precise bounds can be found in [21].) It follows that a.a.s.
, and the proof is finished.

Upper bound
Recall that the edge expansion ρ = ρ(G) of a graph G is defined as follows: In [37] it was shown that a.a.s. ρ(G n m ) ≥ α, provided that 2(m − 1) − 4α − 1 > 0. In other words, for any ε > 0 we have that a.a.s.
Using this observation one can easily obtain a non-trivial upper bound for q * (G n m ).
Let ε > 0 be an arbitrary small constant. Consider any partition A = {A 1 , . . . , A k } of the vertex set V (G n m ). If |A i | > n/2 for some i, then the degree tax is at least On the other hand, if |A i | ≤ n/2 for all i, then a.a.s. the number of edges between parts is equal to and so the edge contribution is a.a.s. at most for any m ≥ 2. Therefore, the following result holds.
Some stronger expansion properties were recently obtained in [27]. However, whereas they presumably could be used to obtain some small improvements for an upper bound of q * (G n m ) (for specific values of m), we do not know how to show that q * (G n m ) → 0 as m → ∞. Perhaps q * (G n m ) = Θ(1/ √ m) as in the case of random (2m)-regular graphs?
6 The Spatial Preferential Attachment model Consider G n = (V n , E n ), a graph generated by the SPA model. As the modularity is defined for undirected graphs, we considerĜ n that is a graph obtained from G n by replacing each directed edge (u, v) by undirected edge uv. (As edges in G n are always from 'younger' to 'older' vertices, there is no problem with generating multigraph;Ĝ n is a simple graph.) Let us recall that V n ⊆ S where S is the unit hypercube [0, 1] m . We will use the geometry of the model to obtain a suitable partition that yields high modularity of G n . The following properties (proved many times; see, for example, [1,19]) are the only properties of the model that will be used in the proof: a.a.s. for every pair i, t such that 1 ≤ i ≤ t ≤ n we have that and |E(G n )| = Θ(n). Since we aim for a result that holds a.a.s., we may assume in the proof below that these properties hold deterministically. Now, we are ready to state our result for the SPA model.
Proof. Let ω = n min{1/m,1−pA 1 }/2 log n −1/2 . Note that ω ≥ n ε for some ε > 0 that depends on the parameters of the model. Let us partition the space S into ω parts as follows: for each integer 1 ≤ r ≤ ω, This partition of S naturally gives us a partition A of the vertex set: for each 1 ≤ r ≤ ω, A r = V n ∩ S r . We will show that a.a.s.
which will finish the proof as q * (Ĝ n ) ≥ q A (Ĝ n ) and always q * (Ĝ n ) ≤ 1.
First, let us start with estimating the edge contribution. In order to do that, we need to estimate the number of edges between different parts. So, let us focus on any part A r . We will investigate how many bad edges in G n connect vertices outside of A r with vertices inside A r by counting (independently) bad edges directed to vertices of similar age. (Note that for convenience we consider here directed graph G n instead ofĜ n .) For a given integer k such that 0 ≤ k ≤ ⌊log n⌋, let It is clear that {V (k) : 0 ≤ k ≤ ⌊log n⌋} and {E (k) : 0 ≤ k ≤ ⌊log n⌋} are partitions of the vertex set and the edge set (both inĜ n and G n ), respectively, and so {C (k) : 0 ≤ k ≤ ⌊log n⌋} is a partition of the bad edges we want to count. It remains to estimate the size of C (k) for a given value of k.
Fix 0 ≤ k ≤ ⌊log n⌋, and let us concentrate on any v i ∈ V (k) . It follows from (10) that the maximum volume of a sphere of influence of v i is O(i −1 log 2 n) = O(e −k log 2 n) (during the whole process) and so the maximum radius of influence of v i is O((e −k log 2 n) 1/m ). Therefore, if there is an edge in the cut directed to v i = (s 1 , . . . , s m ), then v i must fall not only into A r but also into a strip within distance O((e −k log 2 n) 1/m ) from one of the two cutting hyperplanes separating A r from the neighbouring parts; that is, vertices of V (k) are expected to appear in these two strips during the whole process. Hence, it follows from Chernoff bound that with probability at least 1−exp(−Θ(log 2 n)) there are O(e k(1−1/m) log 2 n) vertices in these strips at the end of the process. Note that the exponent of log n has changed from 2/m to 2 in order to guarantee the claimed upper bound is at least log 2 n which is required for a bound to hold with the desired probability. Using (10) one more time, we get that all vertices introduced in this time period have (final) in-degree O((n/e k ) pA 1 log 2 n). Hence, there are |C (k) | = O (e k(1−1/m) log 2 n) · (n/e k ) pA 1 log 2 n = O n pA 1 e k(1−1/m−pA 1 ) log 4 n edges in the cut with probability at least 1 − exp(−Θ(log 2 n)) and so this property holds a.a.s. for all parts A r and all values of k. It follows that a.a.s. the number of bad edges involving A r is at most log n · O n pA 1 n 1−1/m−pA 1 log 4 n , if pA 1 < 1 − 1/m; log n · O(n pA 1 log 4 n), otherwise, = O(n max{1−1/m,pA 1 } log 5 n).
Finally, we get an estimate for the edge contribution: a.a.s.
It remains to estimate the degree tax. In order to do that we need to, for a given r under consideration, estimate v∈Ar deg(v) inĜ n ; that is, v∈Ar (deg − (v) + deg + (v)) in G n . As before, we partition the vertices of A r into sets containing vertices of similar age. Let k 0 be the largest integer k such that (k − 1)ω log 2 n < n. Clearly, k 0 = O(n/(ω log 2 n). This time, for a given integer k such that 1 ≤ k ≤ k 0 , let V (k) = {v i ∈ V n : (k − 1)ω log 2 n < i ≤ min{kω log 2 n, n}}, and our goal is to estimate the size of A r ∩ V (k) . The expected number of vertices of V (k) that fall into A r is |V (k) |/ω ≤ log 2 n + 1 and it follows from Chernoff's bound that with probability at least 1 − exp(−Θ(log 2 n)) it is O(log 2 n). Using (10) for the last time, we get that all vertices introduced in this time period have (final) in-degree O((n/(kω log 2 n)) pA 1 log 2 n), provided k ≥ 2; and O(n pA 1 log 2 n) for k = 1. It follows that with the desired probability Finally, we are able to get an estimate for the degree tax inĜ n : a.a.s.

Discussion and future research
In this paper, we investigated modularity and provided precise theoretical bounds for several random graph models, such as random d-regular graphs, constant average degree graphs, preferential attachment and SPA models. However, there are plenty of directions for future research. For example, for preferential attachment model we expect that q * (G n m ) = Θ(1/ √ m). However, even the fact that q * (G n m ) → 0 as m → ∞ is still unproven. Also, in this paper we studied the most popular version of modularity, while other definitions (suitable for some particular clustering problems) were proposed in the literature (see discussion in [24]). For example, it was proposed to multiply the degree tax by a resolution parameter γ. Note that most of our results can be easily extended to such definition, as we separately estimate edge contribution and degree tax. Also, Erdős-Rényi random graph model can be used as a null model (instead of the pairing model) to compute the degree tax. This version of modularity is much easier to analyze, but such null model cannot describe real networks well, since it has an unrealistic Poisson degree distribution.
Finally, we would like to note that there is another model, which, similarly to SPA, combines geometry and preferential attachment [23]. It would be interesting to investigate the modularity for this model and we expect that its modularity tends to 1 (as for the SPA model). However, these two models are different and our result does not imply anything for the other model. set can be represented by the following triple: vertex v, vector (a 1 − 1, . . . , a zn − 1), and vector (b 1 − 1, . . . , b zn − 1): v starts some path, a i is the number of vertices on path i, b i is the number of vertices not in the set and right after path i. The number of such sets is at most n xn zn (1−x)n zn . The number of edges within this set that are part of the Hamiltonian cycle is xn − zn. Hence, in order for the set to induce yxn/2 edges, (yx/2 − x + z)n edges must be coming from the matching.
The hope is (that is, was) that for small values of z, there are only a few sets to consider. On the other hand, if z is closer to x, then less edges are "for free" (edges of the Hamiltonian cycle). Unfortunately, again this idea does not lead to any substantial improvement. Concentrating on d = 3,x = 0.0225,ŷ = 2.4789, and tuningẑ ≈ 0.00392, the expected number of such sets is tending to infinity as n → ∞.
Conclusion: The lack of improvement is disappointing but perhaps should not be surprising. Looking at one or two parts of a partition maximizing q * is not enough (local property). Having one large term y i /d − x i in (4) might be possible but having all of them to be large perhaps is not. So in order to improve the upper bound, one needs to consider all parts at the same time (global property).