A constraint is a weight at infinity
Worth reading first: The projection and the right angle · The road that squares the problem · The zero that is not a missing entry.
Least squares with an equality constraint —
minimise ‖Ax − b‖ subject to Bx = d
— is what a data fit looks like when part of the answer is known: a curve required to pass through a point, a set of coefficients required to sum to one, a flow required to balance at a node. Its optimality conditions are a saddle-point system with AᵀA in the (1, 1) block, so everything the constraint field says applies to it.
It also has a property that nothing else in this collection has. A constraint is the limit of a weight, and the limit can be watched.
The construction, and why anybody would use it
Stack the constraint on top of the objective with a weight τ and solve the ordinary unconstrained problem
minimise ‖ [τB; A]x − [τd; b] ‖
Nothing about it is constrained. It is a least-squares problem of the sort the field’s first essay is about, with more rows than before, and any least-squares routine will take it.
As τ grows the constraint is enforced more and more nearly, and the solution approaches the constrained one. Measured against a solution computed in BigInt rationals from the problem’s own optimality conditions, the error is 4.69·10⁻⁵ at τ = 10², 4.69·10⁻⁹ at 10⁴ and 4.75·10⁻¹³ at 10⁶ — four orders per two decades of τ, which is 1/τ² exactly, at every stop.
The reason to do it at all is that it needs no special routine. A code that already has a least-squares solver acquires a constrained one for the price of stacking two arrays, and that is why the method is in use rather than a curiosity.
Why the limit is quadratic and not linear
The exponent is worth deriving, because “converges” is not a measurement and “τ⁻²” is.
At finite τ the weighted problem’s solution x(τ) satisfies the normal equations (τ²BᵀB + AᵀA)x = τ²Bᵀd + Aᵀb. Write x(τ) = x* + e where x* is the constrained solution, and expand. The leading term of the residual comes from the fact that x* satisfies Bx* = d exactly but does not make Aᵀ(Ax* − b) zero — it makes it equal to −Bᵀλ for the multiplier λ. Balancing that against τ²BᵀBe gives e = O(τ⁻²) in the constrained directions and, because the objective already determines the rest, O(τ⁻²) overall.
The feasibility itself converges at the same rate: ‖Bx(τ) − d‖/‖d‖ is measured at 2.94·10⁻⁵, 2.94·10⁻⁹ and 2.93·10⁻¹³ at τ = 10², 10⁴ and 10⁶, which is 1/τ² to three digits.
That the two quantities share an exponent is not automatic — a method can approach feasibility faster than it approaches optimality or the other way round — and it is worth having measured, because the randomised field’s version of this page finds a case where the exponent is halved and the two come apart.
Where the limit stops, and it is not where the problem says
In exact arithmetic the limit is takeable to any accuracy: 1/τ² is a statement with no rounding in it. What stops it is the solver, and the three solvers stop in three different places.
The normal equations on the weighted problem form (τB)ᵀ(τB) + AᵀA, whose constraint part has entries of size τ². Once τ² reaches 1/u the objective’s contribution is lost in the rounding of the constraint’s, and the matrix becomes numerically the constraint block alone — which is singular, because B has fewer rows than columns. The last weight at which they are within an order of the right answer is 10⁴, against 1/√u = 6.7·10⁷; by τ = 10¹⁴ the answer is wrong by a factor of fourteen.
Householder QR has no such ceiling. It never forms a Gram matrix, so nothing is ever squared, and its error falls with the 1/τ² slope until it reaches the rounding level at τ = 10⁶ and stays there: 4.8·10⁻¹⁵ at τ = 10¹⁴.
Classical Gram–Schmidt is worse than either, for the reason the essay that compared the two Gram–Schmidts gives: its loss of orthogonality grows like κ², and here κ grows like τ.
So the ceiling belongs to the method. The same problem, the same weights, and one route is at 10⁻¹⁴ where another has no digits at all.
The square root of the precision, again
τ ≈ 1/√u is a threshold this site has met three times now and it is the same threshold each time.
The normal equations lose the solution when κ(A) passes 1/√u, because they solve with κ(A)². The definiteness test fails at a distance from singularity of a few ulps for a related reason. And here, a weight passes 1/√u and its square passes 1/u, at which point adding an O(1) quantity to a τ² one changes nothing.
The rule of thumb it produces is worth stating because it is often quoted without the “for the normal equations” attached: the method of weighting can only impose a constraint to about half the machine’s digits. That is true of a solver that forms a Gram matrix and false of one that does not, and the figure separates the two on one pair of axes.
And the order of the rows is worth eleven orders
Householder QR on the stacked matrix has no ceiling, and it has a condition attached that is easier to violate than to notice: the heavily weighted rows have to come first.
Same matrix, same right-hand side, same reflectors, same operation count, and the only difference is whether the constraint rows are above the data rows or below them:
τ constraint first constraint last 10⁴ 4.69·10⁻⁹ 4.69·10⁻⁹ 10⁸ 1.12·10⁻¹⁴ 5.19·10⁻⁹ 10¹⁴ 4.80·10⁻¹⁵ 2.08·10⁻³
Up to τ = 10⁴ they agree. At 10¹⁴ they are a factor of 4.3·10¹¹ apart, and the wrong ordering has lost ten digits.
The mechanism is in the first reflector. A Householder reflector is built from a whole column and annihilates all of it below the first entry; a column whose large entries are at the bottom has them added to the small ones on the way to computing the column’s norm, and the small ones are lost before they are ever used. With the large rows first, the first reflector eliminates them immediately and the small rows enter a problem that has already been scaled.
This is Powell and Reid’s observation, and it is the sharpest instance on this site of the theme it belongs to: identical algebra, identical arithmetic count, different sequencing, ten digits.
What a row ordering is not
Three readings that survive the paragraph above and should not.
It is not pivoting. A least-squares QR with column pivoting reorders the unknowns and is about rank; this reorders the equations and is about scale. A code can do both, and doing the second does not require the first.
It is not equilibration. Scaling the rows to have equal norm would destroy the weighting, which is the whole point of the construction: the constraint rows are supposed to be large. Row scaling and row ordering are different operations and only the second is available here.
And it is not a property of Householder QR being fragile. The measurement shows the opposite: with the right ordering it is at the rounding level at a weight of 10¹⁴, which is a weight at which the alternative methods have nothing. The ordering is a condition on using a good method well.
Which raises the question of why not solve the saddle-point system
The weighted problem is an approximation and the optimality conditions are exact, so a reader who has read the constraint field will ask why anybody weights at all.
Three answers, and none of them is that weighting is better.
The routine is already there, and adding rows to an array is a smaller change to a program than adding a solver. That is not a numerical argument and it is the reason the method is common.
The weighted problem is unconstrained, so it can be handed to an iterative least-squares method — LSQR, or a sketched solve — where the constrained version would need a projection at every step.
And the weight is a knob. Some problems want the constraint enforced nearly rather than exactly, because it came from a measurement rather than from a law, and then τ is a modelling parameter with a meaning rather than a numerical device. That is the case where the regularisation field’s whole question reappears: how much of the data to believe, expressed as a weight.
The other way the same trade appears
There is a mirror image of this page in the constraint field, and putting the two side by side is worth a paragraph because they look like opposite advice.
The sixth essay there takes an exact constrained system and perturbs it — adds δ to one block and −γ to the other — in order to make the factorisation well behaved, and then measures how much the perturbation costs. This page takes an exact constrained system and approximates it by a weight, and measures how much the approximation costs.
They are the same move in opposite directions. There, the constraint is exact and is loosened to buy a factorisation; here, the constraint is a weight and is tightened to buy exactness. And both end with the same number attached: the error is proportional to the perturbation, the constant is computable, and the practical range is bounded at both ends by the arithmetic.
The difference in the two answers is instructive. There the perturbation is removable, by refining against the unperturbed matrix. Here it is not: refining against the constrained problem would mean having a constrained solver, which is what the whole construction was avoiding. So the weighting method’s error has to be lived with, and how large it is at the largest usable τ is the number that decides whether the method is good enough.
What the exact answer is, and how it is available
The comparison needs a constrained solution that was not computed by any of the three methods, and this page uses the optimality conditions in exact arithmetic.
Form AᵀA and Aᵀb in floating point, assemble the saddle-point system [[AᵀA, Bᵀ], [B, 0]] with the stored doubles, convert every entry to the dyadic rational it already is, and solve in BigInt. That gives the exact solution of the problem the machine is holding, which is the right reference: a comparison against the problem somebody meant would be measuring the rounding of AᵀA rather than the behaviour of the three solvers.
There is a pleasing circularity in it. The reference is computed by forming a Gram matrix and solving a saddle-point system — the two moves this page is about the numerical cost of — and it is exact because BigInt does not round. The moves are not wrong; their arithmetic is.
A weight is not always a device
The construction has been presented as a numerical trick, and in a good many problems it is the model rather than a trick, which changes what the measurement is for.
A constraint that came from a conservation law is exact and should be imposed exactly: mass does not nearly balance. A constraint that came from a calibration measurement is not exact, and imposing it exactly means asserting that one observation is infinitely more reliable than the others. In the second case τ is a statement about relative confidence and the right value of it is finite, small, and chosen from what the measurements are worth — which is the whole subject of another field here.
The numerical content of this page then reads differently. At a modelling τ of, say, 10³, none of the three ceilings is anywhere near: all three solvers agree, the ordering does not matter, and the 1/τ² statement is about a bias that was deliberately introduced and is not an error at all. The measurements above are about the regime where τ is being used to approximate infinity, and that regime is entered on purpose by somebody who wanted an equality and had a least-squares routine.
Separating the two is the difference between reading the figure as a warning and reading it as a specification.
The refusals
The claim the page has to close is the one that reads as a fact about norms: the order of the rows of a least-squares problem does not affect its answer, since a permutation of the rows is a permutation of the residual and the norm is the same. It is exactly true in the algebra. The assertion is fed the pair at τ = 10¹⁴ and required to reject it.
The second refusal covers the reading that a large enough weight enforces the constraint whatever the solver: fed the normal equations at τ = 10¹², where the answer is off by a factor of two, and required to fail. The weight is exact and the arithmetic is not, and past a point more weight buys less.
The third is a control on the reference itself: the exact answer is fed the claim that it misses its own constraint, and required to refuse. An equality constraint is an equality, and a page whose whole subject is how nearly a constraint is satisfied has to know that its yardstick satisfies it exactly.
What to do with all of this
The page has three separate findings and they combine into one rule, which is worth stating plainly because the individual measurements do not.
If a constraint has to be imposed exactly, solve the saddle-point system. The weighting method cannot reach exact — its error is 1/τ² for a finite τ, and τ is bounded by the arithmetic — so “exactly” is not on offer.
If a constraint has to be imposed nearly, weight it, and then two things follow. Use a solver that does not form a Gram matrix, because the one that does stops at half the machine’s digits and stops without saying so. And put the weighted rows first, because a Householder QR that sees them last loses ten of the digits it would otherwise keep.
Neither of the second pair is expensive and neither is discoverable from the answer: the residual is small either way, the factorisation completes either way, and the only quantity that would say otherwise is a comparison against something the code does not have. That is the recurring shape of this whole collection, and it is why the measurement is the essay.
At other settings
What links here
Computed from the collection, not written here: the essays that point at this one.
Reads more easily once this is understood
Essays that name this one as worth reading first.
Shares its objects with
Essays that name at least two of the same things, and that neither author linked.
- A condition number sent to infinity — both name condition number, exact ground truth, normal equations, saddle-point systems
- An eigenvalue count that cannot be slightly wrong — both name condition number, exact ground truth, saddle-point systems
- The basis nobody chose on purpose — both name condition number, qr factorisation, saddle-point systems
- Two condition numbers of one matrix — both name condition number, exact ground truth, saddle-point systems
- When the matrix is wrong too — both name condition number, least squares, normal equations
- A function of a matrix is not a function of its entries — both name condition number, exact ground truth
Named objects
A flat tag is an object no other essay names yet.
Condition numberEquality constrained least squaresExact ground truthHouseholderLeast squaresMethod of weightingNormal equationsQR factorisationRow orderingSaddle-point systems