{'fraction_non_alphanumeric': 0.04313013771751895, 'fraction_numerical': 0.00843386356357425, 'mean_word_length': 4.362049227246708, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Optimality of Graph Scanning Statistic for Online Community Detection

Sequential change-point detection for graphs is a fundamental problem for streaming network data types and has wide applications in social networks and power systems. Given fixed vertices and a sequence of random graphs, the objective is to detect the change-point where the underlying distribution of the random graph changes. In particular, we focus on the local change that only affects a subgraph. We adopt the classical Erdos-Renyi model and revisit the generalized likelihood ratio (GLR) detection procedure. The scan statistic is computed by sequentially estimating the most-likely subgraph where the change happens. We provide theoretical analysis for the asymptotic optimality of the proposed procedure based on the GLR framework. We demonstrate the efficiency of our detection algorithm using simulations.


I. INTRODUCTION
Change-point detection is a fundamental problem for network data, such as power systems [1], [2], sensor networks [3], and social networks [4]- [6]. Network data can be modeled as graphs. For instance, in social networks, each node represents users, and the edge represents the connectivity between users. We consider the Erdős-Rényi model [7], which is parameterized by the probability of having an edge between two nodes. In this paper, we consider the detection of a local change in the graph, which only affects the distribution of a subgraph. The detection procedure is to form the scan statistic based on the Erdős-Rényi model. In particular, we treat the affected subgraph as unknown anomaly information, and apply the generalized likelihood ratio test [8] to form the scan statistic, utilizing the graph scanning techniques [9], [10].
In order to give a computationally efficient algorithm and theoretical calibration, we assume the size of the subgraph affected by the change is known. More specifically, when the change happens, only a subset of the graph, of known size, is affected by the change and has a different distribution, while the distribution for the rest of the graph remains the same. The problem of local change-point detection is challenging for two reasons: (i) it is not clear whether there is a change; (ii) if there is a change at some time, it is not clear which subgraph contains the change.
The major motivating application of our study is community detection. In particular, we are interested in the detection of the emergence of a community in a network that is homogeneous in the beginning. Such a problem is essential for dynamic networks. For example, the social network can start from a homogeneous state, and then evolve over time and form a community. Usually, the interactions between nodes within the community are more dense than other parts of the network. Another example is ambient noise monitoring in seismic sensor networks. More specifically, the cross-correlation function between the sensors affected by the change will have a significant peak at the time of the change. Meanwhile, such waveform does not exist for cross-correlation functions between affected sensors and unaffected sensors, and among unaffected sensors. Therefore, this problem, mathematically, becomes detecting a local change in a sequence of graphs [11].
In this paper, we focus on the parametric approach for constructing scan statistics to detect a local change in a sequence of graphs. For simplicity, we adopt the Erdős-Rényi model (while the analysis can be generalized to more complicated models), where each edge exists with probability p 0 ∈ (0, 1) and independently with each other. After the change, the affected subgraph still follows the Erdős-Rényi model, but with a different parameter p 1 ∈ (0, 1). We consider a sequential detection setting and prove the optimality of the online detection procedure in the sense that the detection delay matches the well-known lower bound. The main idea of the proof is adopted from the seminal work on generalized likelihood ratio test [8].
This paper is related to works in community detection and graph scan statistics. In [12], three likelihood ratio based algorithms were developed for detecting communities in the Erdős-Rényi graph, including the exhaustive search, the mixture, and the hierarchical mixture methods. Theoretical approximation was also given in [12] to characterize the false alarms. In [13], the community detection for Erdős-Rényi graphs was considered as a hypothesis testing problem, where the goal is to find a test function that takes the random graph as input and claim whether there is a community or not. The detectability of this problem in the asymptotic dense regime, when the connection probability p 0 is large enough, was provided in [13]. Later on, information-theoretic lower bounds for the asymptotically sparse regime, when the connection probability p 0 is small enough, was studied in [14].
The rest of the paper is organized as follows. We present the problem setup in Section II. The detection procedure is detailed in Section III. We present the optimality study in Section IV. Numerical examples are presented in Section V to support the theoretical findings. Finally Section VI contains our concluding remarks.

II. PROBLEM SETUP
Given a network with N sensors (nodes) numbered as {1, . . . , N }, the dynamic graphical structure is observed as a sequence of undirected adjacency matrixes G (1) , G (2) , . . . , where G (t) ∈ {0, 1} N ×N characterizes the edge or interaction information between different nodes, i.e., G Assume that there is a change-point at an unknown time τ that changes the distribution of a subgraph with nodes indexed by V * ⊂ {1, . . . , N }. Before the change, the full graph follows the model ER(N, p 0 ) with connection probability p 0 . After the change, the subgraph V * follows ER(|V * |, p 1 ), i.e., the connection probability inside the subgraph V * becomes p 1 , with everything else the same. Here |V * | denotes the cardinality of the set V * . Usually, the true subgraph V * is unknown as it represents the anomaly information. We assume that the cardinality of V * equals a known constant n with n < N . In most applications, we have n N which means that we are only interested in the local graphical changes.
Although the true subgraph where the change happens is unknown, there are only a finite number of possible subgraphs when the total number of nodes N is fixed. Denote all possible subgraphs as: Note that the number of all possible subgraphs can be upper bounded by N n and we further have if we are only interested in locally connected subgraphs, which is a reasonable assumption for community detection tasks where the change tends to happen within a small neighborhood.
In summary, the problem of detecting a local change for the underlying Erdős-Rényi model becomes the following hypothesis testing problem: where τ represents the change-point. This hypothesis testing problem is illustrated in Fig. 1, where the post-change subgraph contains only three nodes and is shown in highlight. Fig. 1. Graphs prior to the change-point in time τ follow the Erdős-Rényi model with coneection probability p 0 . After the change-point τ , the subgraph (shown in highlight) follows the Erdős-Rényi model with connction probability p 1 = p 0 , with everything else the same. We are particularly interested in detecting the local change in the subgraph.
Given access to a sequence of graph observations G (1) , G (2) , . . ., if they are sampled from the hypothesis H 1 in the model (1), our objective is to design a stopping time that can detect the unknown change-point τ as quickly as possible. Meanwhile, if the data are sampled from the hypothesis H 0 in the model (1), it is desired to have less false alarms as possible.
Here we assume the connection probabilities p 0 , p 1 are known, but the subgraph where the change happens is unknown.

III. DETECTION PROCEDURE
The detection problem (1) can be solved based on statistical change detection methodology, which we describe in this section. We start by introducing the basic cumulative sum (CUSUM) procedure for change detection when the subgraph V * is known, and then study the generalized likelihood ratio (GLR) test for unknown subgraphs.
The log-likelihood ratio between the pre-and post-change distributions plays a key role in sequential change detection. For the Erdős-Rényi model ER(N, p 0 ) before change, we have the likelihood function of G (t) is and the likelihood function for post-change model is similarly defined. Therefore, the log-likelihood ratio for the hypothesis testing problem (1) with subgraph V * reads When the subgraph V * is known, we can construct the wellknown CUSUM procedure, which was first introduced by Page in [15]. The CUSUM statistic can be formed recursively as where (x) + := max{x, 0}. The corresponding stopping time is: where the threshold b is a pre-set constant to control the false alarm rates. By Jensen's inequality, it is easy to show that the expectation of the increment term V * (G (t) ) in (2) is negative under the pre-change regime, and positive in the post-change regime. Therefore, the CUSUM statistic S t will have a positive drift after the change happens, enabling its efficient detection of the change-point. The CUSUM procedure was shown to have strong optimality properties in [8], [16]- [18]. In particular, it attains the minimal worst-case detection delay among all testing procedures that satisfy certain false alarm constraint.
However, the CUSUM statistic (2) cannot be used directly when the changed subgraph V * is unknown. Therefore, we adopt the GLR framework [8], [12], also known as the scan test [11], [13]. The GLR test was originally developed for change detection for parametric families when the post-change parameter is unknown, by substituting the maximum likelihood type estimators. Here instead of estimating the post-change parameters, we estimate the unknown post-change subgraph by maximizing the likelihood function of samples in the past. More specifically, the GLR statistic at time t is defined as where R t,k,V is the log-likelihood ratio of samples G (k) , . . . , G (t) , assuming the changed subgraph is V and the change-point τ = k, which can be derived as: (4) Usually, the GLR statistics constructed this way does not enjoy recursive computations as in (2); the computation complexity for maximizing over all possible k ≤ t will increase polynomially with time t. To save the computational cost, we use the window-limited GLR approach [8], which we detailed as follows. At each time t, we form statistics by aggregating test statistic under different subgraphs V , over time where m α is the minimal number of samples to ensure the reliable estimation of the subgraph, and m α is the maximum number of samples to look back in order to reduce the computation time. The window-limited GLR stopping time is [12] T G = inf t : max where b is the threshold, and R t,k,V is the log-likelihood ratio as defined in (4).
We are further interested in knowing which subgraph contains the change in the graph structure. Once we have detected the change-point as k, we can choose a post-change interval (k, t). The test statistic R t,k,V is useful in localizing the change, as the subgraph V * that maximizes R t,k,V , over all possible subgraphs in V, is the maximum likelihood estimate (MLE) of the subgraph containing the change, It is worth mentioning that the solution to (6) is the so-called "densest n subgraph" [19] and it is an NP-hard problem; there is no constant approximation ratio algorithm due to its core hardness. We use the greedy procedure in [19] to approximate the maximum likelihood estimate V k,t . For completeness, we restate the procedure here: "Sort the vertices by order of their degree. Let H denote the n/2 vertices with highest degrees in the graph G. Sort the remaining vertices by the number of neighbors they have in H. Let C denote the n/2 vertices in G \ H with the largest number of neighbors in H. Return H ∪ C."

IV. OPTIMALITY
We first introduce two metrics commonly used to characterize the performance of detection procedures in sequential change detection.
The average run length (ARL) is defined as the average time between false alarms when there is no change; it can be denoted as E ∞ [T ], where E ∞ is the expectation under the pre-change measure (i.e., the change-point is at ∞). The expected detection delay (EDD) refers to the expected delay in detecting the change. There are two common definitions for EDD as introduced in [16] and [20]. We adopt the one in [16] as follows: where the essential supremum is taken over all possible change-point τ and realizations G (1) , . . . , G (τ −1) before the change; and E τ is the expectation under the probability measure that the change-point equals to τ .
The goal is to minimize EDD subject to the ARL constraint that E ∞ [T ] ≥ γ for a positive constant γ.
The lower bound to the worst-case EDDĒ 0 (T ) was given in [8,Theorem 1]. More specifically, we restate this lower bound in our setting (1).
is the Kullback-Leibler (KL) divergence between the graphical distribution ER(n, p 1 ) and ER(n, p 0 ) on the changed subgraph V * with |V * | = n.
Theorem 1 means that for any detection procedure with ARL greater than γ, the minimal detection delay is of the order of log γ/I. Therefore, a detection procedure is called first-order asymptotic optimal if its EDD equals to log γ/I(1+ o(1)) asymptotically as γ → ∞. Below, we prove that the detection rule (5) achieves the lower bound in Theorem 1.
We first consider the pre-change regime and state the following lemma: Lemma 2. For the stopping time (5), we have Proof. First note that where τ k := inf t ≥ k + m α : V k,t ∈ V, and R t,k, V k,t ≥ b . (10) To analyze P ∞ (τ k ≤ k + m α ), we use a change-of-measure argument. Let P k V denote the probability measure under which the distribution of G (i) is ER(N, p 0 ) for i < k, and the distribution of the subgraph V becomes ER(n, Since V is a finite set, Q k is a finite measure. For t ≥ k, let F k,t denote the sigma-algebra generated by G (k) , . . . , G (t) . The Radon-Nikodym derivative of the restriction of measure Q k to F k,t relative to the restriction of P ∞ to F k,t is Hence by Wald's likelihood ratio identity, we have Since where the last inequality is due to the definition of τ k in (10), we have that Substitute into (9), we have Given the condition (8) in Lemma 2, by [8, Theorem 4], we have the following optimality results for our setup (1).
then we have and as α → 0, Therefore the stopping rule (5) is asymptotically optimal.
Proof. For the true subgraph V * , define the window-limited CUSUM rule as It is obvious thatĒ due to the definition of T G in (5). Note that for any finite value N, n, the constraint (12) (13) is proved in [8] whenever T G satisfies the condition (8). Further note that Therefore, T G matches the lower bounds in Theorem 1. In other words, T G is first-order asymptotically optimal.
It is worth mentioning that the condition (12) only yields b ∼ | log α| for finite values of N, n. It does not hold for N that diverges to infinity. The analysis here differs from the original GLR framework considered in [8] and can be viewed as a special case, since the unknown subgraph has finite possibilities while the unknown parameter in parametric models can vary in a continuous space.
Remark 4 (Generalization to unknown p 1 ). When the postchange probability p 1 is unknown, we can estimate it using the maximum likelihood estimator when formulating the GLR detection statistic. More specifically, given G (k) , . . . , G (t) and a subgraph V , the MLE of p 1 is given by And the resulted detection procedure is where U t,k,V is defined as Remark 5 (Generalization to directed graph). In multivariate time series models or point processes, the underlying connectivity can be modeled as a directed graph, in contrary to the undirected graph considered in this paper. It is worth mentioning that the aforementioned maximum likelihood estimate and the optimality results still holds for sequential change detection on directed graphical models, since the loglikelihood ratio can be computed in a similar fashion.

V. NUMERICAL EXAMPLES
We present simulation examples using the Erdős-Rényi graphical models to visualize the detection procedure (5).
The size of the network N , i.e., the total number of nodes, is set as 20 and 50, respectively. In both cases, we are interested in detecting the change that happens only in a much smaller subgraph consisting of n = 5 nodes. The pre-change edgeforming probability is set as p 0 = 0.2, and the post-change probability is p 1 = 0.5, i.e., the change increases the intensity of edges within the changed subgraph.
For numerical issues, we do not compute the worst-case detection delay (7) that takes supremum over all possible past observations and over all possible change-points. Instead, we compute an alternative formulation E 1 [T G ] that can be conveniently evaluated by setting the change-point as τ = 1, i.e., the change happens before we take any sample.
In Fig. 2, we compare the EDD of the GLR procedure in (5) and the CUSUM procedure in (3). The CUSUM statistic serves as a baseline since it is the optimal detection procedure with the smallest detection delay. It is shown that the detection delay of the GLR approach indeed matches the detection delay of CUSUM in first-order (i.e., in the slope). Moreover, it can be seen that the detection delay of the GLR approach tends to increase as we increase the network size N , since it becomes more difficult to scan for the right subgraph containing the change.

VI. CONCLUSION
We have revisited the sequential change detection for Erdős-Rényi graphs. The problem setup can be applied to community detection problems. The graph scanning statistic considered in this paper is formed by scanning all possible subgraphs over the whole graph. The detection procedure matches the wellknown GLR test and is asymptotically optimal.
Future direction includes extending the proposed method to more complicated graphical models and to sequences with dependency. Moreover, the framework can be applied to the goodness-of-fit test for local regions. The global null is that a known graphical distribution P 0 (e.g., ER(N, p 0 )) is a good fit for all local regions (the whole graph). The alternative is that there is a subgraph such that the underlying distribution distinct from P 0 significantly. For each local region, we can compute a local test statistic based on GLR, and compare it with a threshold, which can be set by simulation or the limiting distribution of the test statistic.