Skip to content
AI360Xpert
Beta

The Condition Number

One number for how much a matrix amplifies errors: the ratio of its biggest stretch to its smallest. Large means fragile answers.

A circle entering a matrix with stretches 10 and 1 exits as a long thin ellipse, so errors along the stretched axis grow tenfold
A circle entering a matrix with stretches 10 and 1 exits as a long thin ellipse, so errors along the stretched axis grow tenfold

Why Does This Exist?

Two systems can both be solvable yet differ wildly in trustworthiness. Nudge the inputs by a rounding error and one system's answer barely moves while the other's swings. The condition number

κ(A)=σmax⁡σmin⁡=∥A∥2∥A−1∥2\kappa(A) = \frac{\sigma_{\max}}{\sigma_{\min}} = \lVert A \rVert_2 \lVert A^{-1} \rVert_2

measures that fragility: a relative wobble of ϵ\epsilon in bb can exit Ax=bAx = b amplified up to κ(A)⋅ϵ\kappa(A) \cdot \epsilon in xx. A matrix with κ=10\kappa = 10 is mildly touchy; one with κ=1012\kappa = 10^{12} turns double precision into noise.

This number explains half of numerical linear algebra's behaviour: why the normal equations (XTXX^T X squares the condition number) lose to QR, why feature standardisation speeds up solvers, and why the Hessian's eigenvalue spread in Jacobian and Hessian sets the learning-rate dilemma. Sizes come from norms; systems from linear systems and least squares.

The one idea you need first

Singular values are a matrix's independent stretch factors, largest σmax⁡\sigma_{\max} to smallest σmin⁡\sigma_{\min}. Along the top singular vector inputs grow the most; along the bottom they shrink the most. The condition number is the ratio between those extremes: how uneven the stretching is.

Think of It Like This

A photocopier with uneven zoom

A photocopier enlarges horizontally by 10 and vertically by 1. Feed it a circle and a long thin ellipse comes out. Now smudge the input by a millimetre vertically: the output smudge is a millimetre. Smudge it horizontally: the output smudge is a centimetre.

Worse, run it backwards (solve the system): a millimetre of output smudge could have come from a tenth of a millimetre of input, or from a full millimetre, and the machine cannot tell you which. The zoom ratio 10 is the condition number: the factor by which uncertainty can grow when you invert. A copier with zoom 1 in both directions (orthogonal matrix, κ=1\kappa = 1) never amplifies anything.

How It Actually Works

The error bound that matters: for Ax=bAx = b with perturbed b~=b+Δb\tilde{b} = b + \Delta b,

∥Δx∥∥x∥≤κ(A) ∥Δb∥∥b∥\frac{\lVert \Delta x \rVert}{\lVert x \rVert} \le \kappa(A)\,\frac{\lVert \Delta b \rVert}{\lVert b \rVert}

Relative input error times κ\kappa bounds relative output error. Two consequences: forming XTXX^T X squares κ\kappa (a κ=104\kappa = 10^4 problem becomes 10810^8, borderline unsolvable in single precision), and preconditioning means finding MM such that M−1AM^{-1}A has a smaller κ\kappa before iterating.

Worked example

Take A=diag(1,10)A = \mathrm{diag}(1, 10): stretches 1 and 10, so κ=10/1=10\kappa = 10/1 = 10. Solve Ax=bAx = b with b=[1,10]b = [1, 10], giving x=[1,1]x = [1, 1]. Now perturb bb by [0,0.1][0, 0.1] (a 1% relative wobble, since ∥b∥≈10.05\lVert b \rVert \approx 10.05):

Δx=A−1Δb=[0,0.01],∥Δx∥∥x∥=0.011.414≈0.007\Delta x = A^{-1}\Delta b = [0, 0.01], \quad \frac{\lVert \Delta x \rVert}{\lVert x \rVert} = \frac{0.01}{1.414} \approx 0.007

Here the wobble landed on the tame axis. Aim it at the fragile axis instead, Δb=[0.1,0]\Delta b = [0.1, 0]: Δx=[0.1,0]\Delta x = [0.1, 0] and the relative error hits 0.1/1.414≈7%0.1/1.414 \approx 7\% from a 1% input. Same κ\kappa, direction-dependent damage, worst case exactly κ\kappa-fold. That direction dependence is why the bound uses ≤\le.

Code

The point is the check: compute κ\kappa and confirm the determinant can look innocent while conditioning screams.

import numpy as np

A = np.array([[1.0, 0.0], [0.0, 10.0]])print(float(np.linalg.cond(A)))  # -> 10.0B = np.array([[1e6, 0.0], [0.0, 1e-6]])print(float(np.linalg.det(B)))   # -> 1.0print(float(np.linalg.cond(B)))  # -> 1e+12

BB has determinant 1, the picture of health, and a condition number of a trillion. Determinants measure volume; conditioning measures unevenness. Never read one for the other.

Watch Out For

Trusting a determinant of one

As the code shows, det⁡=1\det = 1 coexists with κ=1012\kappa = 10^{12}: volume preserved, directions mangled. Determinants near zero do flag singularity, but moderate determinants say nothing about conditioning. Ask for κ\kappa (or an estimate) whenever a solve must be trusted, not the determinant.

Training on unscaled features and blaming the optimiser

Features in units of millions beside features in thousandths build a design matrix with enormous κ\kappa, and gradient descent crawls along the valley floor exactly as the Hessian's spread predicts. Standardise first: zero mean, unit variance. It is the cheapest preconditioner in machine learning, and skipping it disguises a conditioning problem as a tuning problem.

The Quick Version

  • κ(A)=σmax⁡/σmin⁡\kappa(A) = \sigma_{\max} / \sigma_{\min}: relative input error can grow κ\kappa-fold in the answer.
  • The diag(1, 10) example scores 10: a 1% wobble can exit near 7% along the fragile axis.
  • Normal equations square κ\kappa; prefer QR or SVD on ill-conditioned problems.
  • Determinant 1 does not mean healthy: the 10610^6/10−610^{-6} diagonal has κ=1012\kappa = 10^{12}.
  • Standardise features first: it is preconditioning you get for free.