New Cardinality Estimation Methods for Hyperloglog Sketches

New Cardinality Estimation Methods for Hyperloglog Sketches

New Cardinality Estimation Methods for HyperLogLog Sketches Otmar Ertl Linz, Austria [email protected] ABSTRACT Algorithm 1 Insertion of a data element D into a HLL sketch. All ¹ º is work presents new cardinality estimation methods for data registers K = K1;:::; Km start from zero. sets recorded by HyperLogLog sketches. A simple derivation of the procedure InsertElement(D) original estimator was found, that also gives insight how to correct ha1;:::; ap ;b1;:::;bq i2 ¹p + qº-bit hash value of D its deciencies. e result is an improved estimator that is unbiased i 1 + ha1;:::; ap i2 over the full cardinality range, is easy computable, and does not k min¹fs j bs = 1g [ fq + 1gº rely on empirically determined data as previous approaches. Based if k > Ki then on the maximum likelihood principle a second unbiased estimation Ki k method is presented which can also be extended to estimate car- end if dinalities of union, intersection, or relative complements of two end procedure sets that are both represented as HyperLogLog sketches. Experi- mental results show that this approach is more precise than the conventional technique using the inclusion-exclusion principle. method of choice. It needs more space than the HLL algorithm, but also allows set manipulations like construction of intersections, 1 INTRODUCTION relative complements, or unions [8]. e laer operation is the only one that is natively supported by HLL sketches. A sketch Counting the number of distinct elements in a data stream or large that represents the set operation result is not always needed. One datasets is a common problem in big data processing. In principle, approach to estimate the corresponding result cardinality directly is nding the number of distinct elements n with a maximum relative based on the inclusion-exclusion principle, which however can lead error ε in a data stream requires O¹nº space [1]. However, proba- to large errors, especially if the result is small compared to the input bilistic algorithms that achieve the requested precision only with set sizes [8]. erefore, it was proposed to combine HLL sketches high probability are able to drastically reduce space requirements. with minwise hashing [7, 19], which improves the estimation error, Many dierent probabilistic algorithms have been developed over even though at the expense of signicant more space consumption. the past two decades [18, 23] until a theoretically optimal algorithm It was recently pointed out without special focus on HLL sketches, was nally found [14]. Although this algorithm achieves the opti- that the application of the maximum likelihood (ML) method to the mal space complexity of O¹ε−2 +lognº [1, 13], it is not very ecient joint likelihood function of two probabilistic data structures leads in practice [23]. to beer cardinality estimates for intersections [24]. More practicable and already widely used in many applications is the HyperLogLog (HLL) algorithm [11] with a near-optimal space complexity O¹ε−2 log logn + lognº. A big advantage of the HLL 2 HYPERLOGLOG DATA STRUCTURE algorithm is that corresponding sketches can be easily merged, e HLL algorithm collects information of incoming elements into which is a requirement for distributed environments. Unfortunately, a very compact sketching data structure, that nally allows to esti- the originally proposed estimation method has some problems mate the number of distinct elements. e data structure consists to guarantee the same accuracy over the full cardinality range. of m = 2p registers. All registers start with zero initial value. e erefore, a couple of variants have been developed to correct the insertion of a data element into a HLL data structure requires the original estimate by empirical means [12, 21, 22]. calculation of a ¹p +qº-bit hash value. e leading p bits of the hash arXiv:1706.07290v1 [cs.DS] 20 Jun 2017 An estimator for HLL sketches, that does not rely on empirical value are used to select one of the 2p registers. Among the next data and that signicantly improves the estimation error, is the following q bits, the position of the rst 1-bit is determined which historic inverse probability estimator [5, 23]. It trades memory is a value in the range »1;q + 1¼. e value q + 1 is used, if all q bits eciency for mergeability. e estimator needs to be continuously are zeros. If the position of the rst 1-bit exceeds the current value updated while inserting elements and the estimate depends on the of the selected register, the register value is replaced. e complete insertion order. Moreover, the estimator cannot be further used aer update procedure is shown in Algorithm 1. merging two sketches, which limits its application to single data A HLL sketch can be characterized by the parameter pair ¹p;qº streams. If this restriction is acceptable, the self-learning bitmap where the precision parameterp p controls the relative estimation [4], which provides a similar trade-o and also needs less space error which scales like 1/ m [11] while q denes the possible range than the original HLL method, could be used alternatively. for registers which is f0; 1;:::;q + 1g. e case q = 0 corresponds Sometimes not only the number of distinct elements but also a to a bit array and shows that the HLL algorithm can be regarded as sample of them is needed in order to allow later ltering according generalization of linear counting [26]. e number of consumed to some predicate and estimating the cardinalities of corresponding hash value bits p + q denes the maximum cardinality that can be subsets. In this case the k-minimum values algorithm [2, 6] is the tracked. Obviously, if the cardinality reaches values in the order of 2p+q , hash collisions will become more apparent and the estimation e harmonic mean was found to work best as it is less sensitive to error will increase. outliers. e result is the so-called raw estimator given by Algorithm 1 has some properties which are especially useful for 2 m αmm distributed data streams. First, the insertion order of elements has nˆraw = αm = : (2) 1 1 Íq+1 −k K + ::: + K C no inuence on the nal sketch state. Furthermore, any two HLL m2 1 m2 m k=0 k 2 ¹ º sketches with same parameters p;q representing two dierent Here αm is a bias correction factor [11] which can be well approx- sets can be easily merged. e sketch that represents the union of 1 imated by α1 := limm!1 αm = 2 log 2 in practice, because the both sets can be constructed by taking the register-wise maximum additional bias is negligible compared to the overall estimation values. error. e state of a HLL sketch is described by the vector K = To investigate the estimation error of the raw estimator and other ¹ ;:::; º K1 Km . Under the assumption of a uniform hash function estimation approaches discussed in the following, we lled 10 000 the inserted elements are distributed over all m registers accord- HLL sketches with up to 50 billion unique elements. To speed up / ing to a multinomial distribution with equal probabilities 1 m [11]. computation we assumed a uniform hash function whose values can erefore, any permutation of K is equally likely for a given car- be simulated by random numbers. We used the Mersenne Twister ;:::; dinality. us, the order of register values K1 Km contains random number generator with a state size of 19 937 bits from the no information about the cardinality which makes the multiset C++ standard library. f ;:::; g K1 Km a sucient statistic for n. Since the values of the Fig. 1 shows the distribution of the relative error of the raw » ; ¼ multiset are all in the range 0 q + 1 , the multiset can also be writ- estimator as function of the true cardinality for p = 12 and q = 20. f g C0 C1 ··· Cq ¹ ºCq+1 ten as K1;:::; Km = 0 1 q q + 1 where Ck is the Corrections for small and large cardinalities have been proposed multiplicity of value k. As a consequence, the multiplicity vector to reduce the obvious bias. For small cardinalities the HLL sketch ¹ º C := C0;:::;Cq+1 , which corresponds to the register value his- can be interpreted as bit array by distinguishing between registers togram, is also a sucient statistic for the cardinality. By denition + with zero and nonzero values. is allows using the linear counting Íq 1 C = m we have k=0 k . cardinality estimator [26] 2.1 Poisson Approximation nˆsmall = m log¹m/C0º: (3) e multinomial distribution is the reason that register values are e corresponding estimation error is small for small cardinalities statistically dependent and that further analysis is dicult. For and is shown in Fig. 2. It was proposed to use this estimator as 5 5 simplication a Poisson model can be used [11], which assumes long as nˆraw ≤ 2m where the factor 2 was empirically determined p+q that the cardinality itself is distributed according to a Poisson distri- [11]. For large cardinalities in the order of 2 , for which a lot bution n ∼ Poisson¹λº. Under the Poisson model the register values of registers are already in a saturated state, meaning that they are independent and identically distributed according to have reached the maximum possible value q + 1, the raw estimator underestimates cardinalities. For the 32-bit hash value case ¹p +q = 8 >0 k < 0 32º, which was considered in [11], following correction formula ><> − λ 32 8 P¹K ≤ kjλº = e m2k 0 ≤ k ≤ q (1) was proposed if nˆraw > 2 /30 ≈ 1:43 × 10 to take these saturated > registers into account >1 k > q: : nˆ = −232 log¹1 − nˆ /232º: (4) e Poisson approximation makes it easier to nd an estimator large raw λˆ = λˆ¹Kº for the Poisson rate λ than for the cardinality n under the e relative estimation error of the original method that includes xed-size model.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 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