Randomised, and the guarantee that changes kind

One nonzero is a birthday problem

A sketched preconditioner's quality is one number, how well the sketch preserves one subspace, and the sketch that ships has one nonzero in each column. It was said to supply the needed distortion at its own width. On an incoherent basis its own width is everyone else's: at four times the dimension CountSketch, uniform sampling and a Gaussian all read κ of 2.6. Put each direction of the basis on a single row and CountSketch is singular on 14 draws of 16 at the same width, by the formula for shared birthdays, and needs the dimension squared to escape it. Two nonzeros reduce that to three draws in sixteen at twice the dimension and none at four. Four nonzeros are a Gaussian for this purpose, at about a sixteenth of its cost to apply.

Worth reading first: The dimension does not appear · Randomisation does not create structure.

The sketch that is not the answer showed what a sketched preconditioner is. Sketch AA to a small matrix SASA, factor it, and use its RR to precondition an iteration on AA itself. The condition number the iteration then sees is the same number at every κ(A)\kappa(A) from a hundred to ten billion, because the spectrum cancels: κ(AR−1)\kappa(AR^{-1}) equals κ(SQ)\kappa(SQ), with QQ an orthonormal basis of the range of AA. So all that decides a sketched preconditioner’s quality is how well SS preserves one subspace.

That essay measured a dense Gaussian sketch and noted why nobody would ship one: applying it costs more than the solve it is meant to save. “The sketches that ship are subsampled randomised Hadamard transforms … or sparse embeddings, CountSketch, with one nonzero per column. The theory in this essay does not care which; the distortion is what it needs, and all three provide it at their own ll.” A sketch that finds the columns it can see then compared range finders on a coherent matrix, and found one nonzero in a row costing a low-rank error that three repaired. Neither measured the one number in question, and “at their own ll” hides what that width is.

One number, three bases

Since κ(SQ)\kappa(SQ) is the whole story, AA can be removed from the experiment and QQ chosen directly. Three orthonormal bases on 1,000 rows are used, at dimension 16. An incoherent one has every row carrying about the average share of the leverage, d/md/m. A half-spiked one has half its directions on single rows and the rest incoherent. A fully spiked one is Q=[I;0]Q = [I;0]: every direction lives on exactly one row, and every leverage is either one or zero. The leverage that did not move has already measured how a row’s leverage can resist an approximation.

Six sketches are applied. A Gaussian one of ll rows. Sparse ones with 8, 4, 2 and 1 nonzeros in each column of SS, each in a random row with a random sign; the last is CountSketch. And uniform sampling of ll rows, scaled, which is what a sketch reduces to if it has no mixing at all. Each is run sixteen times per width, and the smallest singular value decides whether a draw counts as singular.

The median condition number of a sketched orthonormal basis against the sketch's width in multiples of the dimension, every direction on one row, for a Gaussian sketch and for sparse ones, with singular draws drawn at the top of the axisGaussian: 6.96, 4.36, 3.15, 2.68, 2.07, 1.95, 1.56; 4 nonzeros: 6.48, 4.48, 2.95, 2.67, 2.12, 1.90, 1.59; 2 nonzeros: singular, 5.19, 3.33, 2.88, 2.21, 2.41, 1.73; 1 nonzero (CountSketch): singular, singular, singular, singular, singular, singular, 1.00 at widths 1.5, 2, 3, 4, 6, 8, 16 times the dimension.110¹110¹sketch width over dimensionκ(SQ), median of 16Gaussian4 nonzeros2 nonzeros1 nonzero (CountSketch)dimension 16 · 1,000 rows · cut at 40only leverage separates the sketches
Fig. 1 The median condition number of a sketched orthonormal basis against the sketch’s width in multiples of the dimension, for a Gaussian sketch and sparse ones, with singular medians drawn at the top of the axis. The dial sets the basis.

The first stop of the dial, the incoherent basis, is the surprise in the other direction. All four curves lie on top of one another. At twice the dimension the medians are 4.75, 4.44, 4.80 and 4.81, for Gaussian, four, two and one nonzero. At four times it is 2.61, 2.58, 2.57 and 2.68. Uniform sampling also reads 2.64 there. On an incoherent basis every sketch is a Gaussian, including the one with no mixing at all, because each row of QQ is already small and a random selection of them is about as good as a random combination.

So what a Gaussian is buying has nothing to do with the incoherent case, and a benchmark on a random matrix cannot see any difference between these sketches. A person concluding from that benchmark that one nonzero is fine would be correct about that matrix.

Spikes separate them

Now move the dial. The half-spiked basis detaches the one-nonzero sketch from the others: its median is singular up to four times the dimension, with 10 draws of 16 singular at that width, whereas all the others stay close to 2.6. The fully spiked basis makes it stark. At four times the dimension one nonzero is singular on 14 of 16 draws, at eight times on 8 of 16, and at sixteen times on 5 of 16. Uniform sampling is singular on every draw at every width, since it would need to pick all 16 of the non-zero rows from 1,000 and it never will, and no further reading is needed for it.

The reason for one nonzero is familiar to anybody who has counted people in a room.

On a fully spiked basis of dimension 16, the share of one-nonzero sketches that are exactly singular at four widths, against the chance that two of the sixteen spikes share a bucket2 times the dimension: 16 of 16, against 0.99; 4 times the dimension: 14 of 16, against 0.87; 8 times the dimension: 8 of 16, against 0.62; 16 times the dimension: 5 of 16, against 0.38.00.250.50.7512 × dimension: measuredthe chance of a shared bucket4 × dimension: measuredthe chance of a shared bucket8 × dimension: measuredthe chance of a shared bucket16 × dimension: measuredthe chance of a shared bucketshare of sketches singulardimension 16 · sixteen drawsballs into bins, and nothing more
Fig. 2 On a fully spiked basis of dimension 16, the share of one-nonzero sketches that are exactly singular at four widths, against the chance that two of the sixteen spikes share a bucket.

A column of SS with one nonzero sends that row of QQ into one bucket. If two of the sixteen spiked rows land in the same bucket, two rows of SQSQ are merged, and SQSQ loses rank. There is nothing approximate about it: the matrix is singular and no preconditioner exists. The chance is that of two of sixteen people sharing a birthday in a year of ll days, which is about 1−exp⁡(−d2/2l)1 - \exp(-d^2/2l). At ll of 32, 64, 128 and 256 that chance is 0.99, 0.87, 0.62 and 0.38. The measurement gives 16, 14, 8 and 5 draws in sixteen, or 1.00, 0.88, 0.50 and 0.31.

If no collision happens, the sketch does something remarkable: it is a perfect isometry on this basis, up to signs, and κ\kappa is exactly 1.00. That is the median reading at sixteen times the dimension, the first median that is not singular. So a one-nonzero sketch on a spiked basis is either perfect or singular, with nothing in between, and a median across the draws hides that completely. A code that estimates κ\kappa from one run would see either 1.00 or a failure, and neither is a typical value of anything.

The share of one-nonzero sketches singular on a spiked basis against the width over the square of the dimension, at three dimensionsdimension 8: 15 of 16 at 2d, 7 of 16 at 4d, 4 of 16 at 8d, 3 of 16 at 16d; dimension 16: 16 of 16 at 2d, 14 of 16 at 4d, 8 of 16 at 8d, 5 of 16 at 16d; dimension 32: 16 of 16 at 2d, 16 of 16 at 4d, 13 of 16 at 8d, 11 of 16 at 16d.10⁻¹100.250.50.751sketch width over the square of the dimensionshare singulardimension 8dimension 16dimension 32sixteen draws at each widththe width it needs is the dimension squared
Fig. 3 The share of one-nonzero sketches singular on a spiked basis against the width over the square of the dimension, at three dimensions.

Against the width divided by the square of the dimension, three dimensions fall near a single curve, as the formula says they must. So the width that escapes this is proportional to d2d^2, and that is what “its own ll” means for CountSketch. At a dimension of 16, a width of 128 still fails half the time. At a dimension of 32, a width of 256 fails on 13 of 16. A sketch at the conventional four times the dimension is singular nearly always, whatever the dimension. And by a dimension of 1,000 the width needed to be safe is of the order of a million, far past the point where anything has been saved.

Two nonzeros are a long way from one

The repair needs almost nothing.

The median condition number of a sketched orthonormal basis at a width of four times the dimension, by basis and by kind of sketch, with the share singularincoherent: Gaussian 2.61, 0 of 16 singular; 8 nonzeros a column 2.61, 0 of 16 singular; 4 nonzeros 2.58, 0 of 16 singular; 2 nonzeros 2.57, 0 of 16 singular; 1 nonzero (CountSketch) 2.68, 0 of 16 singular; uniform row sampling 2.64, 0 of 16 singular. half on single rows: Gaussian 2.71, 0 of 16 singular; 8 nonzeros a column 2.52, 0 of 16 singular; 4 nonzeros 2.56, 0 of 16 singular; 2 nonzeros 2.78, 0 of 16 singular; 1 nonzero (CountSketch) singular, 10 of 16 singular; uniform row sampling singular, 16 of 16 singular. every direction on one row: Gaussian 2.68, 0 of 16 singular; 8 nonzeros a column 2.51, 0 of 16 singular; 4 nonzeros 2.67, 0 of 16 singular; 2 nonzeros 2.88, 0 of 16 singular; 1 nonzero (CountSketch) singular, 14 of 16 singular; uniform row sampling singular, 16 of 16 singular.12468incoherentGaussian8 nonzeros a column4 nonzeros2 nonzeros1 nonzero (CountSketch)uniform row samplinghalf on single rowsGaussian8 nonzeros a column4 nonzeros2 nonzeros1 nonzero (CountSketch), 10 of 16 singularuniform row sampling, 16 of 16 singularevery direction on one rowGaussian8 nonzeros a column4 nonzeros2 nonzeros1 nonzero (CountSketch), 14 of 16 singularuniform row sampling, 16 of 16 singularκ(SQ) at four times the dimension; singular drawn at 8dimension 16 · 1,000 rowsuniform sampling never sees a spike
Fig. 4 The median condition number of a sketched orthonormal basis at a width of four times the dimension, by basis and by kind of sketch, with the share singular.

With two nonzeros in each column, a spike goes to two buckets. Collisions still happen, but two spikes must share both of their buckets to merge outright, and that is rare at any width worth using. On the fully spiked basis two nonzeros are singular on 9 of 16 at 1.5 times the dimension, 3 of 16 at twice, and on none at three times or above. At four times, the median is 2.88 against the Gaussian’s 2.68. Four nonzeros are not distinguishable from a Gaussian at any width or on any basis measured, within a fifth at every setting, and eight add nothing further.

This agrees with the range-finder measurement from the other side of the field: there, three or four nonzeros in a row brought the error back to the Gaussian’s. It does sharpen it in one way. That essay’s conclusion was that the flatness on an incoherent matrix is useful, because a code need not know its matrix in advance if it pays for three nonzeros. Here the same price buys a qualitatively different guarantee. It is not a matter of a better error: one nonzero’s failure is a singular matrix and a preconditioner that does not exist, and the difference between one and two is what stands between a solve and a Cholesky breakdown.

There is a useful mechanism for why so little suffices. Each spike has become a pair of entries, and SQSQ becomes the incidence matrix of a random graph with ll vertices and dd edges, each spike an edge. Such a matrix loses rank only when an edge set forms a closed structure, and with ll a few times dd a random graph of that density is a forest with at most a few small cycles. That is the threshold behind random-graph arguments in general, and it explains why width proportional to dd now suffices for what needed d2d^2 with a single nonzero. It is a sound account of the mechanism, and these measurements do not distinguish it from others.

What a width is worth, and what a nonzero costs

The iterations to reduce an error by ten to the twelve that a sketched preconditioner's median condition number promises, on a spiked basis, by kind of sketch and widthGaussian: 60, 42, 36, 25; 2 nonzeros: 71, 45, 39, 32; 1 nonzero (CountSketch): no preconditioner, no preconditioner, no preconditioner, no preconditioner at widths 2, 3, 4, 8 times the dimension.0255075100Gaussian2 × dimension603 × dimension424 × dimension368 × dimension252 nonzeros2 × dimension, 3 of 16 fail713 × dimension454 × dimension398 × dimension321 nonzero (CountSketch)2 × dimension, 16 of 16 failfails3 × dimension, 16 of 16 failfails4 × dimension, 14 of 16 failfails8 × dimension, 8 of 16 failfailsiterations promised; a median singular is drawn at 110from the rate, not from a runa width is an iteration count
Fig. 5 The iterations to reduce an error by 101210^{12} that a sketched preconditioner’s median condition number promises, on a spiked basis, by kind of sketch and width.

The conversion from κ(SQ)\kappa(SQ) to work is the usual rate, and it says how much each width is worth. A Gaussian at twice the dimension promises 60 iterations, at three times 42, at four times 36, and at eight times 25. Two nonzeros run 71, 45, 39 and 32. So at four times the dimension two nonzeros cost three iterations out of thirty-six. A one-nonzero sketch promises no number at all until the width is beyond any width anyone uses.

And cost is where the sparse sketches win, by a margin that dwarfs all this.

Multiplications in one sketch-and-precondition solve at four times the dimension, on 100,000 rows, sixteen columns and sixteen nonzeros a row, by kind of sketchGaussian: applying 1.0e+8, factorising 1.6e+4, iterating 1.2e+8; 4 nonzeros: applying 6.4e+6, factorising 1.6e+4, iterating 1.2e+8; 2 nonzeros: applying 3.2e+6, factorising 1.6e+4, iterating 1.2e+8.10⁴10⁵10⁶10⁷10⁸10⁹Gaussian, 36 iterationsapplying the sketchits small factorisationthe iterations4 nonzeros, 36 iterationsapplying the sketchits small factorisationthe iterations2 nonzeros, 39 iterationsapplying the sketchits small factorisationthe iterationsmultiplicationscounted, not timedthe sketch is the small part once sparse
Fig. 6 Multiplications in one sketch-and-precondition solve at four times the dimension, on 100,000 rows, sixteen columns and sixteen nonzeros a row, by kind of sketch.

For a matrix of 100,000 rows, sixteen columns and sixteen nonzeros a row, applying a Gaussian of width 64 costs 10810^8 multiplications, as much as all the iterations together. Applying four nonzeros costs 6.4⋅1066.4 \cdot 10^6, and two nonzeros costs 3.2⋅1063.2 \cdot 10^6. The iterations cost about 1.2⋅1081.2 \cdot 10^8 in every case, and the small factorisation is sixteen thousand, a number that can be dropped from any discussion. So with sparse sketches the total is the iterations plus a few per cent. One further nonzero per column adds 1.6⋅1061.6 \cdot 10^6 multiplications to a solve of 1.2⋅1081.2 \cdot 10^8: about one per cent for the guarantee that the preconditioner exists. A person choosing between one nonzero and two is choosing whether to save a little over 1 per cent, against failure on any coherent problem.

The original comparison of these three sketches, “dramatically lower” cost at “slightly worse” guarantees, was too kind by far to one of them. The dimension does not appear described the sparse case in these terms, with one nonzero in each column, and it was entirely correct for the vectors it measured, which are not spiked. It is for an arbitrary subspace, one a program has not looked at, that the two terms part company. And that is the only case where an oblivious sketch was ever needed, because a code that knows its leverages can simply sample by them.

The worst draw, which is the one a code runs

A median is the wrong summary of a method run once, and the worst of sixteen draws separates the sparse sketches further than their medians do. On the spiked basis at four times the dimension, the Gaussian’s worst κ\kappa is 2.85 and eight nonzeros reach 2.93, within a few per cent. Four nonzeros reach 4.25, though their median is the Gaussian’s, and two reach 5.03. Translated into iterations, those worst draws promise 38, 39, 58 and 69. At eight times the dimension they close again to 27, 26, 32 and 35. So “four nonzeros are a Gaussian” is a statement about the median, and a code that wants the Gaussian’s reliability from a single draw should either use eight nonzeros or widen the sketch. This is the same warning as what a single draw cannot report, and it costs little to act on: going from four to eight nonzeros adds 6.4⋅1066.4 \cdot 10^6 multiplications to a solve of 1.2⋅1081.2 \cdot 10^8.

A retry is a different kind of insurance. A singular or nearly singular factor shows on the diagonal of RR at no extra cost, so a code could simply draw again. With one nonzero the chance of success on a fully spiked basis of dimension dd is the birthday formula’s complement, and the expected number of draws is its reciprocal. At a dimension of 16 and a width of four times that, the chance is 0.13, so about eight draws, each with its own product and factorisation. At a dimension of 32 the chance falls to 0.014 and the expected draws are seventy. At 64 it is 2⋅10−42 \cdot 10^{-4} and the expected draws are about five thousand. A retry works for small problems and then stops working, which is an unattractive property in something meant to be used without looking at the data, and one further nonzero removes the need for it at a one per cent cost.

How common is a spiked basis?

Perfectly spiked bases are not common; a data matrix does not arrive as [I;0][I; 0]. But one row of high leverage is common and so is a handful. The half-spiked case here, with eight rows of full leverage, already fails on ten draws of sixteen at four times the dimension, and a matrix with a few dummy variables, indicator columns, or a block of rows that dominate some direction is halfway to this. A one-hot encoding of a categorical variable with rare categories produces a column with only a few nonzero entries, and an observation that is alone in its category has a leverage of exactly one. Several of those are spikes in exactly the sense measured here. Two observations that hide each other is about the same high-leverage rows from the statistical side. A failure on such data would look like a singular RR in a factorisation, with no evident cause, on a matrix whose condition number is modest.

It helps to say what a code would observe. On a matrix with a few such rows, a one-nonzero sketch gives a factor RR with one diagonal entry many orders below the rest, on about half of the draws, and on the others a perfectly reasonable RR. So the failure looks intermittent, and a person debugging it will reasonably suspect the data or the seed rather than the sketch. A code that retries silently has made it invisible as well, and that code’s run time then varies from one seed to the next by a factor that has no obvious reason. That is an unusual failure mode for something usually described in terms of a modest constant.

Sixteen draws at a dimension of sixteen

Dimension 16 at 1,000 rows, sixteen draws per setting, and three bases that were built to be clear cases. Sixteen draws can only resolve a failure rate of about six per cent, so “no draw singular” is not the same as “never”. The iteration counts are from a rate formula rather than from running LSQR, although the original essay found a run to agree with its rate. The cost count treats a product by a sparse sketch as ζ\zeta per nonzero with no regard for memory access, and the actual gap with a Gaussian on a real machine depends on which arithmetic is fast. Subsampled Hadamard transforms have not been measured here, and nor have sparse sketches with nonzeros placed in the rows rather than in the columns, which is a different object with different collisions.

Still open: how few nonzeros on real leverage, and a sketch that checks itself

Graded leverage rather than spikes. The bases here have leverages of one and zero. The prediction with a sign is that on a basis whose leverages fall geometrically by a factor of two, the one-nonzero sketch at four times the dimension is never singular, because the small leverages leave room in every bucket, but it reads a median κ\kappa above five, twice the Gaussian’s, while two nonzeros read within a fifth. So the failure on ordinary data would be a factor of a few rather than a catastrophe, and it would still be priced in iterations.

The half-spiked retry. A half-spiked basis has fewer spikes to collide, so its success rate is the birthday formula at half the dimension. The prediction is that with eight spikes at a width of 64, a one-nonzero sketch succeeds on two draws in three rather than the six in sixteen measured here, if the incoherent half of the basis does not contribute collisions of its own, and that the shortfall measured against that formula is a direct reading of how much of a basis’s failure is due to its incoherent part.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A flat tag is an object no other essay names yet.

Condition numberOversamplingRandom projectionSketch-and-preconditionSketchingSubspace-embedding