A rank that depends on the thread count
Worth reading first: Rank is a decision · The same program, twice · A block nobody can call sparse.
Rank is a decision is one of this site’s earliest essays and its claim is that rank is not a property a floating-point matrix has: the singular values decay, there is no gap, and where they are cut is a choice that should be reported with the number.
This essay is that claim with one word added. The cut is a choice, and which side of it a singular value falls on is not entirely the caller’s.
Seven curves that lie on top of each other for the first several values and separate below about 10⁻¹³ of σ₁. Counting the values above the threshold gives 12, 12, 12, 10, 10, 11, 11.
One matrix. Three different answers to how many columns does this have.
What is fixed and what is not
The matrix is fixed, exactly: 60 × 14, with singular values falling by a factor of 10^1.1 per index, generated once from a seeded stream. The threshold is fixed: σ₁ · 10⁻¹⁴, which is a conventional choice and the one this site uses elsewhere. The precision is fixed at binary64.
What varies is how the inner products building the Gram matrix AᵀA were summed — one accumulator, two, four, and so on to sixty. That is the only difference between the seven curves, and it is a difference no part of the program specifies.
Why the Gram matrix and not the SVD directly
A fair objection: a rank computation would take the singular value decomposition of A rather than the eigenvalues of AᵀA, and forming the Gram matrix squares the condition number, which the road that squares the problem spends a whole essay warning against.
Both halves of the answer matter.
It is what a great deal of software does. A rank test inside a covariance routine, a least-squares solver written on the normal equations, a kernel method, a principal-component computation on a correlation matrix: all of them start from a Gram matrix, because the Gram matrix is what the problem hands them.
And the squaring is what makes the effect visible at a threshold rather than at the last bit. Squaring the conditioning halves the number of digits, so a disagreement that would sit at 10⁻¹⁶ in the singular values of A sits at 10⁻⁸ in the eigenvalues of AᵀA and therefore at 10⁻⁸ in their square roots. The effect is real in either route; the Gram route brings it up to where a conventional threshold can see it.
The honest statement is therefore: this figure measures a rank test on a Gram matrix, that is a common and slightly disreputable thing to do, and the disreputable part is what makes the machine dependence visible rather than what creates it.
The condition, stated exactly
The disagreement is not universal and the boundary is sharp enough to state.
The curves separate below the level at which the computed singular values are made of rounding. Above it every partitioning agrees to many digits. So the rank is machine-dependent exactly when the threshold falls in the part of the spectrum that is rounding — and that is the same condition under which the rank was never well defined in the first place.
The drag makes it concrete. At 0.6 decades an index the spectrum falls slowly, every singular value clears the threshold, and all seven partitionings return 14 — the full rank, with nothing to disagree about. At 1.1 the spectrum reaches the rounding level around the tenth value and the verdicts split three ways. At 1.4 and 1.6 they split further.
Which yields a rule that is more useful than the alarm: if two partitionings disagree about the rank, the threshold is in the noise, and the rank was a coin flip before the machine was involved. The machine dependence is a symptom of an ill-posed cut rather than a cause of a wrong answer.
Three thresholds, and which of them survive
The threshold in the figure is σ₁·10⁻¹⁴, which is one of three conventions in common use. It is worth asking which of them this affects, because the answer is all of them, differently.
A relative threshold, σ₁·ε. What the figure uses. Its position depends on σ₁, which every partitioning agrees about to fourteen digits, so the threshold itself is stable and only the values being compared with it move. This is the best-behaved of the three.
An absolute threshold. Used where the data has a known noise level — the discrepancy principle’s shape, which when the answer is a choice argues is the only principled way to pick one. Equally affected, and with the same structure: the threshold is fixed and the values wander across it.
A gap-based rule — cut where σᵣ/σᵣ₊₁ is largest. This one is affected worse, and it is the rule that sounds most principled. Below the noise floor the computed singular values are rounding, so the ratios between them are ratios of rounding, and the largest of them lands wherever it lands. A gap rule applied to a spectrum with no gap does not return an arbitrary-but-stable answer; it returns the position of the largest accidental ratio in the noise, which is as machine-dependent as anything in this field.
The ordering is worth carrying: a fixed threshold on a moving value is a coin flip near the line, and a rule that searches for a feature in the noise is a coin flip everywhere in it.
Why that is still worth knowing
A reader might take the previous paragraph as a reason to stop worrying. Three reasons not to.
The verdict is consumed as an integer. A rank of 10 and a rank of 12 do not produce answers that differ slightly; they produce models with a different number of columns, projections onto subspaces of different dimension, and — in a regularised solve — a truncation at a different index. The downstream difference is not proportional to the ambiguity upstream.
Nothing reports the ambiguity. A routine that returns 11 returns 11. It does not return 11, and the tenth and twelfth singular values are within the noise of the threshold, which is the information the caller needs, and which the cheap rank and what it cannot see shows is already missing from the cheap rank-revealing routines for a different reason.
And the ill-posedness is the normal case. A matrix with a clean gap in its spectrum is a matrix somebody constructed. Real spectra decay smoothly — spectral decay measures it on kernel matrices, and the reduction field’s Hankel singular values do the same thing — so the threshold usually does land somewhere in a continuum, and the question of which side a value falls on is usually being decided by something.
Where the curves separate, and what that level is
The seven curves are one curve for the first several values and seven for the rest, and the level at which they part is a computable quantity rather than an accident.
An entry of the Gram matrix is Σₖ AₖᵢAₖⱼ, a sum of sixty products. For the leading columns those products are all of similar size and the same sign, so the summation condition number is near one and every partitioning agrees to the last bit. For the trailing columns — the ones carrying the small singular values — the products cancel almost completely, κ climbs, and the partitionings disagree by κ·u.
The eigenvalues of the Gram matrix inherit that: a perturbation of size ε in the entries moves an eigenvalue by about ε‖A‖², so the computed σ² are uncertain by about u‖A‖² and the computed σ are uncertain below about σ₁√u ≈ σ₁ · 1.5·10⁻⁸.
That is the floor the square-root route imposes and this site has already measured it in another field: the product nobody had to form finds Hankel singular values flooring at σ₁√u — predicted 2.3·10⁻⁹, measured 9.7·10⁻¹⁰ — for exactly this reason. The two essays are the same arithmetic from two directions: there the loss is an accuracy problem, here it is a reproducibility one, and both come from forming a product whose conditioning is the square of the original’s.
Which locates the disagreement precisely. Below σ₁√u the computed singular values are noise, and noise is what differs between partitionings. A threshold below σ₁√u on a Gram-based rank test is reading the machine. The conventional threshold σ₁·10⁻¹⁴ is six orders below that line, which is why this figure has anything in it at all.
What to report instead
The same recommendation the field keeps producing, in its rank-shaped form.
Return the spectrum, not the count. A caller who has the singular values can apply any threshold and can see how many values are near it. This is what rank is a decision argues for on grounds that have nothing to do with machines, and the machine dependence is a second argument for the same thing.
Return the gap ratio at the cut. σᵣ/σᵣ₊₁ is one division and it says whether the cut is a cut or a guess. A ratio of 10³ is a decision; a ratio of 1.2 is a coin flip, and a coin flip is exactly where two partitionings will disagree.
And if a single integer must be returned, make the reduction order-independent. Pre-rounded accumulation on the Gram entries costs three operations an element — for a 60 × 14 matrix, nothing at all — and makes the returned integer a function of the matrix and the threshold, which is what a caller assumed it was. It does not make the integer right, because there is no right one; it makes it stable, which is what a caller who is going to store it in a model actually needs.
What a downstream model does with it
The reason a rank is worse to have unstable than a residual is that a rank is not consumed as a number. It is consumed as a shape, and shapes propagate.
Take the ordinary chain: compute a rank r, keep the leading r singular vectors, project the problem onto them, solve the reduced problem, project back. Two machines with r = 10 and r = 12 do not produce answers 20% apart — they produce answers of different quality on different subspaces, and the difference depends entirely on how much the eleventh and twelfth directions matter for the right-hand side in question.
If those directions are noise, both models are equally good, and the extra two columns in one of them are fitting rounding — which is the whole subject of the regularisation field, and when the answer is a choice is the essay about what happens when a solution is determined by a decision rather than by data.
If those directions carry signal, the smaller model is worse, and by a margin that is not small.
The uncomfortable part is that the machine has no opinion about which. It cuts where the arithmetic happened to land, and whether that was the right place is a question about the problem that the rank test was supposed to be answering.
So the composition is: an ill-posed decision, made by rounding, consumed as a shape, with downstream consequences of unpredictable size and no record anywhere that a decision was made. That is the worst shape in this field, and it is the reason the rank essay sits at the end of the verdict sequence rather than at its start.
The other quantity with the same shape
Worth naming, because it is the same measurement in the field next door.
A rank that is a number of digits makes the point that a numerical rank at a threshold ε is a statement about how many digits the data has. That reading survives here intact, and this essay adds a term to it: the rank is a statement about how many digits the data has and about how many digits the arithmetic delivered, and the second is a property of the machine.
The two are not independent. A matrix whose data carries eight digits and whose Gram matrix is computed to eight digits has a rank that is a coin flip at the eighth; the same matrix with an order-independent Gram computation has a rank that is a stable but arbitrary integer at the eighth. Neither is right. The second is at least the same everywhere, which is the property a pipeline needs even when the number in it is a convention.
One line
A rank is an integer produced by comparing a computed number with a threshold, and when the threshold sits where the arithmetic ran out, the integer is a property of how the work was divided — which is a fact about the machine appearing in the shape of a model.
What the figure would look like on the honest route
A last note to keep the essay from over-claiming, and it is a prediction rather than a measurement, which is why it is labelled as one.
Take the singular values of A directly, by a one-sided Jacobi sweep rather than through AᵀA. Nothing has been squared, so the level at which the computed values are made of rounding is σ₁·u rather than σ₁√u — eight orders lower. A threshold at σ₁·10⁻¹⁴ then sits above that level rather than below it, and the argument this essay makes has nothing to bite on: the values being compared with the threshold are determined to many digits, and a disagreement in their last bits does not move an integer.
That is a prediction from the same mechanism rather than a figure, because the site’s Jacobi sweep does not take a reduction as an argument and instrumenting it would be a second experiment. What is measured, elsewhere, is the floor itself: the product nobody had to form finds the square-root route reaching 10⁻¹⁶ where the product route stops at σ₁√u.
So the honest scope of this essay’s alarm: it is about rank tests that start from a product, which are common and which the least-squares field already warns about for a different reason. A rank test on the matrix itself is a different computation, and the argument here does not reach it.
At other settings
What links here
Computed from the collection, not written here: the essays that point at this one.
Shares its objects with
Essays that name at least two of the same things, and that neither author linked.
- A model that is a rational function — both name numerical rank, rank, singular values
- An inner product with no fixed sign — both name gram matrix, reduction order, run-to-run variation
- A bound every answer satisfies — both name reduction order, run-to-run variation
- A ceiling with a knob on it — both name numerical rank, rank
- Accuracy and agreement are different properties — both name reduction order, run-to-run variation
- An eigenvalue with no value — both name numerical rank, singular values
Named objects
A flat tag is an object no other essay names yet.
Condition squaringGram matrixNumerical rankRankReduction orderRun-to-run variationSingular valuesSpectral decay