One pass, and no room

A list that gives back its places

An estimator of the third frequency moment keeps a list of candidate heavy keys beside a Count-Sketch and samples the rest, and cutting a long list at the end of the pass to the candidates that hold a share of its moment picked the right keys and paid for the whole list. Dropping a candidate during the pass, as soon as it falls below that share, was predicted to make the list's memory follow the stream: under four candidates on steep streams, within a fifth of the best fixed list, and about ten on Zipf 0.5 with most of the earlier win kept. The list ends the pass the right length — three candidates on Zipf 1 — but its memory is its peak, and the peak is set by the twenty-fifth arrival, before any key has stood out: nineteen candidates on Zipf 1, and on flatter streams the most a share θ allows, one over θ. Charged its peak, it beats the end-of-pass cut on every stream from Zipf 0.75 up, 208 words against 364 at Zipf 1, and never reaches the best fixed list, 159.

A share of a list of equals let the stream choose how many heavy keys an estimator of F3=∑fx3F_3 = \sum f_x^3 should count. The estimator is the one the keys worth counting before sampling built: a Count-Sketch watches every arrival, a list keeps the keys the sketch ranks heaviest and counts each exactly from the moment it joins, and copies of the sampling estimator of the moments past the second cover the rest of the stream. The best length of the list moves with the stream’s skew — one candidate on the steepest streams, sixteen at Zipf 0.5 — so the earlier page kept a long list of 64 and, at the end of the pass, counted in the heavy part only the candidates holding at least a share of the moment the list itself held; the rest went back to the sampled part. The share chose well: 1.1 candidates kept on average at Zipf 2, 5.5 at Zipf 0.5. But the list’s 64 places were paid for through the whole pass, 192 words, four times the best estimator’s whole state on the steepest streams.

Its closing section proposed giving the places back as the pass goes. Each time a candidate is replaced or its count grows, the list knows its own total, ∑f^3\sum \hat f^3 over its candidates; a candidate whose cube falls below a share of that total could be dropped there and then. The list would hold, at any moment, only the candidates currently a large share of it, and its memory would be its peak rather than its capacity. The proposal predicted that on Zipf 1 and steeper the peak stays under four candidates, bringing the words within a fifth of the best fixed list, and that at Zipf 0.5 the peak is about ten, keeping most of the earlier win. It named the way it could fail, early in the pass: before many arrivals the sketch’s estimates are small and close together, every candidate is a large share of a small list, and the list may grow to its limit before any key has had time to stand out.

The list that gives back

Everything but the list is the earlier pages’: 60,000 arrivals over 2,048 keys at Zipf exponents from 0 to 2, a Count-Sketch of depth five at the width that makes each estimator smallest, candidates counted from entry, and copies of the sampling estimator enough for a relative standard deviation of 10%. The sampled part’s variance is computed exactly given the list, the heavy part’s error averaged over sixteen sketch seeds, and every estimator is charged in words: five a sketch column, three a counted candidate, two a copy.

The new list keeps its total as values change. After every change, its smallest candidate is dropped while that candidate’s cube is under a share θ of the total; an arriving key joins a list with room only if its estimate’s cube would be at least θ of the total with it included; a list at its cap of 64 replaces its smallest candidate, as before, when an arriving key’s estimate exceeds it. A candidate dropped and later re-admitted starts again from the sketch’s estimate, which is the Count-Sketch’s signed median and so may be under the truth as well as over it, the property a sketch that is allowed to be under traded for accuracy; a count that is never under is the one-sided alternative it was traded against. The list is charged three words for each candidate at its largest peak over the sixteen seeds. Three shares were run, 0.01, 0.03 and 0.1. At a share of nought the list gives nothing back and is the fixed list of its cap, which the measurement requires.

The peak comes first

The list's peak is set before any key has stood out: at a share of 0.03 the Zipf 1 list reaches 19 candidates by its 25th arrival and holds 3 at the end of 60,000; the Zipf 0.5 list reaches 33 by its 50th and ends at 7Candidates on the list after each of the first 2,000 arrivals (every 25) and at every 2,500 after, one sketch seed, a share of 0.03 and a sketch 256 counters wide, on Zipf 1 and Zipf 0.5. Zipf 1: 25 12, 225 2, 425 2, 625 2, 825 2, 1,025 2, 1,225 2, 1,425 2, 1,625 2, 1,825 2, 2,500 3, 5,000 2, 7,500 3, 10,000 3, 12,500 3, 15,000 2, 17,500 3, 20,000 3, 22,500 3, 25,000 3, 27,500 3, 30,000 3, 32,500 3, 35,000 3, 37,500 3, 40,000 3, 42,500 3, 45,000 3, 47,500 3, 50,000 3, 52,500 3, 55,000 3, 57,500 3, 60,000 3; peak 19. Zipf 0.5: 25 25, 225 20, 425 11, 625 10, 825 12, 1,025 12, 1,225 10, 1,425 11, 1,625 8, 1,825 7, 2,500 10, 5,000 8, 7,500 7, 10,000 8, 12,500 8, 15,000 8, 17,500 7, 20,000 8, 22,500 7, 25,000 7, 27,500 7, 30,000 8, 32,500 7, 35,000 7, 37,500 6, 40,000 7, 42,500 7, 45,000 7, 47,500 7, 50,000 8, 52,500 7, 55,000 7, 57,500 7, 60,000 7; peak 33.010203005001e+31.5e+32e+3arrivals so farcandidates on the listZipf 0.5: ends at 7Zipf 1: ends at 3faint levels: the length at 60,000 arrivalsθ = 0.03
Fig. 1 Candidates on the list after each of the first 2,000 arrivals and every 2,500 after, one sketch seed, a share of 0.03, on Zipf 1 and Zipf 0.5. Zipf 1: 19 candidates by the 25th arrival, 2 or 3 from the 500th to the end. Zipf 0.5: 33 by the 50th, about 7 or 8 from then on.

The list’s peak is set before any key has stood out: at a share of 0.03 the Zipf 1 list holds nineteen candidates after its twenty-fifth arrival and three at the end of 60,000; the Zipf 0.5 list holds thirty-three after its fiftieth and seven at the end. The proposal’s failure arrives at the first opportunity. Twenty-five arrivals over 2,048 keys are twenty-five different keys, nearly, each with an estimate near one, and a list whose total is nineteen ones is a list in which every candidate holds a nineteenth, more than 0.03. Every one of them is entitled to its place.

Then the stream does what the proposal expected. Within a few hundred arrivals the heavy keys of a Zipf 1 stream have estimates in the tens, their cubes in the thousands, and the light candidates fall below three per cent of a total those cubes dominate. The list shrinks to two or three and stays there for the remaining 59,000 arrivals, which is exactly the length the earlier page found best. The list’s length at the end of the pass is right. Its length at the start of the pass is what it pays for.

A bound that is not the stream’s

A list that keeps only candidates holding a share θ of its total can never hold more than 1/θ of them, and on every stream flatter than Zipf 1 it reaches its bound: at Zipf 0.5 the peak is 64 at θ = 0.01, 33 at θ = 0.03, 10 at θ = 0.1 (the first held by the cap of 64), while the list it ends the pass with is 15.9, 8.0, 3.7The most candidates the list held during the pass (solid, the largest over sixteen sketch seeds at the width that made the estimator smallest) and the mean it held at the end (faint), against the Zipf exponent, at shares of 0.01, 0.03, 0.1; the bound 1/θ marked at the right. θ = 0.01: Zipf 0 peak 64, end 64.0; Zipf 0.25 peak 64, end 53.3; Zipf 0.5 peak 64, end 15.9; Zipf 0.75 peak 34, end 8.8; Zipf 1 peak 27, end 5.9; Zipf 1.5 peak 5, end 2.2; Zipf 2 peak 4, end 2.1. θ = 0.03: Zipf 0 peak 33, end 28.1; Zipf 0.25 peak 29, end 19.3; Zipf 0.5 peak 33, end 8.0; Zipf 0.75 peak 21, end 4.1; Zipf 1 peak 19, end 3.2; Zipf 1.5 peak 4, end 2.0; Zipf 2 peak 3, end 1.1. θ = 0.1: Zipf 0 peak 10, end 8.7; Zipf 0.25 peak 10, end 6.9; Zipf 0.5 peak 10, end 3.7; Zipf 0.75 peak 6, end 2.3; Zipf 1 peak 6, end 2.0; Zipf 1.5 peak 2, end 1.0; Zipf 2 peak 2, end 1.1.020406000.2500.5000.75011.502Zipf exponent of the streamcandidatesθ = 0.01, peak (1/θ = 100)θ = 0.03, peak (1/θ = 33)θ = 0.1, peak (1/θ = 10)solid: the peak · faint: at the endcandidates
Fig. 2 The most candidates the list held during the pass (the largest over sixteen seeds) and the mean it held at the end, against the Zipf exponent, at shares of 0.01, 0.03 and 0.1. At Zipf 0.5 the peaks are 64, 33 and 10 and the final lengths 15.9, 8.0 and 3.7; at Zipf 1, 27, 19 and 6, and 5.9, 3.2 and 2.0.

A list that keeps only candidates holding a share θ of its total can never hold more than one over θ of them, and on every stream flatter than Zipf 1 it reaches that bound: at Zipf 0.5 the peaks are 33 at a share of 0.03 and 10 at 0.1, and 64, the cap, at 0.01. The bound is arithmetic — if every candidate’s cube is at least θ of the sum of all of them, there are at most 1/θ — and on the flatter streams the early arrivals fill it, because at the start of any stream every candidate is nearly equal. The peak is therefore a property of the share, not of the stream. Only the steep streams escape it, because their heavy keys stand out within the first few dozen arrivals: at Zipf 2 the peak is three at a share of 0.03, and at Zipf 1.5 four.

The proposal’s prediction of a peak under four on Zipf 1 and steeper holds only at Zipf 1.5 and 2, and there only at the larger shares. On Zipf 1 the peak is six even at the largest share, and nineteen at 0.03. Its prediction for Zipf 0.5 — a peak of about ten — holds at a share of 0.1, which is where the bound puts it.

What it costs, charged at the peak

Giving places back during the pass makes the list cheaper than cutting it at the end on every stream from Zipf 0.75 up — 208 words against 364 at Zipf 1, 88 against 274 at Zipf 2 — and still dearer than the best fixed list, 159 and 45; at Zipf 0.5, where the end-of-pass cut won, it loses the winWords a 10% estimate of F3 needs, against the stream's Zipf exponent, 60,000 arrivals over 2,048 keys: every position sampled, the best fixed list of counted candidates, a list of 64 cut at the end to candidates holding 3% of its moment, and the list that gives back its places during the pass at a share of a tenth, charged its largest peak. Zipf 0: sample every position 206, best fixed list 985, share at the end, list of 64 1,730, share during the pass, θ = 0.1 5,552. Zipf 0.25: sample every position 676, best fixed list 1,889, share at the end, list of 64 1,874, share during the pass, θ = 0.1 5,690. Zipf 0.5: sample every position 5,260, best fixed list 1,526, share at the end, list of 64 1,304, share during the pass, θ = 0.1 1,972. Zipf 0.75: sample every position 3,930, best fixed list 358, share at the end, list of 64 474, share during the pass, θ = 0.1 444. Zipf 1: sample every position 1,882, best fixed list 159, share at the end, list of 64 364, share during the pass, θ = 0.1 208. Zipf 1.5: sample every position 632, best fixed list 51, share at the end, list of 64 354, share during the pass, θ = 0.1 170. Zipf 2: sample every position 372, best fixed list 45, share at the end, list of 64 274, share during the pass, θ = 0.1 88.1003001,0003,00000.2500.5000.75011.502Zipf exponent of the streamwords for 10% (log scale)sample every positionshare at the end, list of 64share during the pass, θ = 0.1best fixed list60,000 arrivals, 2,048 keys, F3words, log scale
Fig. 3 Words for a 10% estimate against the Zipf exponent: every position sampled, the best fixed list, a list of 64 cut at the end of the pass, and the list giving back its places at a share of 0.1. At Zipf 1: 1,882, 159, 364 and 208. At Zipf 2: 372, 45, 274 and 88. At Zipf 0.5: 5,260, 1,526, 1,304 and 1,972.

Charged its peak, the list that gives back its places is cheaper than the list cut at the end on every stream from Zipf 0.75 up — 208 words against 364 at Zipf 1, 88 against 274 at Zipf 2 — and dearer than the best fixed list everywhere: 159 at Zipf 1, 45 at Zipf 2. The proposal’s target, within a fifth of the best fixed list, misses by 31% at Zipf 1 and by nearly double at Zipf 2. And at Zipf 0.5, the one stream where the end-of-pass cut beat every fixed list, the list that gives back is the dearest of the three lists, 1,785 words at its best share against the cut’s 1,304.

At the steepest stream the comparison is closest to fair and still lost. At Zipf 2 the list’s peak is two candidates and its final length one, the fixed list’s length; the difference is that the giving-back list’s best sketch is twice as wide, sixteen columns to eight. A list that drops and re-admits candidates hands some of their counting back to the sketch, whose estimate a re-admitted candidate starts from, and a narrow sketch’s estimate is a worse start than a count kept from the first arrival.

Every share, against the best of the others

No share brings the list within a fifth of the best of the plain sampler and the best fixed list on any stream: at Zipf 1 the best share costs 1.31 times it and at Zipf 0.5 1.17; the larger share wins on steep streams and the smaller at Zipf 0.5, where the cut at the end of the pass is 0.85Words for a 10% estimate of F3, as a ratio to the cheaper of the plain sampler and the best fixed list, against the Zipf exponent, for the list giving back its places at three shares and the list of 64 cut at the end. Share during the pass, θ = 0.01: Zipf 0 101.40, Zipf 0.25 15.85, Zipf 0.5 1.85, Zipf 0.75 1.22, Zipf 1 1.57, Zipf 1.5 3.47, Zipf 2 2.09. Share during the pass, θ = 0.03: Zipf 0 54.27, Zipf 0.25 15.75, Zipf 0.5 1.17, Zipf 0.75 1.17, Zipf 1 1.50, Zipf 1.5 3.41, Zipf 2 2.02. Share during the pass, θ = 0.1: Zipf 0 26.95, Zipf 0.25 8.42, Zipf 0.5 1.29, Zipf 0.75 1.24, Zipf 1 1.31, Zipf 1.5 3.33, Zipf 2 1.96. Share at the end, list of 64: Zipf 0 8.40, Zipf 0.25 2.77, Zipf 0.5 0.85, Zipf 0.75 1.32, Zipf 1 2.29, Zipf 1.5 6.94, Zipf 2 6.09.12510205010000.2500.5000.75011.502Zipf exponent of the streamwords against the best of the others (log scale)share at the end, list of 64share during the pass, θ = 0.01share during the pass, θ = 0.03share during the pass, θ = 0.11 = the best of the plain sampler and every fixed listratio, log scale
Fig. 4 Words at each share, as a ratio to the cheaper of the plain sampler and the best fixed list, against the Zipf exponent, beside the list of 64 cut at the end. At Zipf 1: 1.57, 1.50 and 1.31 at shares of 0.01, 0.03 and 0.1, and 2.29 for the cut list. At Zipf 0.5: 1.85, 1.17 and 1.29, and 0.85 for the cut list. On the flat stream every list is many times the plain sampler.

No share brings the list within a fifth of the best of the plain sampler and the best fixed list on any stream; the closest are a share of 0.03 at Zipf 0.5 and 0.75, 17% over each, and a share of 0.1 at Zipf 1, 31% over. The larger share is better on the steep streams, because it holds the early peak to ten and the stream’s heavy keys pass it easily. At Zipf 1 its list ends the pass with two candidates where the smaller shares end with three and six, and the difference in words between the shares there — 249, 239 and 208 — is mostly the difference in their peaks, 27, 19 and 6 candidates. The smaller share is better at Zipf 0.5, because there the keys worth counting are many and each holds a small part of the moment, and a share of a tenth would turn most of them away. Neither is best on both, which is the earlier page’s finding about the end-of-pass share again: the share that selects well depends on the skew, and the skew is what the list was meant to discover.

On the flat stream and at Zipf 0.25 every list loses to sampling every position, the best fixed list by nearly a factor of three and the lists here by eight or more, as the earlier pages found for every list: there are no heavy keys to count, a sketch wide enough to rank keys that are all alike costs more than all the copies it saves, and the estimate that squares the stream is the reminder that a moment of a flat stream is cheap to estimate directly. The share was never going to help there; what it adds on the flat stream is a peak at its bound, ten or thirty-three candidates for keys none of which is heavy.

Where the words go

What the peak costs in words: at Zipf 1 the list given back at its best share holds 6 candidates at its peak, 18 words, against the fixed list's 3 and the end-of-pass cut's 192; at Zipf 0.5 its peak is 33 candidates, 99 words, and its sketch and copies cost 1,686 against the end-of-pass cut's 1,112Words of each part — the sketch at five counters a column, the list at three words a counted candidate (the peak, for the list given back), the copies at two each — for the best fixed list, the list of 64 cut at the end, and the list given back at its best share, at Zipf 1 and Zipf 0.5. Zipf 1, best fixed list of 1: sketch 80, list 3, copies 76, 159 in all. Zipf 1, list of 64 cut at the end: sketch 160, list 192, copies 12, 364 in all. Zipf 1, given back at θ = 0.1: sketch 160, list 18, copies 30, 208 in all. Zipf 0.5, best fixed list of 16: sketch 1,280, list 48, copies 198, 1,526 in all. Zipf 0.5, list of 64 cut at the end: sketch 640, list 192, copies 472, 1,304 in all. Zipf 0.5, given back at θ = 0.03: sketch 1,280, list 99, copies 406, 1,785 in all.Zipf 1, best fixed list of 1159Zipf 1, list of 64 cut at the end364Zipf 1, given back at θ = 0.1208Zipf 0.5, best fixed list of 161,526Zipf 0.5, list of 64 cut at the end1,304Zipf 0.5, given back at θ = 0.031,785pale: sketch · dark: candidates · green: copieswords for a 10% estimate of F3where the words go
Fig. 5 Words by part — the sketch, the candidates, the copies — for the best fixed list, the list of 64 cut at the end and the list given back at its best share, at Zipf 1 and Zipf 0.5. At Zipf 1 the list given back holds 6 candidates at its peak, 18 words, against 3 for the fixed list and 192 for the list of 64.

At Zipf 1 the list given back costs eighteen words of candidates at its peak, against three for the best fixed list and 192 for the list cut at the end; at Zipf 0.5 its peak is thirty-three candidates, ninety-nine words, and its sketch and copies cost 1,686 words against the cut list’s 1,112. On the steep stream the saving the proposal wanted is there and is most of the difference: the list’s own words fall from 192 to 18, and the sketch and copies are about what the cut list needed.

On the flatter stream the list’s words were never the problem. The cut list paid 192 words for its 64 places and the given-back list 99 for its 33, a saving of 93; the rest of the estimator grew by 574. The given-back list is wrong about which keys to keep in a particular way. A candidate it drops in the first few hundred arrivals and admits again later has lost its exact count for the arrivals in between, and its value is the sketch’s estimate from then on. If many of the keys that end up heavy at Zipf 0.5 were dropped once — and early in the pass no key’s share is safe — then more of the heavy part carries sketch error, and the estimator buys it back with a wider sketch and more copies. That is the likeliest account and it is not separately measured here; what is measured is the 574 words.

What the share was good for

The proposal turned a fixed cost into a peak, and the plates say what kind of peak a share of the list’s own total produces. It is set by the start of the stream, when every key is equal, and bounded by the share alone, so on any stream without keys that stand out at once it is one over the share. A share is a statement about the list relative to itself; at the start of a stream the list is small and every statement about it is large.

The items that survive k counters kept a fixed number of counters and decremented them all when a new key found none free — the Misra–Gries summary — and its guarantee was in terms of the stream’s length: a key with more than m/km/k arrivals survives. That threshold is a share of the arrivals so far, not of the summary, and it grows as the stream does. At the twenty-fifth arrival of a stream of 60,000 it admits keys with a third of an arrival; at the end, keys with 900. The share used here does the opposite: it is generous at the start, when the list is small, and strict at the end. The measured peaks are the cost of that direction.

Measured against the earlier pages’ alternatives, the list that gives back is a useful middle setting on steep streams: it is two or three times cheaper than cutting a long list at the end and needs no knowledge of how many keys to keep, which the best fixed list does. It is not the stream choosing the list’s length, because the stream’s early arrivals choose the peak and every stream’s early arrivals look the same.

What these streams leave out

One kind of stream. Every stream is drawn independently from a fixed Zipf law, so the heavy keys are heavy from the first arrival. A stream whose heavy keys arrive late — a key that becomes popular halfway — would keep candidates it later has to drop and admit late the keys it needs, and the given-back list’s peak might then be set in the middle of the pass. The skew a few counters cannot repair found that how skewed a stream is decides how much a few counters can do; how its skew arrives over time is a second question none of these pages asks.

One cap. The list was capped at 64 candidates, the earlier page’s longest list. At a share of 0.01 the cap is what bounds the peak, not the share.

The sketch’s estimate on re-entry. A re-admitted candidate starts from the sketch’s estimate, as every candidate does. Remembering a dropped candidate’s count elsewhere would remove the re-entry error and cost the memory the drop was meant to save.

Still open: a list that waits before it admits

The peak is set in the first few dozen arrivals because the share treats a list of near-equal light keys the same as a list of established heavy ones. A list could refuse to admit anyone until the sketch has seen enough of the stream to rank keys at all, and admit only keys whose estimate is a share of the arrivals so far, as the counter summaries do, rather than a share of the list.

The measurement that follows gives the list both: no candidate before a warm-up of WW arrivals, from 100 to 5,000, and after it a key joins only if its estimate is at least φ\varphi times the arrivals seen, with the list still dropping candidates below a share of its own total as here. It charges the warm-up’s cost honestly — the heavy keys’ first WW arrivals are counted only by the sketch — and measures the peak, the words and the heavy part’s error on every exponent. The prediction is that a warm-up of 500 arrivals brings the Zipf 1 peak from nineteen to three and the words to within a fifth of the best fixed list, 190 or under, and that at Zipf 0.5 the peak falls to about ten without the re-entry loss, recovering the end-of-pass cut’s 1,304. It could fail at the steep end: on Zipf 2 the heaviest key carries a quarter of the stream, its first 500 arrivals are 125 arrivals counted by the sketch instead of exactly, and the sketch’s error on them may cost more copies than the warm-up saves places. The question is whether the time a list waits can be paid for by the places it does not have to give back, or whether every way of deciding who is heavy early makes the same mistakes as the share, only later.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

The objects this essay names

Each one links to every other essay that touches it.

Count-SketchHeavy hitterPeak spaceSamplingThresholdUnbiased estimatorZipf distribution