Streaming algorithm - Heavy Hitter

- 05.31

End of Summer Banger! DJ
photo src: knyce7.podomatic.com

In computer science, streaming algorithms are algorithms for processing data streams in which the input is presented as a sequence of items and can be examined in only a few passes (typically just one). These algorithms have limited memory available to them (much less than the input size) and also limited processing time per item.

These constraints may mean that an algorithm produces an approximate answer based on a summary or "sketch" of the data stream in memory.


AnaCheri-HH-05-1500px | Heavy Hitter Wheels
photo src: www.heavyhitterwheels.com


Maps, Directions, and Place Reviews



History

Though streaming algorithms had already been studied by Munro and Paterson as early as 1980, as well as Philippe Flajolet and G. Nigel Martin in 1982/83, the field of streaming algorithms was first formalized and popularized in a 1996 paper by Noga Alon, Yossi Matias, and Mario Szegedy. For this paper, the authors later won the Gödel Prize in 2005 "for their foundational contribution to streaming algorithms." There has since been a large body of work centered around data streaming algorithms that spans a diverse spectrum of computer science fields such as theory, databases, networking, and natural language processing.

Semi-streaming algorithms were introduced in 2005 as an extension of streaming algorithms that allows for a constant or logarithmic number of passes over the dataset [1].


Heavy Hitter Video



Models

In the data stream model, some or all of the input data that are to be operated on are not available for random access from disk or memory, but rather arrive as one or more continuous data streams.

Streams can be denoted as an ordered sequence of points (or "updates") that must be accessed in order and can be read only once or a small number of times.

Much of the streaming literature is concerned with computing statistics on frequency distributions that are too large to be stored. For this class of problems, there is a vector a = ( a 1 , ... , a n ) {\displaystyle \mathbf {a} =(a_{1},\dots ,a_{n})} (initialized to the zero vector 0 {\displaystyle \mathbf {0} } ) that has updates presented to it in a stream. The goal of these algorithms is to compute functions of a {\displaystyle \mathbf {a} } using considerably less space than it would take to represent a {\displaystyle \mathbf {a} } precisely. There are two common models for updating such streams, called the "cash register" and "turnstile" models.

In the cash register model each update is of the form ? i , c ? {\displaystyle \langle i,c\rangle } , so that a i {\displaystyle a_{i}} is incremented by some positive integer c {\displaystyle c} . A notable special case is when c = 1 {\displaystyle c=1} (only unit insertions are permitted).

In the turnstile model each update is of the form ? i , c ? {\displaystyle \langle i,c\rangle } , so that a i {\displaystyle a_{i}} is incremented by some (possibly negative) integer c {\displaystyle c} . In the "strict turnstile" model, no a i {\displaystyle a_{i}} at any time may be less than zero.

Several papers also consider the "sliding window" model. In this model, the function of interest is computing over a fixed-size window in the stream. As the stream progresses, items from the end of the window are removed from consideration while new items from the stream take their place.

Besides the above frequency-based problems, some other types of problems have also been studied. Many graph problems are solved in the setting where the adjacency matrix or the adjacency list of the graph is streamed in some unknown order. There are also some problems that are very dependent on the order of the stream (i.e., asymmetric functions), such as counting the number of inversions in a stream and finding the longest increasing subsequence.


26x10 Heavy Hitters HH-12 Chrome Wheels
photo src: www.elementwheels.com


Evaluation

The performance of an algorithm that operates on data streams is measured by three basic factors:

  • The number of passes the algorithm must make over the stream.
  • The available memory.
  • The running time of the algorithm.

These algorithms have many similarities with online algorithms since they both require decisions to be made before all data are available, but they are not identical. Data stream algorithms only have limited memory available but they may be able to defer action until a group of points arrive, while online algorithms are required to take action as soon as each point arrives.

If the algorithm is an approximation algorithm then the accuracy of the answer is another key factor. The accuracy is often stated as an ( ? , ? ) {\displaystyle (\epsilon ,\delta )} approximation meaning that the algorithm achieves an error of less than ? {\displaystyle \epsilon } with probability 1 - ? {\displaystyle 1-\delta } .


photo src: www.heavyhitterwheels.com


Applications

Streaming algorithms have several applications in networking such as monitoring network links for elephant flows, counting the number of distinct flows, estimating the distribution of flow sizes, and so on. They also have applications in databases, such as estimating the size of a join.


2015 Heavy Hitter Available NOW! Ă‚» SE Bikes Home
photo src: www.sebikes.com


Some streaming problems

Frequency moments

The kth frequency moment of a set of frequencies a {\displaystyle \mathbf {a} } is defined as F k ( a ) = ? i = 1 n a i k {\displaystyle F_{k}(\mathbf {a} )=\sum _{i=1}^{n}a_{i}^{k}} .

The first moment F 1 {\displaystyle F_{1}} is simply the sum of the frequencies (i.e., the total count). The second moment F 2 {\displaystyle F_{2}} is useful for computing statistical properties of the data, such as the Gini coefficient of variation. F ? {\displaystyle F_{\infty }} is defined as the frequency of the most frequent item(s).

The seminal paper of Alon, Matias, and Szegedy dealt with the problem of estimating the frequency moments.

Calculating Frequency Moments

A direct approach to find the frequency moments requires to maintain a register mi for all distinct elements ai ? (1,2,3,4,...,N) which requires at least memory of order ? ( N ) {\displaystyle \Omega (N)} . But we have space limitations and requires an algorithm that computes in much lower memory. This can be achieved by using approximations instead of exact values. An algorithm that computes an (?,?)approximation of Fk, where F'k is the (?,?)- approximated value of Fk. Where ? is the approximation parameter and ? is the confidence parameter.

Calculating F0 (Distinct Elements in a DataStream)
FM-Sketch Algorithm

Flajolet et al. in introduced probabilistic method of counting which was inspired from a paper by Robert Morris Counting large numbers of events in small registers. Morris in his paper says that if the requirement of accuracy is dropped, a counter n can be replaced by a counter log n which can be stored in log log n bits. Flajolet et al. in improved this method by using a hash function h which is assumed to uniformly distribute the element in the hash space (a binary string of length L).

Let bit(y,k) represent the kth bit in binary representation of y

Let ? ( y ) {\displaystyle \rho (y)} represents the position of least significant 1-bit in the binary representation of yi with a suitable convention for ? ( 0 ) {\displaystyle \rho (0)} .

Let A be the sequence of data stream of length M whose cardinality need to be determined. Let BITMAP [0...L - 1] be the

hash space where the ?(hashedvalues) are recorded. The below algorithm the determines approximate cardinality of A.

  Procedure FM-Sketch:        for i in 0 to L - 1 do          BITMAP[i]:=0       end for      for x in A: do          Index:=?(hash(x))          if BITMAP[index]=0 then BITMAP[index]:=1          end if      end for      B:= Position of left most 0 bit of BITMAP[]       return 2^B  

If there are N distinct elements in a data stream.

  • For i >> log ( N ) {\displaystyle i\gg \log(N)} then BITMAP[i] is certainly 0
  • For i << log ( N ) {\displaystyle i\ll \log(N)} then BITMAP[i] is certainly 1
  • For i ? log ( N ) {\displaystyle i\approx \log(N)} then BITMAP[i] is a fringes of 0's and 1's
K-Minimum Value Algorithm

The previous algorithm describes the first attempt to approximate F0 in the data stream by Flajolet and Martin. Their algorithm picks a random hash function which they assume to uniformly distribute the hash values in hash space.

Bar-Yossef et al. in, introduces k-minimum value algorithm for determining number of distinct elements in data stream. They uses a similar hash function h which can be normalized to [0,1] as h : [ m ] -> [ 0 , 1 ] {\displaystyle h:[m]\rightarrow [0,1]} . But they fixed a limit t to number of values in hash space. The value of t is assumed of the order O ( 1 ? 2 ) {\displaystyle O\left({\dfrac {1}{\varepsilon _{2}}}\right)} (i.e. less approximation-value ? requires more t). KMV algorithm keeps only t-smallest hash values in the hash space. After all the m values of stream are arrived, ? = M a x ( h ( a i ) ) {\displaystyle \upsilon =\mathrm {Max} (h(a_{i}))} is used to calculate F 0 ? = t ? {\displaystyle F'_{0}={\dfrac {t}{\upsilon }}} . That is, in a close-to uniform hash space, they expect at-least t elements to be less than O ( t F 0 ) {\displaystyle O\left({\dfrac {t}{F_{0}}}\right)} .

  Procedure 2 K-Minimum Value    Initialize first t values of KMV   for a in a1 to an do          if h(a) < Max(KMV) then                  Remove Max(KMV) from KMV set                  Insert h(a) to KMV           end if  end for   return t/Max(KMV)  
Complexity analysis of KMV

KMV algorithm can be implemented in O ( ( 1 ? 2 ) ? log ( m ) ) {\displaystyle O\left(\left({\dfrac {1}{\varepsilon _{2}}}\right)\cdot \log(m)\right)} memory bits space. Each hash value requires space of order O ( log ( m ) ) {\displaystyle O(\log(m))} memory bits. There are hash values of the order O ( 1 ? 2 ) {\displaystyle O\left({\dfrac {1}{\varepsilon _{2}}}\right)} . The access time can be reduced if we store the t hash values in a binary tree. Thus the time complexity will be reduced to O ( log ( 1 ? ) ? log ( m ) ) {\displaystyle O\left(\log \left({\dfrac {1}{\varepsilon }}\right)\cdot \log(m)\right)} .

Calculating Fk

Alon et al. in estimates Fk by defining random variables that can be computed within given space and time. The expected value of random variable gives the approximate value of Fk.

Let us assume length of sequence m is known in advance.

Construct a random variable X as follows:

  • Select ap be a random member of sequence A with index at p, a p = l ? ( 1 , 2 , 3 , ... , n ) {\displaystyle a_{p}=l\in (1,2,3,\ldots ,n)}
  • Let r = | { q : q >= p , a q = l } | {\displaystyle r=|\{q:q\geq p,a_{q}=l\}|} , represents the number of occurrences of l within the members of the sequence A following ap.
  • Random variable X = m ( r k - ( r - 1 ) k ) {\displaystyle X=m(r^{k}-(r-1)^{k})} .

Assume S1 be of the order O ( n 1 - 1 / k / ? 2 ) {\displaystyle O(n^{1-1/k}/\lambda ^{2})} and S2 be of the order O ( log ( 1 / ? ) ) {\displaystyle O(\log(1/\varepsilon ))} . Algorithm takes S2 random variable Y1,Y2,...,YS2 and outputs the median Y . Where Yi is the average of Xij where 1 <= j <= S1.

Now calculate expectation of random variable E(X).

Complexity of Fk

From the algorithm to calculate Fk discussed above, we can see that each random variable X stores value of ap and r. So, to compute X we need to maintain only log(n) bits for storing ap and log(n) bits for storing r. Total number of random variable X will be the S 1 * S 2 {\displaystyle S_{1}*S_{2}} .

Hence the total space complexity the algorithm takes is of the order of O ( k log 1 ? ? 2 n 1 - 1 k ( log n + log m ) ) {\displaystyle O\left({\dfrac {k\log {1 \over \varepsilon }}{\lambda ^{2}}}n^{1-{1 \over k}}\left(\log n+\log m\right)\right)}

Simpler approach to calculate F2

The previous algorithm calculates F 2 {\displaystyle F_{2}} in order of O ( n ( log m + log n ) ) {\displaystyle O({\sqrt {n}}(\log m+\log n))} memory bits. Alon et al. in simplified this algorithm using four-wise independent random variable with values mapped to { - 1 , 1 } {\displaystyle \{-1,1\}} .

This further reduces the complexity to calculate F 2 {\displaystyle F_{2}} to O ( log 1 ? ? 2 ( log n + log m ) ) {\displaystyle O\left({\dfrac {\log {1 \over \varepsilon }}{\lambda ^{2}}}\left(\log n+\log m\right)\right)}

Heavy hitters

Find the most frequent (popular) elements in a data stream. Some notable algorithms are:

  • Boyer-Moore majority vote algorithm
  • Karp-Papadimitriou-Shenker algorithm
  • Count-Min sketch
  • Sticky sampling
  • Lossy counting
  • Sample and Hold
  • Multi-stage Bloom filters
  • Count-sketch
  • Sketch-guided sampling

Event detection

Detecting events in data streams is often done using a heavy hitters algorithm as listed above: the most frequent items and their frequency are determined using one of these algorithms, then the largest increase over the previous time point is reported as trend. This approach can be refined by using exponentially weighted moving averages and variance for normalization.

Counting distinct elements

Counting the number of distinct elements in a stream (sometimes called the F0 moment) is another problem that has been well studied. The first algorithm for it was proposed by Flajolet and Martin. In 2010, D. Kane, J. Nelson and D. Woodruff found an asymptotically optimal algorithm for this problem. It uses O(?2 + log d) space, with O(1) worst-case update and reporting times, as well as universal hash functions and a r-wise independent hash family where r = ?(log(1/?) / log log(1/?)).

Entropy

The (empirical) entropy of a set of frequencies a {\displaystyle \mathbf {a} } is defined as F k ( a ) = ? i = 1 n a i m log a i m {\displaystyle F_{k}(\mathbf {a} )=\sum _{i=1}^{n}{\frac {a_{i}}{m}}\log {\frac {a_{i}}{m}}} , where m = ? i = 1 n a i {\displaystyle m=\sum _{i=1}^{n}a_{i}} .

Estimation of this quantity in a stream has been done by:

  • McGregor et al.
  • Do Ba et al.
  • Lall et al.
  • Chakrabarti et al.

Online learning

Learn a model (e.g. a classifier) by a single pass over a training set.

  • Feature hashing
  • Stochastic gradient descent



2CRAVE: Heavy Hitters at DUB LA 2014 - YouTube
photo src: www.youtube.com


Lower bounds

Lower bounds have been computed for many of the data streaming problems that have been studied. By far, the most common technique for computing these lower bounds has been using communication complexity.

Source of the article : Wikipedia



EmoticonEmoticon

 

Start typing and press Enter to search