What is taught wrongly

The threshold that reaches zero

At q = 5 and four errors on a twenty-four-character pattern the filter demands zero shared q-grams, proposes all 2,977 windows, and computes 986,266 table cells where filling the whole table would have cost 96,000. The failure is arithmetic and is knowable before a character is read.

The counting filter’s threshold is t=m+1q(k+1)t = m + 1 - q(k+1). It falls by qq for every error allowed, so for a pattern of twenty-four characters and q=5q = 5 it runs 20, 15, 10, 5 and then zero.

A demand of zero shared qq-grams is not a demand. Every window passes, every window is verified, and the filter has become an expensive way of not filtering: 2,977 windows proposed out of 2,977, and 986,266 table cells computed against the 96,000 that filling the whole table costs.

The share of the text the counting filter proposesA pattern of 24 characters in 4,000 characters of four symbols, with 6 occurrences planted at the stated error count. Each line is one q. The share rises with the errors allowed because the threshold falls with them, and it reaches one exactly where q(k+1) = m + 1 rather than gradually. The vertical axis is logarithmic.0.010.11errors allowed, kshare of windows proposed01234q = 3q = 4q = 5a shaded dot is a collapsed thresholdm = 24 · n = 4,000 · 6 planted1 collapsed rows
Fig. 1 The share of windows proposed as the error budget grows. The line for q = 5 goes to one at k = 4 and the others do not, and the difference is a subtraction rather than a measurement.

Ten times worse than doing nothing

The 986,266 deserves to be read carefully, because “the filter stops helping” understates it by an order of magnitude.

Filling the whole table costs n×mn \times m cells: 96,000. Verifying every window separately costs a banded table of m×(m+2k+1)m \times (m + 2k + 1) cells per window, times 2,977 windows — and because the bands overlap, the same work is done again and again. The result is ten times the cost of the thing the filter exists to avoid.

So the collapse is not a return to baseline. A filter that proposes everything is strictly worse than no filter at all, and by a factor that grows with mm.

What the filter saves, until it does notA pattern of 24 characters in 4,000 characters of four symbols, with 6 occurrences planted at the stated error count. Each line is one q. The value is the whole table's cells divided by the filter's, so one is break-even. Every line reaches it inside this sweep, and the q that reaches it last is not the largest: a longer q-gram raises the threshold and lowers the chance of sharing one, and the two effects trade. The vertical axis is logarithmic.110100errors allowed, ktable cells / filter cells01234q = 3q = 4q = 5a shaded dot is a collapsed thresholdm = 24 · n = 4,000 · 6 planted1 collapsed rows
Fig. 2 The same sweep as a ratio against the whole table. One is break-even; below one the filter is costing more than it saves; and the collapsed point is a tenth.

The collapse is exact, and that is unusual

This collection has measured a filter collapse before. The filter that proposes everything is the seed filter’s, and it arrives gradually: as kk rises the seeds get shorter, short seeds occur by chance, chance hits accumulate, and the candidate fraction climbs through a half and on towards one.

That collapse has two thresholds and neither is sharp. Chance hits appear when a seed falls below logσn\log_\sigma n; the whole text is proposed when the predicted fraction (k+1)(2k+1)/σs(k+1)(2k+1)/\sigma^s reaches one. Both are approximations and the measured curve crosses them smoothly.

The counting filter’s collapse is a subtraction. At q(k+1)=m+1q(k+1) = m+1 the threshold is zero, and a threshold of zero admits everything by definition — not nearly everything, everything, and the plate’s assertion demands exactly that.

One of these two filters can be checked for collapse without running it. That is a real difference in kind, and it is the thing to take from the pair.

What the arithmetic says before anything runs

The whole design space of the counting filter is a subtraction over two integers, and it can be tabulated in advance.

For m=24m = 24: at q=2q = 2 the threshold stays positive to k=6k = 6 and beyond; at q=3q = 3 it reaches 4 at k=6k = 6; at q=4q = 4 it goes negative at k=6k = 6; at q=5q = 5 at k=5k = 5; at q=6q = 6 at k=4k = 4; at q=8q = 8 at k=3k = 3.

So for any pattern length and any error budget there is a largest usable qq, and it is (m+1)/(k+1)\lfloor (m+1)/(k+1) \rfloor minus nothing. That is the sort of statement this collection likes and rarely gets: a parameter choice with a closed form and no measurement in it.

What the arithmetic does not say is which usable qq is best. The threshold being positive is necessary and not sufficient — a filter at q=2q = 2 has a healthy threshold and proposes a great deal, because two-character qq-grams are common. That part needs the sweep.

How many q-grams an occurrence must still share, m = 24Each cell is t = m + 1 − q(k+1): the number of q-grams a window must share with the pattern before it is worth verifying. The shaded cells are where t has reached zero or below, which is a demand of nothing — the filter proposes every window and has stopped being a filter. Nothing here is measured: the collapse is arithmetic, it is known before a text is read, and it happens at q(k+1) = m + 1.k = 0k = 1k = 2k = 3k = 4k = 5k = 6q = 223211917151311q = 3221916131074q = 4211713951-3q = 520151050-5-10q = 6191371-5-11-17q = 81791-7-15-23-31a shaded cell is a threshold of zero or less: every window proposedt = m + 1 − q(k+1) · m = 2411 collapsed cells
Fig. 3 The subtraction, tabulated. Every shaded cell is a configuration that cannot work and every unshaded one is a configuration that might.

Why a long qq collapses first

The direction surprises people who have not written the subtraction down, so it is worth stating the mechanism.

A longer qq-gram is rarer, which is what makes a filter selective. But a longer qq-gram is also destroyed by more errors: one substitution ruins qq of them, so the stock of surviving qq-grams falls faster.

The threshold captures both: it starts higher for a short qq (there are more qq-grams) and falls slower (each error destroys fewer). So the longest qq is the most selective while it works and the first to stop working, and the best choice moves left as the error budget grows.

Measured at k=2k = 2: q=3q = 3 proposes 92 windows, q=4q = 4 proposes 104 and q=5q = 5 proposes 121, so the shortest is already the best. At k=0k = 0 the order is reversed: 8, 6 and 6. The crossover happens between them, which is a measurement rather than arithmetic.

Two collapses, one shape

Set the two filters’ failures side by side and the shape underneath is the same one.

Both filters reduce an expensive stage to a cheap one plus a verification, and both are worth having exactly when the number of candidates is small. Both have a parameter that gets weaker as the error budget grows — the seed length, the shared-qq-gram threshold — and both have a point past which the cheap stage proposes so much that it costs more than the expensive stage would have.

What differs is knowability. The seed filter’s collapse depends on the alphabet, the text length and chance, so it is a measurement; the counting filter’s depends on three integers, so it is a subtraction.

And what also differs is severity. The seed filter at k=4k = 4 on the sweep in this phase proposes 649 candidates and computes 160,446 cells against a table of 96,000 — 1.7 times worse than not filtering. The counting filter at its collapse is ten times worse, because it verifies every window rather than a large fraction of them.

Two filters, one question, two currenciesA pattern of 24 characters against 4,000, answered identically by both filters at every k — checked against the whole table rather than assumed. The bar is cells computed in the verification stage; the number beside it is characters read. The counting filter reads every character and the seed filter reads 41.6% of them, and whichever of the two is the scarce resource decides which filter is better. The table's own cost is 96,000 cells and 96,000 reads at every row.k = 0: q-grams42016,132 readsk = 0: seeds420144 readsk = 1: q-grams5,33617,138 readsk = 1: seeds2,088450 readsk = 2: q-grams16,74418,692 readsk = 2: seeds4,830780 readsk = 3: q-grams27,67519,633 readsk = 3: seeds14,0381,834 readsk = 4: q-grams105,12227,850 readsk = 4: seeds160,44618,091 readsq = 4 · cells drawn · reads besidecells computed in verificationtable: 96,000 cells
Fig. 4 Both filters at five error counts, with the last row of each being past its own collapse. Both are above the table’s cost there and one of them is far above it.

What a practitioner needs before choosing

The two conditions can be stated as a procedure, and it costs one subtraction and one short run.

Subtract. Compute t=m+1q(k+1)t = m + 1 - q(k+1) for the pattern length and error budget in hand. If it is zero or below at every qq worth trying, this filter is not available and the question is which other method to use.

Then measure. For the largest few usable qq, run the filter on a sample of the corpus and read off the candidate fraction. If it is above about 1/(2k+1)1/(2k+1), the verification will cost more than the table would have; below it, the filter pays roughly the reciprocal.

Neither step needs the whole corpus and neither needs a model. This is the sort of thing fitting a class to measurements argues for in the large: where a quantity can be measured cheaply, measuring it beats reasoning about it, and the reasoning is for the part that cannot be measured — here, the arithmetic that rules configurations out before anything runs.

The right response is not a better filter

The obvious reaction to a collapse is to tune, and for this filter the tuning runs out.

At m=24m = 24 and k=5k = 5 the largest usable qq is 4, which gives a threshold of 1 — a demand that a window share one four-gram with the pattern, which nearly every window does. At k=6k = 6 the largest usable qq is 3, with a threshold of 4 out of 22, which is not much better.

So past a certain error rate the filter is arithmetically alive and practically useless, and no choice of qq rescues it. The error rate is the thing that killed it: at k/mk/m above about a fifth, a pattern’s qq-grams are so thoroughly damaged that “shares some qq-grams” stops separating occurrences from anything else.

That is the honest reading, and it points at the other approaches rather than at a parameter. The search that spends a budget is the method whose cost does not depend on how much of the text looks plausible, and it has its own collapse in a different variable.

How many q-grams an occurrence must still share, m = 16Each cell is t = m + 1 − q(k+1): the number of q-grams a window must share with the pattern before it is worth verifying. The shaded cells are where t has reached zero or below, which is a demand of nothing — the filter proposes every window and has stopped being a filter. Nothing here is measured: the collapse is arithmetic, it is known before a text is read, and it happens at q(k+1) = m + 1.k = 0k = 1k = 2k = 3k = 4k = 5k = 6q = 21513119753q = 31411852-1-4q = 413951-3-7-11q = 51272-3-8-13-18q = 6115-1-7-13-19-25q = 891-7-15-23-31-39a shaded cell is a threshold of zero or less: every window proposedt = m + 1 − q(k+1) · m = 1619 collapsed cells
Fig. 5 The design space for a short pattern, where most of the plane is shaded. A sixteen-character pattern with three errors has almost no usable q at all.

The check that the collapse is a collapse

The plate’s assertion is two-sided and both halves matter.

Where the threshold is positive, the filter must propose fewer than every window. Where it is zero or below, it must propose all of them — not 99.9 per cent, all — and the check is an equality against the window count.

The second half is what catches a filter that has quietly stopped filtering for some other reason. A bug in the incremental count that made the shared total drift upward would produce a filter proposing everything at every kk, which looks exactly like the collapse and is not; the first half of the check fails on it while the second passes.

The first half is what catches the opposite bug — a threshold applied with the wrong comparison, so that a collapsed configuration still discards windows. That one loses occurrences and every occurrence it does return is real.

The share of the text the counting filter proposesA pattern of 24 characters in 3,000 characters of four symbols, with 6 occurrences planted at the stated error count. Each line is one q. The share rises with the errors allowed because the threshold falls with them, and it reaches one exactly where q(k+1) = m + 1 rather than gradually. The vertical axis is logarithmic.0.010.11errors allowed, kshare of windows proposed012345q = 5a shaded dot is a collapsed thresholdm = 24 · n = 3,000 · 6 planted2 collapsed rows
Fig. 6 One q taken past its own collapse, which is the row the equality check runs on. The step to one is vertical because the threshold is an integer.

A prediction that is right for the wrong reason

The binomial prediction from the previous essay reports a candidate fraction of exactly one at the collapse, and it deserves no credit for it.

The prediction is the upper tail of a binomial at tt; at t0t \le 0 the tail is the whole distribution and the answer is one. It is right because a probability of at least zero successes is one, not because it has modelled the filter’s behaviour.

Everywhere else the prediction is an estimate with real error — over by a factor of five at q=3q = 3, under by a fifth at q=4q = 4, as measured on text with nothing planted in it. A reader seeing the prediction and the measurement agree exactly at the collapse and disagree by fivefold elsewhere should conclude that the agreement is the artefact.

That is the shape a limit is not a prediction warns about, arriving from an unexpected direction: a model that is exactly right in the one regime where it says nothing.

A prediction of chance candidates, on a text with nothing plantedThe predicted share of windows proposed divided by the measured share, on 4,000 characters holding no occurrence of the pattern at all. Only the rows where the filter is still a filter and chance produces something are drawn — everywhere else the measurement is zero and the ratio is not defined. The prediction treats a window's q-grams as independent, which they are not, and the error runs in both directions: 2 of 3 rows over and the rest under. A tolerance fitted to either end would have been wrong at the other.q = 3, k = 34.9x0.33% measuredq = 3, k = 43.6x6.0% measuredq = 4, k = 40.8x5.2% measuredexactm = 24 · nothing plantedpredicted / measured share4,000 characters
Fig. 7 The prediction against the measurement in the regimes where both are informative. The collapsed rows are excluded because a ratio there is arithmetic rather than evidence.

Where the crossing actually is

“The filter stops paying” and “the threshold reaches zero” are two different events, and the first happens earlier.

At q=4q = 4, the thresholds run 21, 17, 13, 9, 5 across k=0k = 0 to 4, none of them zero. The savings run 228.6, 18.0, 5.7, 3.5 and 0.9 — so the filter has stopped paying at k=4k = 4 while its threshold is still five.

The reason is that the saving depends on the candidate count and the candidate count depends on chance hits, which the threshold does not model. At a threshold of five on a twenty-four-character pattern over four symbols, a fair number of windows share five four-grams with the pattern by accident.

So there are two conditions and a practitioner needs both: the threshold must be positive, which is arithmetic, and the candidate fraction must be under about 1/(2k+1)1/(2k+1), which is a measurement. The first is necessary and the second decides.

What the filter saves, until it does notA pattern of 24 characters in 4,000 characters of four symbols, with 6 occurrences planted at the stated error count. Each line is one q. The value is the whole table's cells divided by the filter's, so one is break-even. Every line reaches it inside this sweep, and the q that reaches it last is not the largest: a longer q-gram raises the threshold and lowers the chance of sharing one, and the two effects trade. The vertical axis is logarithmic.110100errors allowed, ktable cells / filter cells01234q = 4a shaded dot is a collapsed thresholdm = 24 · n = 4,000 · 6 plantedno row collapsed
Fig. 8 One q, drawn against break-even. The line crosses one before the threshold reaches zero, which is why the arithmetic is necessary and not sufficient.

The ceiling is a function of the error rate and nothing else

The subtraction gives a largest usable qq, and the sweep at a longer pattern is read as showing that the design space depends on mm as much as on qq. Write the ceiling out and it says something narrower and more useful.

The threshold is positive when q(k+1)<m+1q(k+1) < m+1, so the ceiling is

qmax=m+1k+11q_{\max} = \left\lceil \frac{m+1}{k+1} \right\rceil - 1

which for large mm and kk is m/km/k — the reciprocal of the error rate, with the pattern length cancelling out.

Check it against the grids. At m=24m = 24 and k=4k = 4 the ratio is 25/5, so qmax=4q_{\max} = 4; at k=5k = 5 it is 25/6 and qmaxq_{\max} is still 4; at k=6k = 6 it is 25/7 and qmaxq_{\max} falls to 3. The sixteen-character grid, where “most of the plane is shaded”, is the same arithmetic at a smaller numerator: at k=3k = 3 the ratio is 17/4 and the ceiling is 4, at k=5k = 5 it is 17/6 and the ceiling is 2.

So doubling the pattern length does not buy a larger qq at the same error rate. A twenty-four-character pattern with four errors and a forty-eight-character pattern with eight are both at qmaxq_{\max} near six, because both have one error in six characters. The ceiling is a property of how damaged the pattern is, not of how long it is.

What the length does buy is the threshold one step below the ceiling, and that is where the longer sweep’s advantage actually comes from. At q=4q = 4 and k=5k = 5: a twenty-four-character pattern has t=2524=1t = 25 - 24 = 1, and a thirty-two-character pattern has t=3324=9t = 33 - 24 = 9. Same qq, same budget, nine times the demand — which is why nothing collapses inside the longer sweep’s range.

The general form is worth writing down because it is the design rule the two conditions add up to. Holding the error rate fixed and backing one step off the ceiling gives tk+1t \approx k+1: the usable threshold grows with the number of errors, not despite it, because a longer pattern carrying proportionally more errors also carries proportionally more qq-grams to spare.

That inverts the intuition this filter usually attracts. More errors is not straightforwardly worse — more errors at the same rate is fine, and more errors at a higher rate is what kills it, since the rate is the only thing in the ceiling. A twelve-character pattern with three errors is hopeless and a hundred-and-twenty-character pattern with thirty errors is hopeless in the same way and for the same reason, and the two are the same point on the only axis that matters.

Which sharpens the procedure by one step. Compute the error rate first; it gives the ceiling directly, and if the ceiling is below two the filter is not available at all — q=1q = 1 is character counting rather than qq-gram filtering, so the death condition is k(m1)/2k \ge (m-1)/2, an error rate of a half. Then take one or two steps below the ceiling, where the threshold is a healthy multiple of kk, and measure there. The q-grams an error cannot destroy is the safety half of that and the filter that proposes everything is the other filter’s version, whose ceiling has the alphabet in it and therefore cannot be written down at all.

Why this belongs in the wrong-answers field

The statement this essay is against is not written down anywhere, which is what makes it worth an essay: that a filter’s parameters can be tuned to make it work.

For this filter they cannot, past an error rate the arithmetic names. The design space is a plane, more than half of it is unusable at any interesting error budget, and the usable part shrinks as the pattern shortens. A practitioner who reaches for a qq-gram filter at k/m=0.25k/m = 0.25 and finds it slow will try other qq values, find them all slow, and conclude something about their implementation.

The collection has this shape elsewhere. The ceiling the shortest pattern sets is a limit on a skipping matcher set by the caller’s pattern set rather than by the algorithm; the block that is not a block is a model parameter that the machine does not supply. In each case the fix is not tuning; it is knowing which regime the problem is in before starting.

What survives the collapse

Two things, and they are the reason the filter is worth building at all.

At low error rates it is excellent: at k=0k = 0 it proposes six windows out of 3,977 and computes 420 cells against 96,000, a saving of 228 times. At k=1k = 1 it saves 18 times and at k=2k = 2 nearly 6.

And its collapse is safe. A filter proposing everything returns every occurrence; it is slow and it is not wrong. That is worth stating because the failure mode of a filter that were unsafe past a threshold would be far more dangerous, and this collection has one of those in the same phase: the search that spends a budget is exact at every budget, while a pruned version of it that looked similar would silently miss.

Two filters, one question, two currenciesA pattern of 20 characters against 4,000, answered identically by both filters at every k — checked against the whole table rather than assumed. The bar is cells computed in the verification stage; the number beside it is characters read. The counting filter reads every character and the seed filter reads 14.5% of them, and whichever of the two is the scarce resource decides which filter is better. The table's own cost is 80,000 cells and 80,000 reads at every row.k = 0: q-grams34816,108 readsk = 0: seeds348120 readsk = 1: q-grams3,16816,681 readsk = 1: seeds1,728378 readsk = 2: q-grams10,24117,682 readsk = 2: seeds4,655770 readsk = 3: q-grams38,36321,209 readsk = 3: seeds24,8433,381 readsq = 4 · cells drawn · reads besidecells computed in verificationtable: 80,000 cells
Fig. 9 The filter in the regime it is for: a short error budget where both currencies are small fractions of the table’s.

The two failures a filter can have

It is worth separating the two things that can go wrong with a filter, because only one of them is what this essay is about and they are easy to conflate.

A filter can be unsafe: it discards a window holding an occurrence, and the answer set is wrong. That is what raising the threshold above the lemma does, and it is measured in the q-grams an error cannot destroy — one occurrence of twelve lost, with every returned occurrence still correct.

A filter can be useless: it proposes everything, the answer set is right, and the cost exceeds the baseline. That is the collapse.

The second is the one that happens by itself, as a parameter moves, with nothing wrong anywhere. It is also the one no correctness check can see: every gate in this collection that compares a filter’s answers against exhaustion passes at the collapse, because the answers are exactly right.

So the gate for this has to measure a cost rather than an answer, which is unusual here and is why the plate asserts a candidate fraction rather than an occurrence set. The filter that proposes everything reached the same conclusion for the other filter, and the two together are the reason this collection’s filter plates all print the selectivity.

The honest limit

The four-symbol alphabet is the hardest case for a qq-gram filter and the sweeps use it throughout. On a twenty-six-symbol alphabet a four-gram is 456,976 possibilities rather than 256, chance hits nearly vanish, and the filter stays useful to a higher error rate — the collapse point does not move, because it is arithmetic, but the practical crossing does.

The occurrences are planted by substituting kk characters at random positions, so every planted occurrence has exactly kk errors and they are spread. Clustered errors damage fewer qq-grams, so a corpus whose errors arrive in bursts would give a filter that works past the point measured here.

And the verification cost model charges a banded table per candidate, which is the right charge for a candidate that has to be checked and is generous towards the whole-table baseline, since a single table shares work between overlapping windows. That makes the ten-times figure at the collapse a conservative statement of how bad it is.

Named alongside this one

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

What links here

The 8 essays that link to this one and share the most of its objects, of 9 that link here.

The objects this essay names

Each one links to every other essay that touches it.

Approximate matchingCounting filterCrossoverEdit distanceFalse-positiveFilteringHonest limitMeasurementParameter choiceQ gramSeed-and-extendSelectivityThresholdVerification