Docsity

Algorithmic Techniques for Data Mining: Iceberg Queries and Frequent Itemsets, Papers of Database Management Systems (DBMS)

Toggle sidebar
bg1
Approximate Frequency Counts over Data Streams
Gurmeet Singh Manku
Stanford University
Rajeev Motwani
Stanford University
Abstract
We present algorithms for computing frequency
counts exceeding a user-specified threshold over
data streams. Our algorithms are simple and have
provably small memory footprints. Although the
output is approximate, the error is guaranteed not
to exceed a user-specified parameter. Our algo-
rithms can easily be deployed for streams of single-
ton items like those found in IP network monitor-
ing. We can also handle streams of variable sized
sets of items exemplified by a sequence of mar-
ket basket transactions at a retail store. For such
streams, we describe an optimized implementation
to compute frequent itemsets in a single pass.
1 Introduction
In several emerging applications, data takes the form
of continuous data streams, as opposed to finite stored
datasets. Examples include stock tickers, network traffic
measurements, web-server logs, click streams, data feeds
from sensor networks, and telecom call records. Stream
processing differs from computation over traditional stored
datasets in two important aspects: (a) the sheer volume of
a stream over its lifetime could be huge, and (b) queries re-
quire timely answers; response times should be small. As
a consequence, it is not possible to store the stream in its
entirety on secondary storage and scan it when a query ar-
rives. This motivates the design for summary data struc-
tures with small memory footprints that can support both
one-time and continuous queries.
Supported by NSF Grant IIS-0118173 and Stanford Graduate
Fellowship
Supported by NSF Grant IIS-0118173, an Okawa Foundation Re-
search Grant, and grants from Microsoft and Veritas.
Permission to copy without fee all or part of this material is granted pro-
vided that the copies are not made or distributed for direct commercial
advantage, the VLDB copyright notice and the title of the publication and
its date appear, and notice is given that copying is by permission of the
Very Large Data Base Endowment. To copy otherwise, or to republish,
requires a fee and/or special permission from the Endowment.
Proceedings of the 28th VLDB Conference,
Hong Kong, China, 2002
An aggregate query that is widely applicable is
SELECT R.EventType, COUNT(*) FROM R GROUP BY
R.EventType, where relation Rmodels a stream of
events with attribute R.EventType denoting the type of
event. In several applications, groups with very low
frequencies are uninteresting; the user is interested in
only those groups whose frequency exceeds a certain
threshold, usually expressed as a percentage of the size
of the relation seen so far. The modified query then
is SELECT R.EventType, COUNT(*) FROM R GROUP
BY R.EventType HAVING COUNT(*) > s |R| where
sis a user-specified percentage and |R| is the length of
stream seen so far.
A related aggregate query is over an input stream rela-
tion whose tuples are sets of items rather than individual
items. The goal is to compute all subsets of items, here-
after called itemsets, which occur in at least a fraction
of
the stream seen so far. This is far more challenging than
counting singleton tuples.
1.1 Motivating Examples
Here are four problems drawn from databases, data min-
ing, and computer networks, where frequency counts ex-
ceeding a user-specified threshold are computed.
1. An iceberg query [FSGM
98] performs an aggregate
function over an attribute (or a set of attributes) of a
relation and eliminates those aggregate values that are
below some user-specified threshold.
2. Association rules [AS94] over a dataset consisting of
sets of items, require computation of frequent itemsets,
where an itemset is frequent if it occurs in at least a
user-specified fraction of the dataset.
3. Iceberg datacubes [BR99, HPDW01] compute only
those Group By’s of a CUBE operator whose aggre-
gate frequency exceeds a user-specified threshold.
4. Traffic measurement and accounting of IP packets re-
quires identification of flows that exceed a certain frac-
tion of total traffic [EV01].
Existing algorithms for iceberg queries, association
rules, and iceberg cubes have been optimized for finite
stored data. They compute exact results, attempting to
minimize the number of passes they make over the en-
tire dataset. The best algorithms take two passes. When
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Algorithmic Techniques for Data Mining: Iceberg Queries and Frequent Itemsets and more Papers Database Management Systems (DBMS) in PDF only on Docsity!

Approximate Frequency Counts over Data Streams

Gurmeet Singh Manku

Stanford University [email protected]

Rajeev Motwani



Stanford University [email protected]

Abstract

We present algorithms for computing frequency counts exceeding a user-specified threshold over data streams. Our algorithms are simple and have provably small memory footprints. Although the output is approximate, the error is guaranteed not to exceed a user-specified parameter. Our algo- rithms can easily be deployed for streams of single- ton items like those found in IP network monitor- ing. We can also handle streams of variable sized sets of items exemplified by a sequence of mar- ket basket transactions at a retail store. For such streams, we describe an optimized implementation to compute frequent itemsets in a single pass.

1 Introduction

In several emerging applications, data takes the form of continuous data streams , as opposed to finite stored datasets. Examples include stock tickers, network traffic measurements, web-server logs, click streams, data feeds from sensor networks, and telecom call records. Stream processing differs from computation over traditional stored datasets in two important aspects: (a) the sheer volume of a stream over its lifetime could be huge, and (b) queries re- quire timely answers; response times should be small. As a consequence, it is not possible to store the stream in its entirety on secondary storage and scan it when a query ar- rives. This motivates the design for summary data struc- tures with small memory footprints that can support both one-time and continuous queries.  Supported by NSF Grant IIS-0118173 and Stanford Graduate Fellowship Supported by NSF Grant IIS-0118173, an Okawa Foundation Re- search Grant, and grants from Microsoft and Veritas.

Permission to copy without fee all or part of this material is granted pro- vided that the copies are not made or distributed for direct commercial advantage, the VLDB copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Very Large Data Base Endowment. To copy otherwise, or to republish, requires a fee and/or special permission from the Endowment.

Proceedings of the 28th VLDB Conference, Hong Kong, China, 2002

An aggregate query that is widely applicable is SELECT R.EventType, COUNT() FROM R GROUP BY R.EventType, where relation R models a stream of events with attribute R.EventType denoting the type of event. In several applications, groups with very low frequencies are uninteresting; the user is interested in only those groups whose frequency exceeds a certain threshold, usually expressed as a percentage of the size of the relation seen so far. The modified query then is SELECT R.EventType, COUNT() FROM R GROUP BY R.EventType HAVING COUNT(*) > s |R| where s is a user-specified percentage and |R| is the length of stream seen so far. A related aggregate query is over an input stream rela- tion whose tuples are sets of items rather than individual items. The goal is to compute all subsets of items, here- after called itemsets, which occur in at least a fraction  of the stream seen so far. This is far more challenging than counting singleton tuples.

1.1 Motivating Examples

Here are four problems drawn from databases, data min- ing, and computer networks, where frequency counts ex- ceeding a user-specified threshold are computed.

  1. An iceberg query [FSGM 98] performs an aggregate function over an attribute (or a set of attributes) of a relation and eliminates those aggregate values that are below some user-specified threshold.
  2. Association rules [AS94] over a dataset consisting of sets of items, require computation of frequent itemsets , where an itemset is frequent if it occurs in at least a user-specified fraction of the dataset.
  3. Iceberg datacubes [BR99, HPDW01] compute only those Group By’s of a CUBE operator whose aggre- gate frequency exceeds a user-specified threshold.
  4. Traffic measurement and accounting of IP packets re- quires identification of flows that exceed a certain frac- tion of total traffic [EV01]. Existing algorithms for iceberg queries, association rules, and iceberg cubes have been optimized for finite stored data. They compute exact results, attempting to minimize the number of passes they make over the en- tire dataset. The best algorithms take two passes. When

adapted to streams, where only one pass is allowed, and results are always expected to be available with short re- sponse times, these algorithms fail to provide any a pri- ori guarantees on the quality of their output. In this paper, we present algorithms for computing frequency counts in a single pass with a priori error guarantees. Our algorithms work for variable sized transactions. We can also compute frequent sets of items in a single pass.

1.2 Offline Streams

In a data warehousing environment, bulk updates occur at regular intervals of time, e.g., daily, weekly or monthly. It is desirable that data structures storing aggregates like frequent itemsets and iceberg cubes, be maintained incre- mentally. A complete rescan of the entire database per up- date is prohibitively costly for multi-terabyte warehouses. We call the sequence of updates to warehouses or backup devices an offline stream to distinguish it from on- line streams like stock tickers, network measurements and sensor data. Offline streams are characterized by regular bulk arrivals. Queries over these streams are allowed to be processed offline. However, there is not enough time to scan the entire database whenever an update comes along. These considerations motivate the design of summary data structures [AGP99] that allow incremental maintenance. These summaries should be significantly smaller than the base datasets but need not necessarily fit in main memory. Query processing over offline and online streams is sim- ilar in that summary data structures need to be incremen- tally maintained because it is not possible to rescan the en- tire input. The difference lies in the time scale and the size of updates. We present the first truly incremental algorithm for maintaining frequent itemsets in a data warehouse setting. Our algorithm maintains a small summary structure and does not require repeated rescans of the entire database.

1.3 Roadmap

In Section 2, we review applications that compute fre- quent itemsets, identifying problems with existing ap- proaches. In Section 3, we formally state the problem we solve. In Section 4, we describe our algorithm for singleton items. In Section 5, we describe how the basic algorithm can be extended to handle sets of items. We also describe our implementation in detail. In Section 6, we report our experiments. Related work is presented in Section 7.

2 Frequency Counting Applications

In this section, we review existing algorithms for four different applications, identifying shortcomings that sur- face when we adapt them to stream scenarios.

2.1 Iceberg Queries

The idea behind Iceberg Queries[FSGM 98] is to iden- tify aggregates in a GROUP BY of a SQL query that exceed

a user-specified threshold . A prototypical query on a re- lation R(c1, c2,  , ck, rest) with threshold is

SELECT c1, c2,  , ck, COUNT(rest) FROM R GROUP BY c1, c2,  , ck HAVING COUNT(rest)

 

The parameter is equivalent to s |R| where s is a per- centage and |R| is the size of R. The algorithm presented in [FSGM  98] uses repeated hashing over multiple passes. It builds upon the work of Park et al [PCY95]. The basic idea is the following: In the first pass, a set of counters is maintained. Each incoming item is hashed onto a counter which is incremented. These counters are then compressed into a bitmap, with a  denoting a large counter value. In the second pass, exact frequencies for only those elements are maintained which hash to a value whose correspond- ing bitmap value is . Variations and improvements of this basic idea are explored in [FSGM  98] It is difficult to adapt this algorithm for streams because at the end of the first pass, no frequencies are available.

2.2 Iceberg Cubes Iceberg cubes [BR99, HPDW01] take Iceberg queries a step further by proposing a variant of the CUBE operator over a relation R(c1, c2,  , ck, X):

SELECT c1, c2,  , ck, COUNT(), SUM(X) FROM R CUBE BY c1, c2,  , ck HAVING COUNT()

 

The algorithms for iceberg cubes take at least  passes, where  is the number of dimensions over which the cube has to be computed. Our algorithms can be applied as a preprocessing step to the problem of computing Iceberg Cubes. If the clause SUM(X) is removed, our algorithm can enable computation of approximate Iceberg Cubes in a single pass. We are currently exploring the application of our algorithms to Iceberg Cubes.

2.3 Frequent Itemsets and Association Rules

A transaction is defined to be a subset of items drawn from  , the universe of all items. For a collection of trans- actions, an itemset  is said to have support  if occurs as a subset in at least a fraction  of all transactions. Association rules over a set of transactions are rules of the form   , where and  are subsets of  such that  and  has support exceeding a user- specified threshold . The confidence of a rule   is the value  "!$#&%('*),+.- $!$#&%('/-

. Usually, only those rules are pro- duced whose confidence exceeds a user-specified thresh- old. The Apriori algorithm [AS94] was one of the first suc- cessful solutions for Association Rules. The problem actu- ally reduces to that of computing frequent itemsets. Once frequent itemsets have been identified, identifying rules

(a) high frequency false positives, and (b) small errors in individual frequencies. Both kinds of errors are tolerable in the applications outlined in Section 2. We say that an algo-

rithm maintains an -deficient synopsis if its output satisfies

the aforementioned properties.

Our goal is to devise algorithms to support -deficient

synopses using as little main memory as possible.

4 Algorithms for Frequent Items

In this section, we describe algorithms for computing -

deficient synopses for singleton items. Extensions to sets of items will be described in Section 5. We actually de- vised two algorithms for frequency counts. Both provide the approximation guarantees outlined in Section 3. The first algorithm, Sticky Sampling, is probabilistic. It fails to provide correct answers with a miniscule probability of failure. The second algorithm, Lossy Counting, is deter- ministic. Interestingly, we experimentally show that Lossy Counting performs better in practice, although it has a the- oretically worse worst-case bound.

4.1 Sticky Sampling Algorithm

In this section, we describe a sampling based algorithm

for computing an -deficient synopsis over a data stream

of singleton items. The algorithm is probabilistic and is said to fail if any of the three properties in Section 3 is not satisfied. The user specifies three parameters: support ,

error and probability of failure

Our data structure

is a set of entries of the form  

where  estimates the frequency of an element  belonging

to the stream. Initially,

is empty, and the sampling rate 

is set to . Sampling an element with rate  means that we

select the element with probability

. For each incoming

element , if an entry for  already exists in

, we incre-

ment the corresponding frequency ; otherwise, we sample

the element with rate . If this element is selected by sam-

pling, we add an entry  

to^

; otherwise, we ignore 

and move on to the next element in the stream.

The sampling rate  varies over the lifetime of a stream

as follows: Let  

. The first

 elements

are sampled at rate   , the next

 elements are sam-

pled at rate  

, the next  elements are sampled at rate

  , and so on. Whenever the sampling rate changes,

we also scan entries in

, and update them as follows: For

each entry  

, we repeatedly toss an unbiased coin until

the coin toss is successful, diminishing  by one for every

unsuccessful outcome; if  becomes  during this process,

we delete the entry from

. The number of unsuccessful coin tosses follows a geometric distribution. Its value can be efficiently computed [Vit85]. Effectively, we have trans- formed

to exactly the state it would have been in, had we been sampling with the new rate from the very beginning.

When a user requests a list of items with threshold , we output those entries in

where   %

Theorem 4.1 Sticky Sampling computes an -deficient

synopsis with probability at least  %

^ using at most

expected number of entries.

Proof : The first

 elements find their way into

. When

the sampling rate is 

, we have $  , for some

. It follows that

Any error in the frequency count of an element  cor-

responds to a sequence of unsuccessful coin tosses during

the first few occurrences of . The length of this sequence

follows a geometric distribution. The probability that this

length exceeds $ is at most  %

, which is less than

 %^ 

, which in turn is less than 

The number of elements with frequency at least  is no more than

. Therefore, the probability that the estimate

for any of them is deficient by $ , is at most  

. The probability of failure should be at most

^. This yields^ !

. Since the space requirements are

, the

space bound follows. "

We call our algorithm Sticky Sampling because

sweeps over the stream like a magnet, attracting all ele- ments which already have an entry in

. Note that the

space complexity for Sticky Sampling is independent of $ ,

the current length of the stream. The idea of maintaining counts of samples was first presented by Gibbons and Ma- tias [GM98], who used it to compress their samples and

solve the Top-k problem where the  most frequent items

need to be identified. Our algorithm is different in that the

sampling rate  increases logarithmically proportional to

the size of the stream, and that we guarantee to produce all

items whose frequency exceeds , not just the top .

4.2 Lossy Counting Algorithm

In this section, we describe a deterministic algorithm that computes frequency counts over a stream of single item transactions, satisfying the guarantees outlined in Sec- tion 3 using at most

space where $ denotes the

current length of the stream. The user specifies two param-

eters: support  and error . This algorithm performs better

than Sticky Sampling in practice although theoretically, its worst-case space complexity is worse. Definitions: The incoming stream is conceptually di-

vided into buckets of width #%$

'& transactions each.

Buckets are labeled with bucket ids , starting from . We

denote the current bucket id by (

, whose value is

&.^ For an element^ , we denote its true frequency in

the stream seen so far by . Note that and # are fixed

while $ , (

and  are running variables whose val-

ues change as the stream progresses.

Our data structure , is a set of entries of the form

 ^ -

, where  is an element in the stream,  is an inte-

ger representing its estimated frequency, and - is the max-

imum possible error in .

Algorithm: Initially, , is empty. Whenever a new ele-

ment  arrives, we first lookup , to see whether an entry for

 already exists or not. If the lookup succeeds, we update

the entry by incrementing its frequency  by one. Other-

wise, we create a new entry of the form   (

$! *)^

We also prune , by deleting some of its entries at bucket

boundaries, i.e., whenever $  

#. The rule for

deletion is simple: an entry   -

is deleted if  - 

!!^ *)^

. When a user requests a list of items with thresh- old , we output those entries in

where   %

For an entry   -^

,  represents the exact frequency

count of  ever since this entry was inserted into ,. The

value of - assigned to a new entry is the maximum num-

ber of times  could have occurred in the first (

$! *)^

buckets. This value is exactly (

% . Once an entry

is inserted into , , its - value remains unchanged.

Lemma 4.1 Whenever deletions occur, (

Lemma 4.2 Whenever an entry   -

gets deleted,

Proof : We prove by induction. Base case: (

$! *)^

An entry   -

is deleted only if   , which is also

its true frequency . Thus,   (

$! *)^

Induction step: Consider an entry   -

that gets

deleted for some (

 .^ This entry was inserted

when bucket -   was being processed. An entry for 

could possibly have been deleted as late as the time when

bucket - became full. By induction, the true frequency of

 when that deletion occurred was no more than^ -. Further,

 is the true frequency of  ever since it was inserted. It fol-

lows that , the true frequency of  in buckets  through

!!^ *)^

, is at most   -. Combined with the deletion rule

that  -  (

, we get  ( 

Lemma 4.3 If  does not appear in , , then 

Proof : If the Lemma is true for an element  whenever it

gets deleted, i.e., when $  

# , it is true for all

other $ also. From Lemma 4.2 and Lemma 4.1, we infer

that   $ whenever it gets deleted. "

Lemma 4.4 If   -

 , , then     $.

Proof : If -  ,   . Otherwise,  was possibly

deleted sometimes in the first - buckets. From Lemma

4.2, we infer that the exact frequency of  when the last

such deletion took place, is at most -. Therefore,   

 -. Since -  (

$! *)^

%   $ , we conclude that

Consider elements whose true frequency exceeds $.

There cannot be more than

 such elements. Lemma 4.

shows that all of them have entries in ,. Lemma 4.4 further

shows that the estimated frequencies of all such elements

are accurate to within $. Thus, , correctly maintains

an -deficient synopsis. The next theorem shows that the

number of low frequency elements (which occur less than

$ times) is not too large.

Theorem 4.2 Lossy Counting computes an -deficient syn-

opsis using at most

entries.

Proof : Let  (

$! *)^

be the current bucket id. For each

 (  , let  denote the number of entries in , whose

bucket id is %  . The element corresponding to such an

entry must occur at least times in buckets %   through

; otherwise, it would have been deleted. Since the size of

each bucket is # , we get the following constraints:

&^  (1)

We claim that

   ^

We prove Inequality (2) by induction. The base case

   follows from Inequality (1) directly. Assume

that Inequality (2) is true for   

 &  % . We

will show that it is true for  ! as well. Adding In-

equality (1) for  " to  %  instances of Inequal-

ity (2) (one each for varying from  to  % ) gives

us #    $#

 *&(&(&^  #^

. Upon rear-

rangement, we get  #   + #  # 

 which

then readily simplifies to Inequality (2) for  , , thereby

completing the induction step.

Since - ,.- /#10  , from Inequality 2, we get - ,.-2

 ^ 

If we make the assumption that in real world datasets, elements with very low frequency (at most

 ) tend to oc-

cur more or less uniformly at random, then Lossy Count-

ing requires no more than 3  space, as proved in the Ap-

pendix. We note that the IBM test data generator for data mining [AS94] for generating synthetic datasets for associ- ation rules, indeed chooses low frequency items uniformly randomly from a fixed distribution.

4.3 Sticky Sampling vs Lossy Counting

In this section, we compare Sticky Sampling and Lossy Counting. We show that Lossy Counting performs signifi- cantly better for streams with random arrival distributions. A glance at Theorems 4.1 and 4.2 suggests that Sticky Sampling should require constant space, while Lossy Counting should require space that grows logarithmically

with $ , the length of the stream. However, these theorems

do not tell the whole story because they bound worst-case space complexities. For Sticky Sampling, the worst case amounts to a sequence with no duplicates, arriving in any order. For Lossy Counting, the worst case corresponds to a rather pathological sequence that we suspect would almost never occur in practice. We now show that if the arrival or- der of the elements is uniformly random, Lossy Counting is superior by a large factor. We studied two streams. One had no duplicates. The other was highly skewed and followed the Zipfian distri- bution. Most streams in practice would be somewhere in

consist of sets of items. This section is less theoretical in nature than the preceding one. The focus is on system-level issues and implementation artifices for optimizing memory and speed.

5.1 Frequent Itemsets Algorithm

The input to the algorithm is a stream of transactions

where each transaction is a set of items drawn from . We

denote the current length of this stream by $. The user

specifies two parameters: support , and error . The chal-

lenge lies in handling variable sized transactions and avoid- ing explicit enumeration of all subsets of any transaction.

Our data structure , is a set of entries of the form

, where  is a subset of items,  is an inte-

ger representing its approximate frequency, and - is the

maximum possible error in . Initially, , is empty.

Imagine dividing the incoming transaction stream into

buckets , where each bucket consists of #  $

'& transac-

tions. Buckets are labeled with bucket ids , starting from

. We denote the current bucket id by (

. We do not process the input stream transaction by transaction. In- stead, we try to fill available main memory with as many transactions as possible, and then process such a batch of transactions together. This is where the algorithm differs from that presented in Section 4.2. Over time, the amount of main memory available might increase/decrease. Let

denote the number of buckets in main memory in the cur-

rent batch being processed. We update , as follows:

 UPDATE SET: For each entry   -   , , up-

date  by counting the occurrences of  in the current

batch. If the updated entry satisfies   -  (

$! *)^

we delete this entry.

 NEW SET: If a set  has frequency  in the

current batch and does not occur in , , create a new

entry   ( 

It is easy to see that every set  whose true fre-

quency 

$ , has an entry in ,. Also, if an entry

 , , then, the true frequency 

satisfies the

inequality  

   -. When a user requests a list of

items with threshold , we output those entries in , where

It is important that

be a large number. The reason

is that any subset of  that occurs

  times or more,

contributes an entry to ,. For a smaller

, more spurious

subsets find their way into ,.

In the next section, we show how , can be represented

compactly and how UPDATE SET and NEW SET can be implemented efficiently.

5.2 Data Structures

Our implementation has three modules: BUFFER, TRIE, and SETGEN. BUFFER repeatedly reads in a batch of trans- actions into available main memory. TRIE maintains the

data structure , described earlier. SETGEN operates on

the current batch of transactions. It enumerates subsets of these transactions along with their frequencies. Together

with TRIE, it implements the UPDATE SET and NEW SET operations. The challenge lies in designing a space efficient representation of TRIE and a fast algorithm for SETGEN that avoids generating all possible subsets of itemsets. Buffer : This module repeatedly reads in a batch of transactions into available main memory. Transactions are sets of item-id’s. They are laid out one after the other in a big array. A bitmap is used to remember transaction bound- aries. A bit per per item-id denotes whether this item-id is the last member of some transaction or not. After reading in a batch, BUFFER sorts each transaction by its item-id’s.

Trie : This module maintains the data structure , out-

lined in Section 5.1. Conceptually, it is a forest (a set of

trees) consisting of labeled nodes. Labels are of the form

   -   , where   is an item-id,  is its

estimated frequency, - is the maximum possible error in ,

and   is the distance of this node from the root of the

tree it belongs to. The root nodes have level . The level of

any other node is one more than that of its parent. The chil- dren of any node are ordered by their item-id’s. The root nodes in the forest are also ordered by item-id’s. A node in the tree represents an itemset consisting of item-id’s in

that node and all its ancestors. There is a  to  mapping

between entries in , and nodes in TRIE.

Tries are used by several Association Rules algorithms. Hash tries [AS94] are a popular choice. Usual implemen-

tations of , as a trie would require pointers and variable-

sized memory segments (because the number of children of a node changes over time). Our TRIE is different from traditional implementations. Since tries are the bottleneck as far as space is con- cerned, we designed them to be as compact as possi- ble. We maintain TRIE as an array of entries of the form

   -    corresponding to the pre-order

traversal of the underlying trees. Note that this is equiva- lent to a lexicographic ordering of the subsets it encodes. There are no pointers from any node to its children or its

siblings. The  ’s compactly encode the underlying tree

structure. Our representation is okay because tries are al- ways scanned sequentially, as we show later. SetGen : This module generates subsets of item-id’s along with their frequencies in the current batch of trans- actions in lexicographic order. Not all possible subsets need to be generated. A glance at the description of UP- DATE SET and NEW SET operations reveals that a subset must be enumerated iff either it occurs in TRIE or its fre- quency in the current batch exceeds

. SETGEN uses the following pruning rule: If a subset does not make its way into TRIE af- ter application of both UPDATE SET and NEW SET , then no supersets of should be considered. This is similar to the Apriori pruning rule. We describe an efficient implementation of SETGEN in greater detail later.

Overall Algorithm

BUFFER repeatedly fills available main memory with as

many transactions as possible, and sorts them. SETGEN operates on the current batch of transactions. It generates sets of itemsets along with their frequency counts in lexi- cographic order. It limits the number of subsets using the pruning rule. Together, TRIE and SETGEN implement the UPDATE SET and NEW SET operations. In the end, TRIE

stores the updated data structure , , and BUFFER gets ready

to read in the next batch.

5.3 Efficient Implementations

Buffer : If item-id’s are successive integers from  thru

-  - , and if  is small enough (say, less than  million), we

maintain exact frequency counts for singleton sets. If -  -

, we need an array of size only  



. When ex- act frequency counts are maintained, BUFFER first prunes

away those item-id’s whose frequency is less than $ , and

then sorts the transactions. Note that $ is the length of the

stream up to and including the current batch of transactions.

Trie : As SETGEN generates its sequence of sets and as- sociated frequencies, TRIE needs to be updated. Adding or deleting TRIE nodes in situ is made difficult by the fact that TRIE is a compact array. However, we take advantage of the fact that the sets produced by SETGEN (and there- fore, the sequence of additions and deletions) are lexico- graphically ordered. Recall that our compact TRIE stores its constituent subsets in their lexicographic order. This lets SETGEN and TRIE work hand in hand. We maintain TRIE not as one huge array, but as a set of fairly large-sized chunks of memory. Instead of modify- ing the original trie, we create a new TRIE afresh. Chunks from the old TRIE are freed as soon as they are not re- quired. Thus, the overhead of maintaining two Tries is not significant. By the time SETGEN finishes, the chunks of the original trie have been completely discarded. For finite streams, an important TRIE optimization per- tains to the last batch of transactions when the value of

the number of buckets in BUFFER, could be small. Instead of applying the rules in Section 5.1, we prune nodes in the trie more aggressively by setting the threshold for deletion

to  instead of (



. This is because the lower frequency nodes do not contribute to the final output.

SetGen : This module is the bottleneck in terms of time for our algorithm. Optimizing it has made it fairly complex. We describe the salient features of our implementation. SETGEN employs a priority queue called Heap which initially contains pointers to smallest item-id’s of all trans- actions in BUFFER. Duplicate members (pointers pointing to the same item-id) are maintained together and they con- stitute a single entry in Heap. In fact, we chain all the point- ers together, deriving the space for this chain from BUFFER itself. When an item-id in BUFFER is inserted into Heap ,

the -byte integer used to represent an item-id is converted

into a -byte pointer. When a heap entry is removed, the

pointers are restored back to item-id’s. SETGEN repeatedly processes the smallest item-id in Heap to generate singleton sets. If this singleton belongs

to TRIE after UPDATE SET and NEW SET rules have been applied, we try to generate the next set in lexicographic se- quence by extending the current singleton set. This is done by invoking SETGEN recursively with a new heap created out of successors of the pointers to item-id’s just removed and processed. The successors of an item-id is the item-id following it in its transaction. Last item-id’s of transactions have no successors. When the recursive call returns, the smallest entry in Heap is removed and all successors of the currently smallest item-id are added to Heap by following the chain of pointers described earlier.

5.4 System Issues and Optimizations

BUFFER scans the incoming stream by memory map- ping the input file. This saves time by getting rid of double copying of file blocks. The UNIX system call for mem- ory mapping files is mmap(). The accompanying mad- vise() interface allows a process to inform the operating systems of its intent to read the file sequentially. We used the standard qsort() to sort transactions. The time taken to read and sort transactions pales in comparison with the time taken by SETGEN, obviating the need for a custom sort routine. Threading SETGEN and BUFFER does not help because SETGEN is significantly slower. Tries are written and read sequentially. They are oper- ational when BUFFER is being processed by SETGEN. At this time, the disk is idle. Further, the rate at which tries are scanned (read/written) is much smaller than the rate at which sequential disk I/O can be done. It is indeed possible to maintain TRIE on disk without any loss in performance. This has two important advantages:

(a) The size of a trie is not limited by the size of main memory available, as is the case with other algorithms. This means that our algorithm can function even when the amount of main memory available is quite small. (b) Since most available memory can be devoted to

BUFFER, we can work with smaller values of than

other algorithms can handle. This is a big win.

TRIE is currently implemented as a pair of anony- mous memory mapped segments. They can be associated with actual files, if the user so desires. Since tries are read/written sequentially, as against being accessed ran- domly, it is possible to compress/decompress it on the fly as sections of it are read/written to disk. Our current im- plementation does not attempt any compression; we use four int’s for node labels. Writing TRIE to disk violates a pedantic definition of single-pass algorithms. However, we should note that the term single-pass is meaningful only for disk-bound applications. Our program is cpu-bound. Memory requirements for Heap are modest. Available main memory is consumed primarily by BUFFER, assum- ing TRIE are on disk. Our implementation allows the user to specify the size of BUFFER.

0

20

40

60

80

100

120

0 0.002 0.004 0.006 0.008 0.

Time taken in seconds

Support threshold s

Varying Buffer Sizes and Support s Buffer = 16 MBBuffer = 4 MB Buffer = 28 MB Buffer = 40 MB

0

20

40

60

80

100

120

0 10 20 30 40 50

Time taken in seconds

Buffer size in MBytes

Varying Support s and Buffer Sizes Support = 0.001 Support = 0. Support = 0.004 Support = 0.

0

20

40

60

80

100

120

100 200 300 400 500 600 700 800 900 1000

Time taken in seconds

Length of stream in Thousands

Time taken as stream progresses Support 0.001 Support 0. Support 0.

(a) Times taken for IBM test dataset      with  items. No of transactions $ was  million.

0

100

200

300

400

500

600

700

800

900

1000

0 0.002 0.004 0.006 0.008 0.

Time taken in seconds

Support threshold s

Varying Buffer Sizes and Support s Buffer = 16 MBBuffer = 4 MB Buffer = 28 MB Buffer = 40 MB

0

100

200

300

400

500

600

700

800

900

1000

0 10 20 30 40 50

Time taken in seconds

Buffer size in MBytes

Varying Support s and Buffer Sizes Support = 0.001 Support = 0. Support = 0.004 Support = 0.

0

100

200

300

400

500

600

700

800

900

1000

0 100 200 300 400 500 600 700 800 9001000

Time taken in seconds

Length of stream in Thousands

Time taken as stream progresses Support 0.001 Support 0. Support 0.

(b) Times taken for IBM test dataset  

(   with  items. No of transactions $ was  million.

Figure 2: Experimental results for our algorithm over IBM test datasets.

0

200

400

600

800

1000

1200

0.004 0.008 0.012 0.016 0.

Time taken in seconds

Support threshold s

Varying Buffer Sizes and Support s Buffer = 12 MBBuffer = 8 MB Buffer = 16 MB Buffer = 20 MB

0

200

400

600

800

1000

1200

0 5 10 15 20

Time taken in seconds

Buffer size in MBytes

Varying Support s and Buffer Sizes Support = 0.005 Support = 0. Support = 0.010 Support = 0. Support = 0.

0

200

400

600

800

1000

1200

10 20 30 40 50 60 70 80 90

Time taken in seconds

Length of stream in Thousands

Time taken as stream progresses Support 0.010 Support 0. Support 0.

(a) Times taken for frequent word-pairs in 100K web pages.

0

500

1000

1500

2000

0 0.004 0.008 0.012 0.016 0.

Time taken in seconds

Support threshold s

Varying Buffer Sizes and Support s Buffer = 14 MBBuffer = 6 MB Buffer = 22 MB Buffer = 30 MB

0

500

1000

1500

2000

0 5 10 15 20 25 30

Time taken in seconds

Buffer size in MBytes

Varying Support s and Buffer Sizes Support = 0.004 Support = 0. Support = 0.012 Support = 0. Support = 0.

0

200

400

600

800

1000

1200

1400

1600

1800

200 400 600 800

Time taken in seconds

Length of stream in Thousands

Time taken as stream progresses Support 0.004 Support 0. Support 0.

(b) Times taken for frequent word-pairs in 800K Reuters documents

Figure 3: Times taken for Iceberg Queries over Web pages and Reuters articles.

BUFFER set to  MB. The table shows the total memory

required by the two programs. For our program, this in- cludes the maximum cost of HEAP and TRIE, during run- time. As the value of support  increases, the memory re- quired by TRIE decreases. This is because there are fewer itemsets with higher support. The size of the TRIE also

decreases when BUFFER changes from  MB to  MB.

This is because the value of

(see Section 5.1) increases. Therefore, there are fewer low frequency subsets (with fre-

quency less than ) that creep into the trie. It is interesting

to observe that with BUFFER set to a small value,  MB,

our algorithm was able to compute all frequent itemsets us- ing much less memory than Apriori but more time. With

BUFFER size  MB, the entire input fits in main memory.

Our program beats Apriori be a factor of

to. showing

that our main memory implementation is much faster.

6.2 Iceberg Queries

An iceberg query studied in [FSGM  98] was the iden-

tification of all pairs of words in a repository of  ! 

web documents which occur at least 

 times to-

gether. Note that the relation

for this query is not explic- itly materialized. This query is equivalent to identifying all

word pairs that occur in at least   

 of all documents.

We ran this query over two different datasets.

The first dataset was a collection of   web pages

crawled by WebBase, a web crawler developed at Stanford University [HRGMP00]. Words in each document were identified. Common stop-words [SB88] were removed. The resulting input file was

 MB. Experiments for this

dataset were carried out on a 933 MHz Pentium III ma- chine running Linux Kernel version 2.2.16. The second dataset was the well-known Reuters news-

wire dataset, containing    news articles. The input

file resulting from this dataset after removing stop-words was roughly

 MB. Experiments for this dataset were

carried out on a 700 MHz Pentium III machine running Linux Kernel version 2.2.16.

We study the interplay of $ , the length of the stream, ,

the support, time taken, and the size of BUFFER in Figure 3. The overall shape of the graphs is very similar to those for frequent itemsets over the IBM test datasets that we studied in the previous section. For the sake of comparison with the algorithm presented in the original Iceberg Queries paper [FSGM  98], we ran

our program over    web documents with support

. This settings corresponds to the first query

studied in [FSGM  98] (see Figure

in their paper). We ran our program on exactly the same machine, a 200 MHz Sun Ultra/II with 256 MB RAM running SunOS 5.6. We

fixed BUFFER at 

MB. Our program processed the in-

put in  batches, producing .,  frequent word pairs.

BUFFER, Heap and auxiliary data structures required

MB. The maximum size of a trie was  MB. Our program

took 

 seconds to complete. Fang et al [FSGM  98] re-

port that the same query required over '  seconds using

roughly . MB main memory. Our algorithm is faster.

An interesting duality emerges between our approach and that of the algorithm in [FSGM 98]. Our program scans the input just once, but repeatedly scans a temporary file on disk (the memory mapped TRIE). The Iceberg algo- rithm scans the input multiple times, but uses no temporary storage. The advantage in our approach is that it does not require a lookahead into the data stream.

7 Related and Future Work

Problems related to frequency counting that have been studied in the context of data streams include approximate frequency moments [AMS96], 

differences [FKSV99], distinct values estimation [FM85, WVZT90], bit count- ing [DGIM02], and top-k queries [GM98, CCFC02]. Algorithms over data streams that pertain to aggrega- tion include approximate quantiles [MRL99, GK01], V- optimal histograms [GKS01b], wavelet based aggregate queries [GKMS01, MVW00], and correlated aggregate queries [GKS01a]. We are currently exploring the application of our basic techniques to sliding windows, data cubes, and two-pass algorithms for frequent itemsets.

8 Conclusions

We proposed novel algorithms for computing approx- imate frequency counts of elements in a data stream. Our algorithms require provably small main memory footprints. The problem of identifying frequent elements is at the heart of several important problems: iceberg queries, frequent itemsets, association rules, and packet flow identification. We can now solve each of them over streaming data. We also described a highly optimized implementation for identifying frequent itemsets. In general, our algorithm produces approximate results. However, for the datasets we studied, our algorithm runs in one pass and produces exact results, beating previous algorithms in terms of time. Our frequent itemsets algorithm can handle smaller val- ues of support threshold than previously possible. It re- mains practical even in environments with moderate main memory. We believe that our algorithm provides a practi- cal solution to the problem of maintaining association rules incrementally in a warehouse setting.

References

[AGP99] S. ACHARYA, P. B. GIBBONS, AND V. POOSALA. Aqua: A fast decision support system using approximate query answers. In Proc. of 25th Intl. Conf. on Very Large Data Bases , pages 754–755, 1999. [AMS96] N. ALON, Y. MATIAS, AND M. SZEGEDY. The space complexity of approximating the frequency moments. In Proc. of 28th Annual ACM Symp. on Theory of Computing , pages 20–29, May 1996. [AS94] R. AGRAWAL AND R. SRIKANT. Fast algorithms for min- ing association rules. In Proc. of 20th Intl. Conf. on Very Large Data Bases , pages 487–499, 1994. [BR99] K. BEYER AND R. RAMAKRISHNAN. Bottom-up compu- tation of sparse and iceberg cubes. In Proc. of 1999 ACM SIGMOD , pages 359–370, 1999.