Towards Optimal Cardinality Estimation of Unions and Intersections with Sketches

Towards Optimal Cardinality Estimation of Unions and Intersections with Sketches

Towards Optimal Cardinality Estimation of Unions and Intersections with Sketches Daniel Ting Facebook 1730 Minor Ave Seattle, WA [email protected] ABSTRACT operations on sketches and derive cardinality estimates that Estimating the cardinality of unions and intersections of sets are optimal or nearly optimal. is a problem of interest in OLAP. Large data applications This problem of estimating the number of distinct ele- often require the use of approximate methods based on small ments in a dataset in a memory efficient manner appears sketches of the data. We give new estimators for the cardi- in a wide range of applications. For example, in data ana- nality of unions and intersection and show they approximate lytics and OLAP, a web company may count distinct users an optimal estimation procedure. These estimators enable accessing a service [21]. The summarizations are used in the improved accuracy of the streaming MinCount sketch networking to detect denial of service attacks by counting to be exploited in distributed settings. Both theoretical network flows [15], and in databases to optimize query plans and empirical results demonstrate substantial improvements [22]. Other applications include graph analysis where they over existing methods. are used to estimate the diameter of a graph [9], [5]. The extended problem for unions has particular impor- tance in OLAP and distributed settings. The streaming CCS Concepts cardinality estimator given by [23], [10] is optimal in the •Mathematics of computing ! Probabilistic algo- sense that no unbiased estimator has lower asymptotic vari- rithms; •Theory of computation ! Sketching and ance. This is much stronger than typical space-complexity sampling; •Computing methodologies ! Distributed results in the theory literature [2], [19] that just guarantee algorithms; an optimal rate. It guarantees optimality of the constant in front of the rate. This optimality is evident in practice as the estimators require half the space of existing meth- Keywords ods to achieve the same error on MinCount sketches. The cardinality estimation; data sketching; randomized algorithms streaming estimator, however, cannot be applied directly in distributed settings. In a map-reduce setting, the map- pers computing efficient streamed sketch summaries need a 1. INTRODUCTION method to combine them at a reducer. A union operation Consider a dataset D. The basic approximate distinct on the sketches would allow the efficiency gains to be trans- count problem is to construct a memory efficient summa- fered to distributed settings and turn the streamed sketch rization S of D and to estimate the cardinality of the set into a mergeable summary [1]. These efficiency gains can of unique items A using just the sketch S. Under this ba- be tremendous as empirical results show efficient cardinal- sic formulation, a sketch answers a cardinality question that ity estimation for unions can reduce variance and the space must be specified before computing the sketch. We consider requirements by an order of magnitude when many sketches the extended problem of estimating the cardinality of set are merged. unions, jA1 [A2j, and intersections, jA1 \A2j, using multiple In OLAP settings, one is often interested in cardinality sketches. This has two important consequences. First, com- estimates on multi-dimensional data, for example counting binatorially many cardinality questions can be accurately the number of users accessing a web service by geographic answered by sketches. Second, the significant improvements location, time window, and other factors [21]. This results in accuracy using the HIPS or optimal martingale estimator in exponentially many cardinalities to estimate. Unions and of [10] and [23] can be realized in distributed settings. More intersections allow a limited number of sketches to answer a specifically, we wish to define union [~ and intersection \~ multitude of cardinality questions. Cardinality estimates for intersections are not as well stud- Permission to make digital or hard copies of all or part of this work for personal or ied as for unions. While most sketches for approximate dis- classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation tinct counting have a natural but inefficient union operation, on the first page. Copyrights for components of this work owned by others than the they do not have one for intersections. Intersection car- author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or dinality estimates are often computed using the inclusion- republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]. exclusion principle or by using Jaccard similarity [13], [4] KDD ’16, August 13 - 17, 2016, San Francisco, CA, USA when an estimator is available. These methods still require c 2016 Copyright held by the owner/author(s). Publication rights licensed to ACM. first accurately estimating the cardinality of the union or ISBN 978-1-4503-4232-2/16/08. $15.00 the Jaccard similarity of a set with the union. DOI: http://dx.doi.org/10.1145/2939672.2939772 Our contributions are as follows. We introduce two tech- [12] uses over twice the memory as that used in [8]. The dis- niques for computing unions and intersections on approx- advantage of using the optimal streaming methods described imate distinct counting sketches: pseudo-likelihood based in [23] and [10] is that they require the data to arrive in a methods and re-weighting component estimators. These are single stream. They are not immediately applicable in dis- applied to Streaming MinCount sketches in this paper but tributed settings or in OLAP settings where the sketches are may be applied to other sketches as well. The resulting es- pre-aggregations that need to be further merged. timators demonstrate state of the art performance on both real and synthetic datasets. The pseudo-likelihood based 3. NAIVE ESTIMATION MinCount method is conjectured to be asymptotically ef- ficient as it is nearly the same as the asymptotically ef- We first consider basic estimation procedures for unions ficient maximum likelihood estimator. This establishes a and intersections on distinct counting sketches. Many sketches nearly ideal baseline for comparison. Re-weighted compo- used in approximate distinct counting have a natural union nent estimators are much simpler to implement and gener- operation. For example, the LPCA sketch is a bitmap and alize, and they are empirically shown to be as efficient as is equivalent to a Bloom filter with the number of hashes the pseudo-likelihood based estimators. We also derive vari- k = 1. Taking the union of LPCA sketches simply takes the ance estimates which allow confidence intervals to be given bitwise OR of the sketches. The resulting sketch is identi- for the cardinality estimates. In the special case where the cal to the sketch computed on the union of the original sets. streams are different permutations of the same set, we show This property holds for other sketches such as HyperLogLog that merging the streaming estimates yields a more accu- [16] and MinCount [18] as well. In other words, there is an ~ ~ rate estimate than the estimator on a single stream. Thus, operation [ such that S(A1)[S(A2) = S(A1 [ A2) where S unlike existing methods, the union operation on streaming is the function that generates a sketch from a streamed set. sketches exploits information about the order of elements in For notational convenience, we will denote Si = S(Ai). each stream. The variance after averaging over all possible Unlike the union, typically no natural intersection oper- orderings is shown to be 2=3 the variance of the streaming ation exists for approximate distinct counting sketches. A MinCount estimator. In addition to improved estimation, simple method to obtain cardinality estimates for the inter- the resulting methods yield mergeable summaries [1] under section is to use union estimates and the inclusion-exclusion both union and intersection operations unlike existing meth- principle, jA1 \ A2j = jA1j + jA2j − jA1 [ A2j. In the case ^ ods. where there is an estimate J(S1;S2) for the Jaccard similar- ity, two existing intersection cardinality estimator are given 2. EXISTING BASIC METHODS by [4] and [13]. Throughout, we will use a hat to denote estimated quantities, with N^(S) denoting a cardinality esti- The basic approximate distinct counting problem has been mate using sketch S. The naive and Jaccard based estimates well studied in the literature beginning with the seminal pa- of the cardinality of the union and intersection are given by per by Flajolet and Martin [17]. Methods include Linear Probabilistic Counting (LPCA) [25], HyperLogLog [16], the N^naive(S1[~S2) = N^(S(A1 [ A2)) (1) Multiresolution Bitmap [15], the S-bitmap [7], α-stable dis- N^ (S \~S ) = N^(S ) + N^(S ) − N^(S(A [ A )) tribution methods [12], and MinCount [18]. Kane, et al naive 1 2 1 2 1 2 [19] also gave a method that is optimal in terms of space- N^Jaccard;1(S1\~S2) = J^(S1;S2)N^(S1[~S2) complexity. J^(S ;S ) As described in [23], all these methods generate a stochas- N^ (S \~S ) = 1 2 N^(S ) + N^(S ) Jaccard;2 1 2 ^ 1 2 tic process called the area process that is governed solely by 1 + J(S1;S2) the number of distinct elements encountered. A sketch S These estimation strategies turn out to be suboptimal. can be mapped to a set R(S) ⊂ (0; 1) called the remaining For the intersection estimators, one reason is that the error area. Given a random hash, each element in a stream is is often roughly proportional to the size of the union or the hashed to some value U. If U is still in the remaining area, larger set, while a good procedure should give error that is U 2 R(S), the sketch is updated by cutting out a portion bounded by the size of the smaller set.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us