{'fraction_non_alphanumeric': 0.03316631482564794, 'fraction_numerical': 0.011928682249408653, 'mean_word_length': 4.205613663444988, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Fast and Accurate Mining of Correlated Heavy Hitters

The problem of mining Correlated Heavy Hitters (CHH) from a two-dimensional data stream has been introduced recently, and a deterministic algorithm based on the use of the Misra--Gries algorithm has been proposed by Lahiri et al. to solve it. In this paper we present a new counter-based algorithm for tracking CHHs, formally prove its error bounds and correctness and show, through extensive experimental results, that our algorithm outperforms the Misra--Gries based algorithm with regard to accuracy and speed whilst requiring asymptotically much less space.


Introduction
Mining heavy hitters (also called frequent items), is a well known and studied data mining task. Algorithms for detecting heavy hitters in a data stream can be classified as being either counter or sketch based, depending on their main data structure. Counter-based algorithms rely on a fixed number of counters in order to keep track of stream items. Sketch-based algorithms, as their name suggests, monitor the input data stream by using a set of counters which are stored in a sketch data structure, tipically a two-dimensional array. In this case, hash functions map items to their corresponding sketch cells. Counter-based algorithms are deterministic and sketch-based ones are randomized, thus providing a probabilistic guarantee.
Regarding the counter-based algorithms, the first sequential algorithm has been designed by Misra and Gries [26]. About twenty years later, the same algorithm was rediscovered independently by both Demaine et al. [13] (the so-called Frequent algorithm) and by Karp et al. [19]. Among the recently developed counter-based algorithms we recall here Sticky Sampling, Lossy Counting [23] and Space Saving [24]. Notable examples of sketch-based algorithms are CountSketch [5], Group Test [10], Count-Min [9] and hCount [18].
Regarding parallel algorithms, [3,4] provide message-passing based parallel versions of the Frequent and Space Saving algorithms. Shared-memory algorithms have been designed as well, and we recall here the parallel version of Frequent [32], the parallel version of Lossy Counting [31] and the parallel versions of Space Saving [12,27]. Novel shared-memory parallel algorithms for frequent items were recently proposed in [28]. Accelerator based algorithms for frequent items exploiting a GPU (Graphics Processing Unit) include [14,16].
The problem of mining Correlated Heavy Hitters has been introduced recently [20] by Lahiri et al. Data mining problems that require to compute correlated heavy hitters may be found in the context of network monitoring and management, as well as anomaly and intrusion detection. As an example, consider the stream of pairs (source address, destination address) of IP packets passing through a router. Identifying the nodes that are responsible for the majority of the traffic through that router (frequent items over a single dimension) could be useful, but it is also interesting to discover, for all of the frequent sources, what are the destinations that receive the majority of connections by the same source. Important sources are detected as frequent items over the first dimension, then we search for the frequent destinations in the context of each one of those sources, i.e., the correlated heavy hitters of the stream. In order to formally state the problem, we recall here preliminary notation and definitions.
Definition 2 The frequency f x of an item which appears as first element in the tuple (x, y) is given by f x = |{(i, j) ∈ σ : (x = i)}|.
The frequency f x refers to the frequency of the item x disregarding the second item belonging to the tuple, i.e., the frequency computed when considering the sub-stream induced by the projection of the tuples on the first dimension, which is also referred to as the primary dimension (whose items are referred to as primary items). We are now ready to state the Exact Correlated Heavy Hitters problem.

Problem 1 Exact Correlated Heavy Hitters problem.
In the online setting, given a data stream σ of length N made of (x, y) tuples in which the item x is drawn from the universe U 1 = {1, ..., m 1 } and the item y is drawn from the universe U 2 = {1, ..., m 2 }, two user-defined thresholds φ 1 and φ 2 such that 0 < φ 1 < 1 and 0 < φ 2 < 1, the Exact Correlated Heavy Hitters (ECHH) problem requires determining all of the (x, y) tuples such that: and The Exact Correlated Heavy Hitters problem can not be solved using limited space and only one pass through the input stream, hence the Approximate Correlated Heavy Hitters problem (ACHH) is introduced [20]. We state the problem as follows.
Problem 2 Approximate Correlated Heavy Hitters problem.
Given a data stream σ of length N made of (x, y) tuples in which the item x is drawn from the universe U 1 = {1, ..., m 1 } and the item y is drawn from the universe U 2 = {1, ..., m 2 }, two user-defined thresholds φ 1 and φ 2 such that 0 < φ 1 < 1 and 0 < φ 2 < 1 and two error bounds ǫ 1 and ǫ 2 such that 0 < ǫ 1 < φ 1 and 0 < ǫ 2 < φ 2 , the Approximate Correlated Heavy Hitters (ACHH) problem requires determining all of the primary items x such that and no items with should be reported; moreover, we are required to determine for each frequent primary candidate x, all of the tuples (x, y) such that and no tuple (x, y) such that should be reported.
In this paper we present CSSCHH (Cascading Space Saving Correlated Heavy Hitters) a new counter-based algorithm for tracking CHHs in a two-dimensional data stream and solving the ACHH problem, formally prove its error bounds and correctness and show, through extensive experimental results, that our algorithm outperforms the Misra-Gries based algorithm [20] proposed by Lahiri et al. (from now on called MGCHH) with regard to accuracy and speed whilst requiring asymptotically much less space.
The rest of this manuscript is organized as follows. In Section 2 we provide an overview of related work, we recall in Section 3 the MGCHH algorithm introduced in [20] and present our algorithm in Section 4. Then, we formally prove its error bound and correctness in Section 5. Next, we analyze our algorithm worst case time and space complexity in Section 6. We compare, from a theoretical perspective, CSSCHH against MGCHH in Section 7. Extensive experimental results are reported and discussed in Section 8. We draw our conclusions in Section 9.

Related work
The problem of efficiently analyzing two-dimensional data streams in order to gain insights and compute significant statistics has been largely investigated in many forms.
Gehrke et al. [15], Ananthakrishna et al. [2] and Cormode et al. [11] refer to the notion of correlated aggregates and present solutions tailored to different contexts. On a two-dimensional stream, i.e., a stream of items' pairs, a correlated aggregate is an aggregate value computed along the second dimension on a set of pairs defined by a particular constraint on the first dimension. A typical correlated aggregate is, for instance, the average value of the items on the second dimension computed for those pairs such that the frequency of the first dimension item is above a fixed threshold.
Mining heavy hitters can also be applied to streams of pairs, when a pair is regarded as a single item. The problem requires finding all of the items which appear in the stream with a frequency greater than a threshold. [7,21] present an overview and comparison of the most common frequent items algorithms, while Zhang et al. in [30] treat the case of multidimensional and hierarchical heavy hitters in the context of network traffic analysis.
A stream of items' tuples can also be processed in order to find frequent itemsets, i.e., a set of items which appear in the stream with a frequency above a threshold. In the context of streams of pairs we are interested in finding the frequent two-itemsets. Also, strictly correlated is the notion of association rules, which are implications of the type first item =⇒ second item; the problem entails searching for pairs of items that are frequent two-itemsets and such that the frequency of the second item with regard to the number of occurrences of the first item is above a fixed threshold. Several frequent itemsets algorithm in the offline setting have been proposed, we recall here Apriori [1], Eclat [29] and FPGrowth [17], while an overview of streaming algorithms that solve the frequent itemsets problem is given in [6].
In [25], Mirylenka et al. introduce the notion of Conditional Heavy Hitters and compare it with other related problems, such as association rules and Correlated Heavy Hitters, highlighting how solving these problems actually leads to different outputs, each emphasizing particular aspects of the input data stream. A group of algorithms is proposed and experimentally evaluated with respect to the approximate mining of Conditional Heavy Hitters. One of these, FamilyHH, is based on the same approach we use in our algorithm, but the authors conclude that the algorithm is not particularly suitable for that problem.
Lahiri et al. [20] introduced the notion of Correlated Heavy Hitters and proposed an approximate solution based on the Misra-Gries algorithm. We will refer to the Misra and Gries algorithm as MG, and to the their CHH algorithm as MGCHH. In this paper, we present a new counter-based algorithm for tracking CHHs, with reference to the original problem formulation introduced in [20]. Therefore, we compare our solution against MGCHH. In the next section, we recall the MGCHH algorithm.

The Misra-Gries based CHH algorithm
This CHH algorithm, recently introduced in [20] by Lahiri et al., is based on a nested application of the Misra and Gries algorithm [26]. Before delving into the details of MGCHH, we recall first how MG works. Being counter-based, MG keeps track of stream items by using a data structure holding k counters, i.e., pairs (item, frequency). In particular, given a stream σ of length N , a support threshold φ to determine frequent items (i.e., those items whose frequency exceeds φN ), and an error threshold 0 < ǫ < 1, MG requires at least k = 1 ǫ counters to estimate the frequencies of the items with an error less than or equal to ǫN .
The MG algorithm works as follows. Upon receiving an item from the stream, if one of the counters is already monitoring the item, then the counter is updated by increasing by one the frequency of the item. If none of the counters is monitoring the item but there is a counter available in the data structure (i.e., a counter which is not monitoring any item), this counter is then assigned the responsibility of monitoring the received item and its corresponding frequency is set to one. Otherwise, all of the counters in the data structure are already in charge of monitoring an item. In this case, since the number of counters can not exceed k, all of the counters' frequencies are decremented by one. As a result, the counters whose frequencies after the decrement are reset to zero become available to monitor incoming items (since their items are discarded). It is worth recalling here that MG underestimates the frequency of an item; therefore, a single pass of the algorithm over the stream is not enough for exact identification of frequent items.
MGCHH is a single-pass algorithm solving Problem 2 as follows. Basically, the algorithm estimates the frequencies of the items occurring in the stream along the primary dimension using a set of counters (primary counters) updated as in the MG algorithm; moreover, another set of counters (secondary counters) is associated to each primary counter to keep track of the frequent items occurring along the secondary dimension and correlated to the primary item. In other words, for each distinct item d along the primary dimension, the algorithm maintains its frequency estimatef d and an embedded MG set of secondary counters related to the sub-stream σ d induced by d: σ d = {y|(d, y) ∈ σ}. The embedded secondary counters are a set of pairs (s,f d,s ), where s is an item occurring in σ d andf d,s estimates the frequency of the tuple (d, s) in σ. Alternatively,f d,s can be seen as the frequency estimate of s in σ d . Therefore, the MGCHH actions onf d are driven by the item d occurring in σ whilst the actions onf d,s depend instead on the item s occurring in σ d .
The MGCHH main data structure is a Let s 1 and s 2 be respectively the maximum number of primary counters in H and the maximum number of secondary counters in each H d . In MGCHH s 1 and s 2 depend on the parameters φ 1 , φ 2 , ǫ 1 , ǫ 2 , and are set at the beginning of the algorithm.
When the algorithm starts, its data structures are initialized. The number of counters s 1 (for tracking the primary items) and s 2 (for tracking correlated items) is selected in order to solve the ACHH problem within the ǫ 1 and ǫ 2 error bounds; moreover, s 1 and s 2 are also chosen to minimize the total space required, as discussed in [20]. In practice, letting α = 1+φ 2 ǫ 2 counters in order to keep track of the primary frequent items and s 2 = 2 ǫ 2 counters to track correlated frequent items; otherwise, if ǫ 1 < ǫ 2 2α , then MGCHH sets s 1 = 1 ǫ 1 and Upon receiving a tuple (x, y) from the stream, the data structures are updated as needed. Depending on the tuple (x, y), the update process works as follows: 1. If x is in H (i.e., it is already monitored), and y is in H x as well, then bothf x andf x,y are incremented. 2. If x is in H, but y is not in H x (i.e., it is not monitored) and there is an available counter, then y is added to H x and its frequency is initialized to one. If no counter is available (i.e., |H x | = s 2 ), then each counter in H x is decremented by one. If the frequency of any monitored item goes to zero, the item is evicted from H x . After this operation, the size of H x is such that |H x | ≤ s 2 . 3. If x is not in H, and |H| < s 1 then a counter is created for x in H setting its frequencyf x to one, and initializing H x with the counter (y, 1). If |H| = s 1 , then for each monitored item d ∈ H, its frequencyf d is decremented by one; if this decrement causesf d to become zero, then the counter monitoring d is discarded and removed from H. Otherwise, an arbitrary item s is randomly selected from H d such thatf d,s > 0 andf d,s is decremented by one. Iff d,s goes to zero, the item s is discarded from H d . This further decrement guarantees that the sum of thef d,s frequencies within H d is less than or equal tof d .
Finally, in order to report the CHHs in the stream, a query can be posed to the data structures as follows. For each primary item

A Space Saving based algorithm
Our Cascading Space Saving Correlated Heavy Hitters (CSSCHH) algorithm exploits the basic ideas of the Space Saving algorithm [24], combining two Space Saving stream summaries for tracking the primary item frequencies and the tuple frequencies.
We refer to our algorithm as cascading Space Saving since it is based on the use of two distinct and independent applications of Space Saving. It is worth noting here immediately that it is not possible to follow the same approach used in MGCHH, i.e., a nested application of Space Saving in place of Misra-Gries. The reason is that upon arrival of a primary item which is not monitored, if the primary summary is already full then Space Saving must evict the item monitored by the counter with the minimum frequency and replace it with the newly arrived item, incrementing the counter. However, in the nested approach, substituting the item also requires updating the embedded secondary summary but, in the Space Saving case, we can not reuse the secondary summary because it refers to the evicted item, not to the newly arrived one. Therefore, we use two independent Space Saving stream summaries as data structures. The first, denoted by S p , and referred to as the primary stream summary, monitors a subset of primary items which appears in the stream through the use of k 1 distinct counters. The second, denoted by S t , includes k 2 counters and monitors a subset of the tuples which appear in the stream.
The counters are updated in order to accurately estimate the items' frequencies and a lightweight data structure is exploited to keep the elements sorted by their estimated frequencies. A detailed description of the Space Saving algorithm is given in [24]. Here, we briefly recall how Space Saving works and its main properties.
A stream summary S is a data structure used to monitor k distinct items and includes k counters. We denote with c j the jth counter and by c j .i and c j .f respectively the item monitored by the jth counter and its corresponding estimated frequency. When processing an item which is already monitored by a counter, its estimated frequency is incremented by one. When processing an item which is not monitored, there are two possibilities. If a counter is available, it will be in charge of monitoring the item and its estimated frequency is set to one. Otherwise, if all of the counters are already occupied (their frequencies are different from zero), the counter storing the item with minimum frequency is incremented by one. Then the monitored item is replaced by the new item. This is because since an item which is not monitored can not have a frequency greater than the minimal frequency. The complexity of the Space Saving update procedure is O(1) in the worst case, as proved by its authors.
Let N be the length of the input stream, c i ∈S c i .f the sum of the counters in S, k = |S| the number of counters in S, f v the exact frequency of an item v,f v its estimated frequency andf min the minimum frequency in S. Then, the following relations hold for Space Saving: Our CSSCHH algorithm starts by initializing the S p primary stream summary data structure allocating k 1 counters and the correlated S t stream summary allocating k 2 counters. We shall explain in Section 5 how exactly the values of k 1 and k 2 are derived. Algorithm 1 presents the pseudocode related to the initialization phase of CSSCHH.

Algorithm 1 CSSCHH Init
Require: Threshold for primary itmes φ 1 ; threshold for correlated items φ 2 ; tolerance for primary items ǫ 1 ; tolerance for correlated items ǫ 2 . Ensure: Properly initialized S p and S t stream summaries Allocate k 1 counters for S p 7: Allocate k 2 counters for S t 8: return S p and S t 9: end procedure In CSSCHH algorithm, a tuple (x, y) is processed by updating two stream summaries, S p and S t . The primary item x is used to update the primary stream summary S p ; the tuple (x, y) is also considered as a single item and it is used to update the correlated stream summary S t . Since for each tuple in the stream both stream summaries are updated by means of the Space Saving update procedure, we inherit its properties. Let f x andf x denote the exact and estimated frequency of the primary item x, and let f xy andf xy denote the exact and estimated frequency of the tuple (x, y); moreover, denoting by c p i and c t i the ith counter in the primary and in the correlated stream summary, and denoting byf p min andf t min the minimum frequency in the primary and correlated stream summary, the following relations hold: The update procedure of CSSCHH is presented in Algorithm 2.

Algorithm 2 CSSCHH Update
Require: x, y, the items of a tuple. Ensure: Update of S p and S t stream summaries.
SpaceSavingUpdate(S t , (x, y)) 4: end procedure In order to retrieve the correlated heavy hitters, a query is posed to both stream summaries. The query procedure internally uses two lists, F and C. The former stores primary items and their estimated frequencies (r,f r ). The latter stores CHHs (r, s,f rs ) in which r is a primary frequent item, s the correlated frequent item candidate andf rs the estimated frequency of the tuple (r, s).
The query algorithm inspects all of the k 1 counters in the S p stream summary. If the frequency of the monitored item is greater than the selection criterion (i.e., c p j .f > φ 1 N ), then we add the monitored item r = c p j .i and its estimated frequencŷ f r = c p j .f to F . The algorithm inspects now all of the k 2 counters of the S t stream summary. The monitored items in S t are the tuples (r, s). We check if the primary item r is a primary frequent item candidate (i.e., if r ∈ F ); if this condition is true and the tuple estimated frequency is greater than the selection criterion (i.e., c t j .f > φ 2 (f r − N k 1 )), then the triplet (r, s,f rs ) is added to C. The Query procedure is presented as Algorithm 3.

Algorithm 3 CSSCHH Query
Require: S p and S t stream summaries. Ensure: Set of correlated frequent items C 1: procedure CSSCHH-Query(S p , S t ) 2: for each c t j ∈ S t do 10:

Correctness
We are going to formally prove the correctness of our algorithm. The main results of this section are the following two theorems.

Theorem 1
The CSSCHH algorithm reports all of the primary items x whose exact frequency f x is greater than the threshold, i.e., f x > φ 1 N and no items whose exact frequency is such that f The algorithm determines all of the primary frequent candidates through the selection criterionf x > φ 1 N . Since the stream summary provides an overestimation of the frequencyf x ≥ f x , if the exact frequency of an item is greater than the threshold, its estimated frequency will be greater as well:f x ≥ f x > φ 1 N , hence the item will be selected and this proves the first part of the theorem.
The second part of the theorem states that, given an item x, if its exact frequency is f x ≤ (φ 1 − 1 k 1 )N , which can be rewritten as then the item will not be selected; hence we must prove that its estimated frequency is less thanf x ≤ φ 1 N . By using the Space Saving properties we know that the estimate error provided by the stream summary S p is bounded by N k 1 : hence, by using Eq. (10) we havê which proves the theorem. Moreover, this theorem also implies that for all of the primary frequent candidates it holds that: Theorem 2 All of the tuples (x, y) with the item x reported as primary frequent candidate and with exact frequency f xy greater than the threshold (f xy > φ 2 f x ) are reported as correlated heavy hitter candidate. No tuple with a primary item x reported as frequent primary candidate and with exact frequency less than f xy ≤ (φ 2 − k 2 φ 2 +k 1 k 2 (k 1 φ 1 −1) )f x is reported as correlated heavy hitter candidate.
Proof The algorithm determines a correlated heavy hitter candidate (x, y) only if the primary item x as been reported as primary frequent item candidate and if its estimated frequency is greater than the selection criterionf xy > φ 2 (f x − N k 1 ). We must prove that those tuples whose exact frequency is greater than the threshold f xy > φ 2 f x are reported by the algorithm and hence their estimated frequency is greater than the selection criterionf xy > φ 2 (f x − N k 1 ). If f xy > φ 2 f x is true, then f xy > φ 2 f x is also true since the stream summary S t provides an overestimation of the tuple frequency. Now, since x is reported as primary frequent candidate, from Theorem 1 we have that f x ≥f x − N k 1 and it holds that Since the frequency estimate is greater than the selection criterion, the tuple will be reported and this proves the first part of the theorem.
The second part of the theorem states that those items with an exact frequency such that f xy ≤ (φ 2 − k 2 φ 2 +k 1 k 2 (k 1 φ 1 −1) )f x will not be reported, hence we must prove that their estimate frequency is less than or equal to the selection criterion i.e., f xy ≤ φ 2 (f x − N k 1 ). Since the algorithm first filters the tuples retaining only the ones whose primary item belongs to the primary frequent item candidates, from Theorem 1 it follows that for all of the primary frequent candidates it holds that: To prove the theorem we start assuming the exact frequency is such that Due to the S t stream summary properties, the error of the tuple frequency estimate is bounded by N k 2 , so thatf xy − N k 2 ≤ f xy and it holds that: Since the frequency estimate is an overestimation (i.e., f x ≤f x ), using Eq. (15) we can write: Taking into account that the estimated frequency is less than the selection criterion, the corresponding tuple will not be reported, proving the theorem. Moreover, this theorem also implies that for all of the correlated heavy hitter candidates it holds that: ⊓ ⊔ Theorems 1 and 2 can be used for tuning the stream summary sizes k 1 and k 2 . The ACHH problem poses a constraint about the tolerance ǫ 1 on the number of primary frequent false positives and a corresponding constraint about the tolerance ǫ 2 on the number of correlated heavy hitter false positives. Therefore, k 1 and k 2 are also subject to the following constraints: C1 The ACHH problem does not admit false negatives, hence all of the real primary frequent items must be reported. The maximum number of primary frequent items is 1 C2 The ACHH problem allows primary false positives only with a tolerance given by ǫ 1 N , hence for all of the primary frequent candidates it must be f x ≥ (φ 1 − ǫ 1 )N . Using Theorem 1 we need to impose: C3 The ACHH problem does not admit false negatives, hence all of the real correlated heavy hitters must be reported. The maximum number of correlated heavy hitters is 1 C4 The ACHH problem allows correlated false positives only with a tolerance given by ǫ 2 f x , hence for all of the correlated heavy hitter candidates it must be f xy ≥ (φ 2 − ǫ 2 )f x . Using Theorem 2 we need to impose: Solving Eq. (24) w.r.t. k 2 , we have Since k 2 and k 1 represent the sizes of the stream summaries, both are positives integers. Therefore, a solution to Eq. (25) is feasible only when the left hand side term is positive. To summarize, the current constraint is expressed by the following equations: Constraint C1 can be ignored since it is already embodied by constraint C2; indeed, the problem requires that ǫ 1 < φ 1 . Constraint C3 can be ignored as well since it can be easily proved that for any value of the input parameters.
Introducing the terms β = 1 ǫ 2 φ 1 and γ = ǫ 2 +φ 2 ǫ 2 φ 1 , we have to determine k 1 and k 2 such that their sum is minimized subject to the following constraints: The optimal values for k 1 and k 2 are obtained by solving a constrained minimization problem. Introducing a variable substitution r = k 1 + k 2 and s = k 1 the constrained minimization problem is formulated as follows: From the last constraint we can deduce that the minimum value of r must belong to the curve r = s + β s s−γ which attains its minimum for s = γ + √ βγ. Taking into account both constraints on s, the minimum is reached when Therefore, the corresponding k 1 and k 2 values are These are the values set by Algorithm 1 in order to initialize the CSSCHH stream summaries data structure by using the minimum number of counters, and, consequently, of space required to solve the ACHH problem.

Space and Time complexity
In this section, we analyze the worst case time and space complexity of our algorithm. Regarding the initialization phase (Algorithm 1), the worst case complexity is clearly O(1) since initialization consists of just a few assignments, each one requiring at most O(1) time.
The update procedure (Algorithm 2) requires constant time as well. Indeed, each one of the two calls to SPACESAVINGUPDATE requires at most O(1).
Finally, a query (Algorithm 3) requires time at most O(k 1 + k 2 ). Indeed, the first part of the query is just a linear scan of the k 1 counters related to the primary stream summary S p , in which we check, for each counter, if the corresponding monitored item's frequency exceed the selection criterion. When the check succeeds, the item and its estimated frequency are added to the hash table F . Since checking the condition can be done in constant time, this part of the query requires time at most O(k 1 ).
Next, we inspect the correlated stream summary S t . Again, this is just a linear scan. For each counter, we retrieve the stored tuple (r, s), and its estimated frequency. Then, we search for the primary item r in F ; if the item belongs to F and if the condition required for the tuple (r, s) to be considered a CHH is verified, then we update the list C holding the CHHs that shall be returned to the user. Searching in F requires constant time (since F is implemented as an hash table), and verifying the CHH condition requires constant time as well, the second part of the query requires time at most O(k 2 ). It follows that, overall, the query requires in the worst case time at most O(k 1 + k 2 ).
Regarding the space complexity, it is clear that the total space required is at most O(k 1 + k 2 ), since we use k 1 counters for S p and k 2 counters for S t . More specifically, in order to express the space complexity with regard to the input parameters, we distinguish two cases as in Eq. (30). When 1/ǫ 1 ≤ γ + √ βγ, we have otherwise, for 1/ǫ 1 > γ + √ βγ, it holds that

Theoretical Comparison
In this section we compare MGCHH and our algorithm CSSCHH from a theoretical perspective, before presenting the results of the experiments that we have carried out. We begin by comparing the space complexity and how many counters are required by both algorithms to guarantee their error bounds.
In the former case the space complexity of MGCHH is O( ), and in the latter case its space complexity is O( 1 ǫ 1 ǫ 2 ) [20]. MGCHH requires a total of s 1 + (s 1 s 2 ) counters, since the algorithm consists of a nested application of the Frequent algorithm: besides the s 1 counters for primary frequent items, there are s 1 s 2 counters for correlated items. Indeed, for each primary counter there is an entire summary consisting of s 2 counters.
Our CSSCHH algorithm requires k 1 = max 1 ǫ 1 , γ + √ βγ counters for the primary frequent items and k 2 = β k 1 k 1 −γ for the correlated frequent items, where β = 1 ǫ 2 φ 1 and γ = ǫ 2 +φ 2 ǫ 2 φ 1 . As shown in the previous section, the space complexity of our algorithm is O It is immediate verifying that our algorithm requires asymptotically less space than MGCHH. From a practical perspective, it's worth noting here that MGCHH is also subject to the constraint ǫ 1 < φ 1 /2, whilst our algorithm is not. Figure 1 depicts the number of counters required by MGCHH and CSSCHH (using a logarithmic scale on the z axis) fixing φ 1 = 0.01, φ 2 = 0.01 and letting ǫ 1 varying up to φ 1 /2, ǫ 2 varying up to φ 2 .

Fig. 1: Counters required by MGCHH and CSSCHH
As shown by the two surfaces, CSSCHH requires several orders of magnitude less counters than MGCHH. Moreover, we expect MGCHH to be slower with regard to CSSCHH. Indeed, every update step, in which the incoming primary stream item is not monitored and all of the s 1 counters are full, requires not only decrementing all of the s 1 counters (as in the Frequent algorithm), but also, for each one of them, MGCHH must randomly select a correlated item and decrease its frequency as well. Now, we consider and discuss the accuracy of MGCHH. Being based on the Frequent algorithm, we know that, overall, its accuracy shall be lower than the accuracy provided by CSSCHH which is, instead, based on the Space Saving algorithm. Indeed, it is well known that Space Saving is more accurate than Frequent [8,22]. In the next section we shall experimentally see how much faster and accurate CSSCHH is with regard to MGCHH.

Experimental results
In order to compare and evaluate our CSSCHH algorithm against MGCHH we have implemented them in C++. The source code has been compiled using the clang c++ compiler v8.0 on Mac OS X v10.12 with the following flags: -Os -std=c++14. We recall here that, on Mac OS X, the optimization flag -Os provides better optimization than the -O3 flag and is the standard for building the release build of an application. The tests have been carried out on a machine equipped wth 16 GB of RAM and a 3.2 GHz quad-core Intel Core i5 processor with 6 MB of cache level 3.
The items in the synthetic datasets used in our experiments are distributed according to the Zipf distribution. In each one of the experiments, the execution have been repeated 10 times using a different seed for the pseudo-random number generator used for creating the input data stream (using the same seeds in the corresponding executions of different algorithms). For each input distribution generated, the results have been averaged over all of the runs. The input items are 32 bits unsigned integers. Table 1 reports all of the experiments on synthetic datasets that have been carried out.
We have also experimented using a real dataset, namely Worldcup'98. This dataset is publicly available 1 and stores information related to the requests made to the World Cup web site during the 1998 tournament. For each request, the dataset includes a ClientID (which is a unique integer identifier for the client that issued the request) and an ObjectID (again, a unique integer identifier for the requested URL). In this experiment we determine correlated heavy hitters between ClientID and ObjectID pairs, treating ClientID as the primary items, and ObjectID as the secondary item. Owing to the huge size of the full dataset, we used a subset of the available data, i.e., the data from day 41 to day 46 of the competition. Table 3 reports the statistical characteristics of the real dataset.
Regarding synthetic datasets, we vary the input data stream size (n, in millions), the skew of the zipfian distribution (ρ), the total space used (measured in MegaBytes) and the φ 1 and φ 2 support thresholds. The value of the remaining parameters are fixed and reported in each individual plot. Regarding the total space used, it is worth noting here that, for MGCHH, a counter (related to either a primary or a correlated item) requires 4 bytes to store the monitored item (an unsigned int) and 8 bytes to store its estimated frequency (a long int), for a total of 12 bytes. On the other hand, for CSSCHH a counter related to primary items requires 12 bytes as well, but a counter monitoring a tuple (x, y) requires instead 4 bytes for x, 4 bytes for y and 8 bytes to store the estimated frequency, for a total of 16 bytes. Therefore, the total space used by MGCHH is 12(s 1 + s 1 s 2 ) bytes, whilst the total space used by CSSCHH is 12k 1 + 16k 2 bytes. The test related to the space used is carried out by assigning to both algorithm exactly the same space (measured in MegaBytes) in order to fairly compare both algorithms and to understand how the algorithms behave when performing under exactly the same conditions (with regard to the space used). Therefore, the allocated space determines the number of counters to be used correspondingly by the algorithms. In all of the other tests, we preserved this property choosing s 1 , s 2 , k 1 and k 2 such that 12k 1 + 16k 2 = 12(s 1 + s 1 s 2 ) and k 1 = s 1 . Table 2 reports the counters corresponding to the space used in the experiments.
We begin our analysis discussing the results for synthetic datasets. The recall is the total number of true frequent items reported over the number of frequent items given by an exact algorithm. Therefore, an algorithm is correct iff its recall is equal to one. Since the algorithms under test are based respectively on Frequent (MGCHH) and on Space Saving (CSSCHH), their recall is always one if they are allowed to use enough counters. In all of the test we used a number of counters s 1 and k 1 greater than 1 φ 1 for the primary items and a number of counters for correlated items greater that 1 φ 2 for s 2 and greater than 1 φ 1 φ 2 for k 2 . This guarantees both algorithms to reach a recall equal to one in every case. The plots on the recall have not been reported in the paper.
Next, we analyze the accuracy, beginning with the precision attained (with regard to the CHHs). Since precision is defined as the total number of true frequent items reported over the total number of items reported, this metric quantifies the number of false positives outputted by an algorithm. It follows that, from this point of view, the algorithm's precision should ideally be one. As shown in Figure 2, CSSCHH clearly outperforms MGCHH with regard to the precision. Indeed, CSSCHH is consistently able to provide one or near one precision in all of the tests carried out, whilst MGCHH lags far behind.
Accuracy is also related to the absolute and relative errors on the frequency estimate committed by the algorithms. Denoting with f the exact frequency of a CHH and withf the corresponding frequency reported by an algorithm, then the absolute error is, by definition, the difference f −f .
Similarly, the relative error is defined as |f−f| f and the average relative error is derived by averaging the relative errors over all of the measured frequencies. Figures 3 and 4 depict respectively absolute and relative errors committed by the algorithms (with regard to CHHs). Each single plot reports both the maximum and the mean values attained by both algorithms. Again, it is immediate verifying that CSSCHH is extremely accurate in all of the cases, with absolute and relative errors always equal to zero. On the contrary, MGCHH estimates are clearly affected by significant error.
Finally, we evaluated the algorithm with regard to their speed in processing stream items. Figure 5 shows the speed attained, reported as updates per millisecond. Again, CSSCHH outperforms MGCHH, being consistently much faster in all of the cases. In particular, MGCHH is more than three times faster in all of the tests that have been carried out, except the tests in which we vary the skew of the input distribution and the space we allow to be used. Anyway, as shown by the plots, CSSCHH is always faster than MGCHH.
Next, we compare MGCHH and CSSCHH using the real dataset Worldcup'98. Figures 6 and 7 depict the results obtained respectively when varying the space allowed and the φ 2 threshold (fixing the φ 1 threshold). Table 4 reports the counters corresponding to the space used. It is worth noting here that, owing to the skewness of the dataset being really low (see Table 3), we fixed φ 1 to a low value (0.001) and φ 2 varying from 0.001 to 0.01, since otherwise no (or just a few) correlated heavy hitters exist. As shown, both algorithms exhibit the same behaviour already observed on synthetic datasets, with CSSCHH clearly outperforming MGCHH with regard to every metric under consideration.    We conclude by noting that the experimental results fully confirm our theoretical expectations reported in the previous section. CSSCHH is more accurate in terms of both precision, absolute and relative error committed. Our algorithm is also faster than MGCHH. Therefore, CSSCHH is a better alternative to MGCHH for mining correlated heavy hitters.

Conclusions
In this paper, we have studied the problem of mining Correlated Heavy Hitters from a two-dimensional data stream. We have presented CSSCHH, a new counterbased algorithm for tracking CHHs, and formally proved its error bounds and correctness. We have compared our algorithm to MGCHH, a recently designed deterministic algorithm based on the Misra-Gries algorithm both from a theoretical