Jump to content

Flajolet–Martin algorithm

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 2001:878:200:1053:fc84:e4b1:5621:e0ec (talk) at 08:14, 10 November 2014 (Space missing in name). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The Flajolet-Martin algorithm is an algorithm for approximating the number of distinct elements in a stream with a single pass and space-consumption which islogarithmic in the maximum number of possible distinct elements in the stream. The algorithm was introduced by Philippe Flajolet and G. Nigel Martin in their 1984 paper "Probabilistic Counting Algorithms for Data Base Applications".[1] Later it has been refined in the papers "LogLog counting of large cardinalities" by Marianne Durand and Philippe Flajolet,[2] and "HyperLogLog: The analysis of a near-optimal cardinality estimation algorithm" by Philippe Flajolet et al.[3]

In their 2010 paper "An optimal algorithm for the distinct elements problem",[4] Daniel M. Kane, Jelani Nelson and David P. Woodruff gives an improved algorithm whichuses nearly optimal space, and has optimal O(1)update and reporting times.

The algorithm

Assume that we are given a hash function which maps input to integers in the range andwhere the outputs are sufficiently uniformly distributed. Note that the set of integers from 0 to corresponds to the set of binary strings of length . For any non-negative integer , define to be the -th bit in the binary representation of , such that:

We then define a function which outputs the position of the least significant 1-bit in the binary representation of :

where . Note that with the above definition we areusing 0-indexing for the positions.For example, since the least significant bit is a 1, and since the least significant 1-bit is at the third position. At this point, note that under the assumption that the output of our hash-functionis uniformly distributed, then the probability of observing a hash-output ending with (a one, followed by zeroes) is since this corresponds to flipping heads and then a tail with a fair coin.

Now the Flajolet-Martin algorithm for estimating the cardinality of a multiset is as follows:

  1. Initialize a bit-vector BITMAP to be of length and contain all 0's.
  2. For each element in :
    1. index = .
    2. .
  3. Let denote the smallest index such that .
  4. Estimate the cardinality of as where .

The idea is that if is the number of distinct elements in the multiset , then is accessed approximately times, is accessed approximately times and so on. Consequently if then is almost certainly 0, and if then is almost certainly 1. If then can be expected to be either 1 or 0.

The correction factor is found by calculations which can be found in the original paper.

Improving accuracy

A problem with the Flajolet-Martin algorithm in the above form, is that the results vary a lot. A common solution is to run the algorithm multiple times with different hash-functions, and combine the results from the different runs. One idea is to take the mean of the results together from each hash-function, obtaining a single estimate of the cardinality. The problem with this is that averaging is very susceptible to outliers (which are likely here). A different idea is to use the median which is less prone to be influences by outliers. The problem with this is that the results can only take form , where is integer. A common solution is to combine both the mean and the median: Create hash-functions and split them into distinct groups (each of size ). Within each group use the median for aggregating together the results, and finally take the mean of the group estimates as the final estimate.

References

  1. ^ Attention: This template ({{cite doi}}) is deprecated. To cite the publication identified by doi:10.1016/0022-0000(85)90041-8, please use {{cite journal}} (if it was published in a bona fide academic journal, otherwise {{cite report}} with |doi=10.1016/0022-0000(85)90041-8 instead.
  2. ^ Attention: This template ({{cite doi}}) is deprecated. To cite the publication identified by doi:10.1007/978-3-540-39658-1_55, please use {{cite journal}} (if it was published in a bona fide academic journal, otherwise {{cite report}} with |doi=10.1007/978-3-540-39658-1_55 instead.
  3. ^ Philippe Flajolet, Éric Fusy, Olivier Gandouet, Frédéric Meunier (2007). "Hyperloglog: The analysis of a near-optimal cardinality estimation algorithm" (PDF). Discrete Mathematics and Theoretical Computer Science: 127–146. CiteSeerX.psu:10.1.1.76.4286.{{cite journal}}: CS1 maint: multiple names: authors list (link)
  4. ^ Attention: This template ({{cite doi}}) is deprecated. To cite the publication identified by doi:10.1145/1807085.1807094, please use {{cite journal}} (if it was published in a bona fide academic journal, otherwise {{cite report}} with |doi=10.1145/1807085.1807094 instead.

Additional sources