Linear algebra in practice: factorisations and conditioning
NUM · Chapter 412 min readAsked at Two Sigma, Citadel Securities, Hudson River Trading, Jump
Assumes Numerical integration: trapezoid, Simpson and Gauss.
After this lesson you should be able to
- Choose a factorisation from the matrix structure.
- Explain the condition number and what it costs in precision.
- Say why you never invert a matrix explicitly.
Solving a linear system is the inner loop of regression, portfolio optimisation and risk. The mathematics says the answer is ; the numerics says never to compute that, and the difference between the two is where precision is lost on real, nearly-collinear financial data.
| Matrix | Use | Cost |
|---|---|---|
| General square | LU with partial pivoting | |
| Symmetric positive definite | Cholesky | — half of LU |
| Rectangular, least squares | QR | |
| Rank-deficient or ill-conditioned | SVD | , most expensive and most robust |
| Large and sparse | Iterative (CG, GMRES) | Per iteration, times the iterations |
Equation 4.2
The condition number
How much a relative error in the input can be amplified in the output. A condition number of means losing about digits of precision.
- Singular values. The ratio of the largest to the smallest is the condition number.
- All sixteen digits of a double are gone; the answer is noise.
Why the normal equations lose twice as much. The condition number of is the *square* of that of . So a design matrix with — awkward but workable, losing six digits — becomes once you form the product, which leaves four digits of a double. QR works on directly and never forms the product, so it loses six digits rather than twelve. On well-conditioned data both approaches agree; on collinear data, which is when you most need the answer, the normal equations can return coefficients that are simply wrong, and nothing in the output says so.
Example 4.4
A design matrix has condition number . How many digits survive solving by QR, and by the normal equations?
Show the worked solutionHide the worked solution
Worked solution
- Formula
- Substitute
- Solve
- Answer
Sanity check. Two significant digits on a regression coefficient is not a rounding issue, it is the difference between a usable estimate and a meaningless one. And a condition number of is entirely ordinary for a factor library with correlated features.
The rest of this lesson is in Premium
You have read the opening. 10 more sections follow, including 4 worked examples and 3 quick checks.
Nothing is charged for 7 days, and you can cancel before then. Or read Complexity: reading it off, and deriving it in full, free.