Module contents
Lesson 18 of 25Advanced 90 min

Pseudoinverse, minimum-norm solutions and spectral filtering

Understand the Moore–Penrose pseudoinverse, minimum-norm least squares, spectral regularization and gradient descent’s implicit bias.

After this lesson you can

  • Derive the pseudoinverse from the SVD and verify Penrose conditions.
  • Characterize minimum-norm least-squares solutions.
  • Analyze ill-conditioning and spectral noise amplification.
  • Compare truncated SVD, Tikhonov and early stopping.
  • Derive gradient descent’s implicit bias and interpolation peak.

Before you start

Motivation: no inverse or too many solutions

Solving Ax=b\mat{A}\vb{x} = \vb{b} with A∈Rm×n\mat{A} \in \R^{m\times n} is scientific computing’s most repeated operation, and the textbook case A\mat{A} square and invertible is rare. Usually one of three situations occurs.

SituationWhat happensWhat is needed
Overdetermined (m>nm > n, rank nn)Usually no solutionx\vb{x} minimizing ∥Ax−b∥\norm{\mat{A}\vb{x} - \vb{b}} (least squares)
Underdetermined (m<nm < n, rank mm)Infinitely many exact solutionsA selection criterion
Rank-deficient (r<min⁡(m,n)r < \min(m, n))Both at onceMinimize residual and select among minimizers

The second case is no academic rarity. A linear model with more parameters than data, or a sufficiently wide network, can exactly fit training data: an entire affine subspace of parameters has zero loss. Equations do not select one, but the training algorithm does, and the choice determines generalization. Robotics has the same issue with a redundant arm (more joints than task degrees of freedom): infinitely many joint velocities yield the same gripper movement (differential inverse kinematics).

A fourth case is more treacherous: A\mat{A} is square and invertible, but so ill-conditioned that A−1b\mat{A}\inv\vb{b} is useless. Deblurring an image, measuring temperature through a wall or reconstructing a CT scan are inverse problems of this kind. The inverse exists, but applied to data with noise 0.1 %0.1\,\% can yield solutions with relative error 10910^9, as a 64-point blur will show.

We construct one tool addressing all four cases. The pseudoinverse A+\mat{A}\pinv gives the canonical answer to the first three: the minimum-norm least-squares solution. For the fourth we modify it with spectral filters, deciding component by component of the SVD how much to trust data. Finally we see gradient descent already applies both ideas implicitly.

The shortest solution

Start with the smallest drawable underdetermined case: two equations and three unknowns.

A=[110.5−0.511],b=[21].\mat{A} = \begin{bmatrix} 1 & 1 & 0.5 \\ -0.5 & 1 & 1 \end{bmatrix}, \qquad \vb{b} = \begin{bmatrix} 2 \\ 1 \end{bmatrix}.

Each equation is a plane in R3\R^3 and solutions form their intersection, a line. Since rows are independent, the null space has dimension 3−2=13 - 2 = 1 and is generated by their cross product, n∝(2,−5,6)\vb{n} \propto (2, -5, 6). By the four subspaces, every solution is a particular solution plus a null-space vector: x(t)=xp+t n\vb{x}(t) = \vb{x}_p + t\,\vb{n}.

Which to choose? A natural criterion is shortest: least ∥x∥\norm{\vb{x}}. Geometrically it is the perpendicular foot from the origin to the line. That point is perpendicular to n\vb{n}, hence belongs to null⁡(A)⊥=row⁡(A)\nullsp(\mat{A})^\perp = \row(\mat{A}), the row span. The shortest solution is therefore the intersection of the solution line and row space: exactly one, because a line parallel to n\vb{n} intersects a plane perpendicular to n\vb{n} once.

To find it seek the form x=A⊤c\vb{x} = \mat{A}\T\vb{c} (row combination) and impose AA⊤c=b\mat{A}\mat{A}\T\vb{c} = \vb{b}. Here AA⊤=[2.25112.25]\mat{A}\mat{A}\T = \begin{bmatrix} 2.25 & 1 \\ 1 & 2.25 \end{bmatrix}, giving c=165(56,4)\vb{c} = \tfrac{1}{65}(56, 4) and

x+=A⊤(AA⊤)−1b=165(54, 60, 32)≈(0.831, 0.923, 0.492),∥x+∥≈1.336.\vb{x}^+ = \mat{A}\T(\mat{A}\mat{A}\T)\inv\vb{b} = \tfrac{1}{65}(54,\ 60,\ 32) \approx (0.831,\ 0.923,\ 0.492), \qquad \norm{\vb{x}^+} \approx 1.336.

You can check n⊤x+=(2⋅54−5⋅60+6⋅32)/65=0\vb{n}\T\vb{x}^+ = (2\cdot 54 - 5\cdot 60 + 6\cdot 32)/65 = 0. Any other solution x++t n^\vb{x}^+ + t\,\hat{\vb{n}} (with unit n^\hat{\vb{n}}) has length, by Pythagoras, ∥x+∥2+t2\sqrt{\norm{\vb{x}^+}^2 + t^2}.

InteractiveThe shortest solution
  • row space row⁡(A)\row(\mat{A})
  • null space (dashed) and solutions
  • x+=A+b\vb{x}^+ = \mat{A}^+\vb{b}
  • gradient descent
Norm along the line: ∥x(t)∥=∥x+∥2+t2\norm{\vb{x}(t)} = \sqrt{\norm{\vb{x}^+}^2 + t^2}
1.30
Gradient descent
Starting point
1.00
iteration 0 of 40
∥x(t)∥\norm{\vb{x}(t)}1.864
∥x+∥=∥A+b∥\norm{\vb{x}^+} = \norm{\mat{A}^+\vb{b}}1.336
n⊤xk\vb{n}\T\vb{x}_k (null-space component)0.000
∥Axk−b∥\norm{\mat{A}\vb{x}_k - \vb{b}}2.2361
∥xk−x+∥\norm{\vb{x}_k - \vb{x}^+}1.336
Starting from 0\vb{0}, the null-space component starts at 0andneverchanges:thelimitis0 and never changes: the limit is \vb{x}^+$.
The solid red line gives solutions of Ax=b\mat{A}\vb{x} = \vb{b}; dashed line is the null space and blue disk is row space. Move tt (or drag below) and watch ∥x(t)∥\norm{\vb{x}(t)}: the minimum is at t=0t = 0, at x+\vb{x}^+, where the line crosses row space at right angles to x+\vb{x}^+. Press play: gradient descent from 0\vb{0} (orange) stays in row space and lands at x+\vb{x}^+. Choose “From x0\vb{x}_0” and drag the orange point: n⊤xk\vb{n}\T\vb{x}_k never changes across iterations, and limit x∞\vb{x}_\infty is no longer shortest. Increase the step beyond ησ12=2\eta\sigma_1^2 = 2 to see divergence.

The interactive anticipates the lesson’s most surprising result: gradient descent, knowing nothing about minimum norm, finds x+\vb{x}^+ if started at the origin. The reason is visible: gradient of 12∥Ax−b∥2\tfrac12\norm{\mat{A}\vb{x} - \vb{b}}^2 is A⊤(Ax−b)\mat{A}\T(\mat{A}\vb{x} - \vb{b}), a combination of rows of A\mat{A}, so each step stays within row⁡(A)\row(\mat{A}) and never touches the component of x\vb{x} in the null space. We prove this below.

The Moore–Penrose pseudoinverse

Formula A⊤(AA⊤)−1\mat{A}\T(\mat{A}\mat{A}\T)\inv applies only with independent rows, and (A⊤A)−1A⊤(\mat{A}\T\mat{A})\inv\mat{A}\T (from the normal equations) only with independent columns. SVD defines a construction that always works.

Recall reduced SVD writes A=∑i=1rσiuivi⊤\mat{A} = \sum_{i=1}^r \sigma_i\vb{u}_i\vb{v}_i\T with r=rank⁡Ar = \rank\mat{A} and σ1≥⋯≥σr>0\sigma_1 \ge \dots \ge \sigma_r > 0. As a map, A\mat{A} takes row space span⁡{v1,…,vr}\spn\{\vb{v}_1, \dots, \vb{v}_r\} bijectively to column space span⁡{u1,…,ur}\spn\{\vb{u}_1, \dots, \vb{u}_r\}, stretching each vi\vb{v}_i to σiui\sigma_i\vb{u}_i, and collapses the null space. The bijection between row and column spaces is the only invertible part. The pseudoinverse reverses it and sends what it cannot invert to zero.

Thus A+ui=vi/σi\mat{A}\pinv\vb{u}_i = \vb{v}_i/\sigma_i for i≤ri \le r and A+y=0\mat{A}\pinv\vb{y} = \vb{0} if y∈null⁡(A⊤)\vb{y} \in \nullsp(\mat{A}\T). It is the “inverse” of arrow vi↦σiui\vb{v}_i \mapsto \sigma_i\vb{u}_i, existing for every matrix.

The definition uses one SVD, which is not unique. Uniqueness of the result follows from a purely algebraic characterization.

Proof

Existence. With X=VΣ+U⊤\mat{X} = \mat{V}\mat{\Sigma}\pinv\mat{U}\T and orthogonal U\mat{U} and V\mat{V}, AXA=U(ΣΣ+Σ)V⊤\mat{A}\mat{X}\mat{A} = \mat{U}(\mat{\Sigma}\mat{\Sigma}\pinv\mat{\Sigma})\mat{V}\T. Matrix ΣΣ+Σ\mat{\Sigma}\mat{\Sigma}\pinv\mat{\Sigma} is diagonal with entries σi⋅σi−1⋅σi=σi\sigma_i\cdot\sigma_i\inv\cdot\sigma_i = \sigma_i if σi>0\sigma_i > 0 and 00 otherwise: it is Σ\mat{\Sigma}, giving (1). Similarly Σ+ΣΣ+=Σ+\mat{\Sigma}\pinv\mat{\Sigma}\mat{\Sigma}\pinv = \mat{\Sigma}\pinv gives (2). Also AX=U(ΣΣ+)U⊤\mat{A}\mat{X} = \mat{U}(\mat{\Sigma}\mat{\Sigma}\pinv)\mat{U}\T and XA=V(Σ+Σ)V⊤\mat{X}\mat{A} = \mat{V}(\mat{\Sigma}\pinv\mat{\Sigma})\mat{V}\T, and ΣΣ+\mat{\Sigma}\mat{\Sigma}\pinv, Σ+Σ\mat{\Sigma}\pinv\mat{\Sigma} are diagonal with ones in the first rr positions: (3) and (4).

Uniqueness. This is guided exercise “Penrose: existence and uniqueness”: if X\mat{X} and Y\mat{Y} satisfy all four conditions, both equal XAY\mat{X}\mat{A}\mat{Y}.

∎

The existence proof exposes two matrices worth recognizing:

AA+=∑i=1ruiui⊤=Pcol⁡(A),A+A=∑i=1rvivi⊤=Prow⁡(A).\mat{A}\mat{A}\pinv = \sum_{i=1}^r \vb{u}_i\vb{u}_i\T = \mat{P}_{\col(\mat{A})}, \qquad \mat{A}\pinv\mat{A} = \sum_{i=1}^r \vb{v}_i\vb{v}_i\T = \mat{P}_{\row(\mat{A})}.

These are orthogonal projections onto column and row spaces. In particular, I−A+A\mat{I} - \mat{A}\pinv\mat{A} projects onto the null space and appears in gradient descent’s implicit bias. Conditions (1) and (2) say A+\mat{A}\pinv inverts A\mat{A} “where possible”, and (3) and (4) that it does so with orthogonal, not oblique, projections. Without (3) and (4) there are generally infinitely many generalized inverses: any left inverse of a full-rank tall matrix satisfies (1) and (2).

Special cases worth remembering

A\mat{A}A+\mat{A}\pinvWhy
Square invertibleA−1\mat{A}\invΣ+=Σ−1\mat{\Sigma}\pinv = \mat{\Sigma}\inv
Full column rank (r=nr = n)(A⊤A)−1A⊤(\mat{A}\T\mat{A})\inv\mat{A}\T, left inverse: A+A=In\mat{A}\pinv\mat{A} = \mat{I}_nsatisfies all four conditions
Full row rank (r=mr = m)A⊤(AA⊤)−1\mat{A}\T(\mat{A}\mat{A}\T)\inv, right inverse: AA+=Im\mat{A}\mat{A}\pinv = \mat{I}_mlikewise
Column vector a≠0\vb{a} \neq \vb{0}a⊤/∥a∥2\vb{a}\T/\norm{\vb{a}}^2case r=n=1r = n = 1
Rank one, uv⊤\vb{u}\vb{v}\Tvu⊤/(∥u∥2∥v∥2)\vb{v}\vb{u}\T/(\norm{\vb{u}}^2\norm{\vb{v}}^2)one sum term
Diagonalinvert nonzero entriesU\mat{U} and V\mat{V} are identities up to signs and order
Zero matrix m×nm\times nzero matrix n×mn\times mr=0r = 0

For example, for a=(3,4)⊤\vb{a} = (3, 4)\T it is a+=125(3,4)\vb{a}\pinv = \tfrac{1}{25}(3, 4), and a+a=1\vb{a}\pinv\vb{a} = 1. Some inverse properties survive: (A+)+=A(\mat{A}\pinv)\pinv = \mat{A}, (A⊤)+=(A+)⊤(\mat{A}\T)\pinv = (\mat{A}\pinv)\T, (cA)+=c−1A+(c\mat{A})\pinv = c\inv\mat{A}\pinv for c≠0c \ne 0 and rank⁡A+=rank⁡A\rank\mat{A}\pinv = \rank\mat{A}. Others do not: generally (AB)+≠B+A+(\mat{A}\mat{B})\pinv \neq \mat{B}\pinv\mat{A}\pinv. With A=[11]\mat{A} = \begin{bmatrix} 1 & 1 \end{bmatrix} and B=[10]\mat{B} = \begin{bmatrix} 1 \\ 0 \end{bmatrix}, AB=1\mat{A}\mat{B} = 1, hence (AB)+=1(\mat{A}\mat{B})\pinv = 1, but B+A+=[10][0.50.5]=0.5\mat{B}\pinv\mat{A}\pinv = \begin{bmatrix} 1 & 0 \end{bmatrix}\begin{bmatrix} 0.5 \\ 0.5 \end{bmatrix} = 0.5.

The minimum-norm solution

We have the object. The theorem justifying the preceding statements is:

Proof

Take full SVD A=UΣV⊤\mat{A} = \mat{U}\mat{\Sigma}\mat{V}\T and change coordinates: y=V⊤x\vb{y} = \mat{V}\T\vb{x} and c=U⊤b\vb{c} = \mat{U}\T\vb{b}. Orthogonal U\mat{U} preserves norms:

∥Ax−b∥2=∥U⊤(UΣV⊤x−b)∥2=∥Σy−c∥2=∑i=1r(σiyi−ci)2+∑i=r+1mci2.\norm{\mat{A}\vb{x} - \vb{b}}^2 = \norm{\mat{U}\T(\mat{U}\mat{\Sigma}\mat{V}\T\vb{x} - \vb{b})}^2 = \norm{\mat{\Sigma}\vb{y} - \vb{c}}^2 = \sum_{i=1}^{r}(\sigma_i y_i - c_i)^2 + \sum_{i=r+1}^{m} c_i^2.

The second sum does not depend on x\vb{x}: it is the part of b\vb{b} outside column space, the irreducible residual. The first vanishes exactly when yi=ci/σiy_i = c_i/\sigma_i for i≤ri \le r, while coordinates yr+1,…,yny_{r+1}, \dots, y_n do not appear and are free. Thus minimizers are x=Vy\vb{x} = \mat{V}\vb{y} with

y=(c1/σ1,…,cr/σr, yr+1,…,yn),yr+1,…,yn∈R arbitrarios.\vb{y} = (c_1/\sigma_1, \dots, c_r/\sigma_r,\ y_{r+1}, \dots, y_n), \qquad y_{r+1}, \dots, y_n \in \R \text{ arbitrarios}.

Since vr+1,…,vn\vb{v}_{r+1}, \dots, \vb{v}_n is a basis of null⁡(A)\nullsp(\mat{A}), this is x⋆+null⁡(A)\vb{x}^\star + \nullsp(\mat{A}) with x⋆=∑i≤r(ci/σi)vi=VΣ+U⊤b=A+b\vb{x}^\star = \sum_{i \le r} (c_i/\sigma_i)\vb{v}_i = \mat{V}\mat{\Sigma}\pinv\mat{U}\T\vb{b} = \mat{A}\pinv\vb{b}, proving 1. Vector x+\vb{x}^+ combines v1,…,vr\vb{v}_1, \dots, \vb{v}_r, spanning row⁡(A)\row(\mat{A}); any other minimizer differs by a nonzero null-space vector outside row⁡(A)\row(\mat{A}): this is 2. Finally V\mat{V} preserves norms, ∥x∥2=∥y∥2=∑i≤r(ci/σi)2+∑i>ryi2\norm{\vb{x}}^2 = \norm{\vb{y}}^2 = \sum_{i \le r} (c_i/\sigma_i)^2 + \sum_{i > r} y_i^2, minimized uniquely with free yiy_i zero; the stated decomposition is Pythagoras with x+⊥x−x+\vb{x}^+ \perp \vb{x} - \vb{x}^+. This is 3.

∎

The expansion to remember is

x+=∑i=1rui⊤bσi vi,\vb{x}^+ = \sum_{i=1}^{r} \frac{\vb{u}_i\T\vb{b}}{\sigma_i}\,\vb{v}_i,

which constructs the solution: project b\vb{b} onto each output direction ui\vb{u}_i, divide by stretch σi\sigma_i and place the result in input direction vi\vb{v}_i. Null-space directions receive nothing. Also Ax+=AA+b=Pcol⁡(A)b\mat{A}\vb{x}^+ = \mat{A}\mat{A}\pinv\vb{b} = \mat{P}_{\col(\mat{A})}\vb{b}: fitted part is the projection of b\vb{b} onto column space, already known from the projections lesson. What is new is which x\vb{x} produces it.

Ill-posed problems: noise divided by σᵢ

Return to the fourth case. Hadamard called a problem well-posed when a solution exists, is unique and continuously depends on data. The pseudoinverse fixes the first two. The third formally holds in finite dimensions, but with a constant potentially 101310^{13}.

Our running example is deconvolution. A signal x∈R64\vb{x} \in \R^{64} (smooth peak and rectangular pulse) passes through a Gaussian blur of width 0.040.04: A\mat{A} is matrix 64×6464\times 64 with Aij∝exp⁡ ⁣(−(ti−tj)2/(2⋅0.042))A_{ij} \propto \exp\!\big(-(t_i - t_j)^2/(2\cdot 0.04^2)\big), symmetric positive definite. Observe b=Ax+e\vb{b} = \mat{A}\vb{x} + \vb{e} with small noise e\vb{e}. Singular values fall from σ1≈0.993\sigma_1 \approx 0.993 to σ64≈4.3⋅10−14\sigma_{64} \approx 4.3\cdot 10^{-14}: condition number κ(A)≈2.3⋅1013\kappa(\mat{A}) \approx 2.3\cdot 10^{13}.

Using the previous expansion and invertibility of A\mat{A},

A+b=∑i=1nui⊤(Ax+e)σi vi=x+∑i=1nui⊤eσi vi.\mat{A}\pinv\vb{b} = \sum_{i=1}^{n} \frac{\vb{u}_i\T(\mat{A}\vb{x} + \vb{e})}{\sigma_i}\,\vb{v}_i = \vb{x} + \sum_{i=1}^{n} \frac{\vb{u}_i\T\vb{e}}{\sigma_i}\,\vb{v}_i.

If noise is white with standard deviation δ\delta per component, ui⊤e\vb{u}_i\T\vb{e} also has standard deviation δ\delta (an orthonormal basis does not change an isotropic Gaussian vector’s distribution). Error in component ii is order δ/σi\delta/\sigma_i: noise is not spread evenly but concentrates in directions of small σi\sigma_i and is multiplied by 1/σi1/\sigma_i. With relative noise 10−310^{-3}, exact inversion yields relative error order 10910^9. This is not rounding: it is the exact inverse applied to slightly perturbed data.

When is there hope? Useful signal in each component is ui⊤Ax=σi vi⊤x\vb{u}_i\T\mat{A}\vb{x} = \sigma_i\,\vb{v}_i\T\vb{x}. For exact solution to have reasonable norm, coefficients ∣ui⊤bexacto∣\abs{\vb{u}_i\T\vb{b}_{\text{exacto}}} must decay on average faster than σi\sigma_i. This is the discrete Picard condition (studied in depth in inverse problems). Smooth signals satisfy it: their oscillating-direction coefficients are tiny. Noise breaks it because its coefficients never decay.

Why “oscillating directions”? Under blur, vi\vb{v}_i changes sign exactly i−1i - 1 times: v1\vb{v}_1 is a hump, v2\vb{v}_2 a wave, through v64\vb{v}_{64} alternating at every point. These are discrete analogues of Fourier modes, and blur attenuates faster oscillations more, like a low-pass filter. Thus our signal’s smooth part (Gaussian peak) has coefficients ∣vi⊤x∣\abs{\vb{v}_i\T\vb{x}} falling below 10−510^{-5} around i=30i = 30, whereas the rectangular pulse with two jumps retains coefficients order 0.10.1 at those indices. That part cannot be recovered above noise, explaining why every regularized reconstruction rounds jumps.

InteractiveThe Picard plot
Spectral coefficients (logarithmic scale)
  • σi\sigma_i
  • ∣ui⊤b∣\abs{\vb{u}_i\T\vb{b}}
  • ∣ui⊤b∣/σi\abs{\vb{u}_i\T\vb{b}}/\sigma_i
Truncated SVD reconstruction, k=kP=23k = k_P = 23
  • true signal
  • reconstruction
Without knowing x\vb{x}, the plot suggests kP=23k_P = 23 with an error of 13.2 %; the best cutoff gives 12.3 %. Inverting all 64 components gives a relative error of 2.1⋅1092.1\cdot 10^{9}.
1.0e−3
Picard cutoff kPk_P23
Relative error at kPk_P13.2 %
Best kk (knowing x\vb{x})29 (12.3 %)
Naive inverse error (k=64k = 64)2.1⋅1092.1\cdot 10^{9}
Noise level δ\delta per component4.1⋅10−44.1\cdot 10^{-4}
Gray shows blur singular values σi\sigma_i; blue, noisy-data coefficients ∣ui⊤b∣\abs{\vb{u}_i\T\vb{b}}; red, their ratio, the size of each component of A−1b\mat{A}\inv\vb{b}. Blue initially falls with gray (signal), then plateaus at the noise floor and red grows unchecked. Move noise from 10−710^{-7} to 10−110^{-1}: the floor rises or falls and cutoff kPk_P moves. At right, truncated SVD uses that cutoff without knowing the signal and comes close to the best possible cutoff. Enable noiseless coefficients to see Picard’s condition: dashed blue decreases on average at least as fast as gray, keeping their ratio bounded; rectangular-pulse jumps prevent much faster decay.

A Picard plot is a diagnostic instrument, not decoration. Without knowing the solution it reveals noise level (floor height), how many SVD components carry information (those above it), and whether the signal satisfies the Picard condition (coefficients fall faster than σi\sigma_i before the floor). The second supplies a natural cutoff kk.

Spectral filters

The expansion of x+\vb{x}^+ suggests the remedy: do not treat all components equally. A spectral filter multiplies each term by factor φi∈[0,1]\varphi_i \in [0, 1]:

xφ=∑i=1rφi ui⊤bσi vi=V Φ Σ+U⊤b,Φ=diag⁡(φ1,…,φn).\vb{x}_\varphi = \sum_{i=1}^{r} \varphi_i\,\frac{\vb{u}_i\T\vb{b}}{\sigma_i}\,\vb{v}_i = \mat{V}\,\mat{\Phi}\,\mat{\Sigma}\pinv\mat{U}\T\vb{b}, \qquad \mat{\Phi} = \diag(\varphi_1, \dots, \varphi_n).

The idea is φi≈1\varphi_i \approx 1 where σi\sigma_i is large against noise (trust data) and φi≈0\varphi_i \approx 0 where small (ignore it). This family is spectral filtering. The pseudoinverse is the trivial filter, φi=1\varphi_i = 1 for every i≤ri \le r.

Truncated SVD. The simplest filter is a step: φi=1\varphi_i = 1 if i≤ki \le k and 00 otherwise. This replaces A\mat{A} with its best rank-kk approximation and applies the pseudoinverse: xk=Ak+b\vb{x}_k = \mat{A}_k\pinv\vb{b}. The parameter is kk and the Picard plot suggests the cutoff.

Tikhonov. Instead of cutting off, penalize solution size:

xλ=arg min⁡x ∥Ax−b∥2+λ∥x∥2,λ>0.\vb{x}_\lambda = \argmin_{\vb{x}}\ \norm{\mat{A}\vb{x} - \vb{b}}^2 + \lambda\norm{\vb{x}}^2, \qquad \lambda > 0.

The objective is a strictly convex quadratic (Hessian 2(A⊤A+λI)2(\mat{A}\T\mat{A} + \lambda\mat{I}) is positive definite), so the unique minimizer is given by zero gradient. Expanded in the SVD basis:

2A⊤(Ax−b)+2λx=02\mat{A}\T(\mat{A}\vb{x} - \vb{b}) + 2\lambda\vb{x} = \vb{0}
Objective gradient set to zero (first-order condition).
1/6

Tikhonov factor φ(σ)=σ2/(σ2+λ)\varphi(\sigma) = \sigma^2/(\sigma^2 + \lambda) is 1/21/2 at σ=λ\sigma = \sqrt{\lambda}, approaches 11 as σ≫λ\sigma \gg \sqrt\lambda and behaves like σ2/λ\sigma^2/\lambda when σ≪λ\sigma \ll \sqrt\lambda. In variable s=ln⁡σs = \ln\sigma it is exactly a logistic sigmoid: φ=1/(1+e−2(s−ln⁡λ))\varphi = 1/\big(1 + e^{-2(s - \ln\sqrt\lambda)}\big). It is a smoothed step centered at λ\sqrt\lambda, with the same logarithmic-scale shape for every λ\lambda.

What matters is its effect on noise. Noise component ii is multiplied not by 1/σi1/\sigma_i but σi/(σi2+λ)\sigma_i/(\sigma_i^2 + \lambda), whose maximum as a function of σ\sigma occurs at σ=λ\sigma = \sqrt\lambda, with value 1/(2λ)1/(2\sqrt\lambda). Tikhonov bounds noise amplification by 1/(2λ)1/(2\sqrt\lambda) regardless of the spectrum of A\mat{A}.

The bias–noise tradeoff

With b=Ax+e\vb{b} = \mat{A}\vb{x} + \vb{e}, any filter’s error separates componentwise into two terms:

xφ−x=−∑i(1−φi) (vi⊤x) vi⏟sesgo de regularizacioˊn+∑iφi ui⊤eσi vi⏟ruido propagado.\vb{x}_\varphi - \vb{x} = \underbrace{-\sum_{i}(1 - \varphi_i)\,(\vb{v}_i\T\vb{x})\,\vb{v}_i}_{\text{sesgo de regularización}} + \underbrace{\sum_{i}\varphi_i\,\frac{\vb{u}_i\T\vb{e}}{\sigma_i}\,\vb{v}_i}_{\text{ruido propagado}}.

The first is deterministic; the second has zero mean if noise does, so the cross term vanishes in expectation and E∥xφ−x∥2=∑i(1−φi)2(vi⊤x)2+δ2∑iφi2/σi2\E\norm{\vb{x}_\varphi - \vb{x}}^2 = \sum_i (1 - \varphi_i)^2(\vb{v}_i\T\vb{x})^2 + \delta^2\sum_i \varphi_i^2/\sigma_i^2 for white noise with standard deviation δ\delta. More filtering (lower kk, higher λ\lambda) reduces propagated noise and increases bias: signal components are lost. Total error forms a U with an intermediate minimum; the art is finding it without knowing x\vb{x}.

InteractiveFilter factors and deconvolution
Filter factors φ(σ)\varphi(\sigma)
  • Tikhonov
  • σi\sigma_i of the matrix
Signal and reconstruction
  • true x\vb{x}
  • data b\vb{b}
  • reconstruction xφ\vb{x}_\varphi
Relative error versus parameter (drag to select)
Too permissive: components pass with σi\sigma_i below the noise, amplified by 1/σi1/\sigma_i. The error is 8.2 times the minimum.
Filter
1.0e−8
1.0e−3
Relative error ∥xφ−x∥/∥x∥\norm{\vb{x}_\varphi - \vb{x}}/\norm{\vb{x}}92.5 %92.5\,\%
Minimum possible with this filter11.3 %11.3\,\%
σ\sigma cutoff1.0⋅10−41.0\cdot 10^{-4}
∥xφ∥\norm{\vb{x}_\varphi}5.025.02
Residual ∥Axφ−b∥\norm{\mat{A}\vb{x}_\varphi - \vb{b}} / noise ∥e∥\norm{\vb{e}}2.4⋅10−3  /  3.2⋅10−32.4\cdot 10^{-3} \;/\; 3.2\cdot 10^{-3}
Top left shows chosen filter factor φ(σ)\varphi(\sigma) logarithmically with 64 blur-matrix singular values as points; right shows true signal (dashed), noisy blurred data (points) and reconstruction. Below is relative error versus parameter: drag the curve. Initial λ\lambda passes noise and creates oscillations; raise λ\lambda to the U minimum and further to see oversmoothing. Switch to truncated SVD and gradient descent: “Compare” shows all three filters at the same cutoff σ\sigma are nearly equal, as are minimum errors.

Choosing the parameter

In the figure you cheat: error is visible because x\vb{x} is known. In a real problem decide from available information. Three classical criteria:

  • Discrepancy principle (Morozov). Knowing noise level ∥e∥\norm{\vb{e}}, fitting data better makes no sense: choose λ\lambda with ∥Axλ−b∥≈∥e∥\norm{\mat{A}\vb{x}_\lambda - \vb{b}} \approx \norm{\vb{e}}. The interactive shows both quantities.
  • L-curve (Hansen). Plot log⁡∥xλ∥\log\norm{\vb{x}_\lambda} against log⁡∥Axλ−b∥\log\norm{\mat{A}\vb{x}_\lambda - \vb{b}} as λ\lambda varies. An L appears: the vertical branch is noise (norm explodes without better fit), the horizontal oversmoothing (residual grows without reduced norm). Choose the corner of maximum curvature. Noise knowledge is unnecessary.
  • Generalized cross-validation (GCV) and ordinary cross-validation, as in machine learning.

None is infallible; the deconvolution cell yields different λ\lambda values and errors near optimum.

The regularization path and ridge regression

As λ\lambda travels from ∞\infty to 00, xλ\vb{x}_\lambda traces a continuous regularization path from 0\vb{0} to x+\vb{x}^+. The latter holds even if A\mat{A} is rank deficient: for σi>0\sigma_i > 0, σi/(σi2+λ)→1/σi\sigma_i/(\sigma_i^2 + \lambda) \to 1/\sigma_i, and for σi=0\sigma_i = 0 the term vanishes for all λ\lambda. Thus,

A+=lim⁡λ→0+(A⊤A+λI)−1A⊤,\mat{A}\pinv = \lim_{\lambda \to 0^+}(\mat{A}\T\mat{A} + \lambda\mat{I})\inv\mat{A}\T,

another pseudoinverse definition explaining its discontinuity: the limit exists for each A\mat{A}, but is not uniform in A\mat{A}.

In statistics this estimator is ridge regression, with design matrix A=X\mat{A} = \mat{X}; its spectral expression is ridge shrinkage in the SVD basis. In robotics it is damped least-squares inverse kinematics: near an arm singularity, Jacobian σmin⁡\sigma_{\min} approaches zero and the pseudoinverse would demand enormous joint speeds, whereas damping bounds response by 1/(2λ)1/(2\sqrt\lambda).

Tikhonov also has a probabilistic reading. If the model is b=Ax+e\vb{b} = \mat{A}\vb{x} + \vb{e} with noise e∼N(0,δ2I)\vb{e} \sim \Normal(\vb{0}, \delta^2\mat{I}) and prior on the unknown is x∼N(0,τ2I)\vb{x} \sim \Normal(\vb{0}, \tau^2\mat{I}), log posterior density, up to constants, is −12δ2∥Ax−b∥2−12τ2∥x∥2-\tfrac{1}{2\delta^2}\norm{\mat{A}\vb{x} - \vb{b}}^2 - \tfrac{1}{2\tau^2}\norm{\vb{x}}^2. Maximizing it is Tikhonov with λ=δ2/τ2\lambda = \delta^2/\tau^2: noise variance divided by signal variance (MAP–Tikhonov equivalence). Minimum norm is the limit τ→∞\tau \to \infty at fixed noise, or δ→0\delta \to 0: trusting data without reservation.

A practical detail: Tikhonov is ordinary least squares on an augmented system,

∥Ax−b∥2+λ∥x∥2=∥[Aλ I]x−[b0]∥2,\norm{\mat{A}\vb{x} - \vb{b}}^2 + \lambda\norm{\vb{x}}^2 = \left\| \begin{bmatrix} \mat{A} \\ \sqrt\lambda\,\mat{I} \end{bmatrix}\vb{x} - \begin{bmatrix} \vb{b} \\ \vb{0} \end{bmatrix} \right\|^2,

solved by QR without forming A⊤A\mat{A}\T\mat{A} (which squares the condition number). For many λ\lambda values one SVD is preferable because each xλ\vb{x}_\lambda then costs only O(rn)\bigO(rn): the code exercise.

Implicit bias of gradient descent

We turn the first interactive’s observation into a theorem. Let f(x)=12∥Ax−b∥2f(\vb{x}) = \tfrac12\norm{\mat{A}\vb{x} - \vb{b}}^2 have gradient ∇f(x)=A⊤(Ax−b)\grad f(\vb{x}) = \mat{A}\T(\mat{A}\vb{x} - \vb{b}), and run gradient descent with fixed step xk+1=xk−η A⊤(Axk−b)\vb{x}_{k+1} = \vb{x}_k - \eta\,\mat{A}\T(\mat{A}\vb{x}_k - \vb{b}).

Proof

Write yk=V⊤xk\vb{y}_k = \mat{V}\T\vb{x}_k and c=U⊤b\vb{c} = \mat{U}\T\vb{b}. Since A⊤A=VΣ⊤ΣV⊤\mat{A}\T\mat{A} = \mat{V}\mat{\Sigma}\T\mat{\Sigma}\mat{V}\T and A⊤b=VΣ⊤c\mat{A}\T\vb{b} = \mat{V}\mat{\Sigma}\T\vb{c}, iteration decouples coordinatewise:

yk+1,i=yk,i−η σi(σiyk,i−ci).y_{k+1, i} = y_{k,i} - \eta\,\sigma_i(\sigma_i y_{k,i} - c_i).

For i≤ri \le r with yi⋆=ci/σiy_i^\star = c_i/\sigma_i, this is yk+1,i−yi⋆=(1−ησi2)(yk,i−yi⋆)y_{k+1,i} - y_i^\star = (1 - \eta\sigma_i^2)(y_{k,i} - y_i^\star). The η\eta assumption gives ∣1−ησi2∣<1\abs{1 - \eta\sigma_i^2} < 1 for all i≤ri \le r (because 0<ησi2≤ησ12<20 < \eta\sigma_i^2 \le \eta\sigma_1^2 < 2), so yk,i→ci/σiy_{k,i} \to c_i/\sigma_i. For i>ri > r, σi=0\sigma_i = 0 and yk+1,i=yk,iy_{k+1,i} = y_{k,i}: those coordinates never move and equal y0,i=vi⊤x0y_{0,i} = \vb{v}_i\T\vb{x}_0. The limit is

∑i≤rciσivi+∑i>r(vi⊤x0) vi=A+b+Pnull⁡(A)x0,\sum_{i \le r}\frac{c_i}{\sigma_i}\vb{v}_i + \sum_{i > r}(\vb{v}_i\T\vb{x}_0)\,\vb{v}_i = \mat{A}\pinv\vb{b} + \mat{P}_{\nullsp(\mat{A})}\vb{x}_0,

and Pnull⁡(A)=I−A+A\mat{P}_{\nullsp(\mat{A})} = \mat{I} - \mat{A}\pinv\mat{A}. This minimizer is nearest to x0\vb{x}_0 because it is the orthogonal projection of x0\vb{x}_0 onto affine subspace x++null⁡(A)\vb{x}^+ + \nullsp(\mat{A}).

∎

This is gradient descent on quadratics with a nuance: the quadratic is not strictly convex, and on flat null-space directions the algorithm simply does not move. Implicit bias is that inertia: nobody requested minimum norm, but the algorithm inherits the initial null-space component, zero if initialized at zero. The same holds for stochastic gradient descent on a consistent system: each stochastic gradient is a multiple of row a~i\tilde{\vb{a}}_i, iteration stays in x0+row⁡(A)\vb{x}_0 + \row(\mat{A}) and, if it converges to a solution, it must be A+b+(I−A+A)x0\mat{A}\pinv\vb{b} + (\mat{I} - \mat{A}\pinv\mat{A})\vb{x}_0, the unique solution in that affine subspace.

The proof gives more than the limit. From x0=0\vb{x}_0 = \vb{0} after mm steps,

xm=∑i≤r[1−(1−ησi2)m]ui⊤bσi vi,\vb{x}_m = \sum_{i \le r}\Big[1 - (1 - \eta\sigma_i^2)^m\Big]\frac{\vb{u}_i\T\vb{b}}{\sigma_i}\,\vb{v}_i,

a spectral filter with φi(m)=1−(1−ησi2)m\varphi_i^{(m)} = 1 - (1 - \eta\sigma_i^2)^m (Landweber iteration in inverse problems). Directions with ησi2m≫1\eta\sigma_i^2 m \gg 1 have converged; those with ησi2m≪1\eta\sigma_i^2 m \ll 1 have barely started, with φi≈mησi2\varphi_i \approx m\eta\sigma_i^2. The cutoff is at σ≈1/ηm\sigma \approx 1/\sqrt{\eta m}, like Tikhonov with λ≈1/(ηm)\lambda \approx 1/(\eta m): stopping early regularizes (early stopping). This is the previous interactive’s third filter.

The interpolation peak

Combine everything in the motivating scenario: regression with nn data and pp features, fit using w^=Xp+y\hat{\vb{w}} = \mat{X}_p\pinv\vb{y}. If p<np < n this is ordinary least squares; if p>np > n it is the minimum-norm interpolator found by gradient descent from zero.

Near p=np = n something striking occurs. For independent Gaussian features of variance 11, the Marchenko–Pastur theorem says that for large nn and pp, singular values of Xp∈Rn×p\mat{X}_p \in \R^{n\times p} fill interval [ ∣n−p∣, n+p ][\,\abs{\sqrt n - \sqrt p},\ \sqrt n + \sqrt p\,]. The lower edge vanishes at p=np = n: a random square matrix is on the verge of singularity, and w^=∑i(ui⊤y/σi)vi\hat{\vb{w}} = \sum_i (\vb{u}_i\T\vb{y}/\sigma_i)\vb{v}_i divides noise y\vb{y} by nearly zero σmin⁡\sigma_{\min}. For p<n−1p < n - 1 an exact formula quantifies this: if y=Xpw+ε\vb{y} = \mat{X}_p\vb{w} + \vb{\eps} with noise independent of Xp\mat{X}_p, zero mean and covariance δ2I\delta^2\mat{I} (we write δ\delta as before to distinguish singular values), then

E∥w^−w∥2=δ2 E[tr⁡ (Xp⊤Xp)−1]=δ2 pn−p−1,\E\norm{\hat{\vb{w}} - \vb{w}}^2 = \delta^2\,\E\big[\tr\,(\mat{X}_p\T\mat{X}_p)\inv\big] = \delta^2\,\frac{p}{n - p - 1},

using the inverse Wishart mean, E[(Xp⊤Xp)−1]=I/(n−p−1)\E[(\mat{X}_p\T\mat{X}_p)\inv] = \mat{I}/(n - p - 1). This diverges as pp approaches nn. If the model also omits influential features, their contribution behaves as extra noise and the peak is larger.

Past p=np = n, σmin⁡≈p−n\sigma_{\min} \approx \sqrt p - \sqrt n grows again and the peak recedes. Error then has two descents, classical and overparameterized: double descent, studied for this exact model by Hastie, Montanari, Rosset and Tibshirani (2022).

InteractiveThe interpolation peak
  • minimum norm (λ=0\lambda = 0)
  • theory or reference
Calculating 5 × 62 fits…
Where the signal is
26
0
Statuscalculating…
Linear regression with n=30n = 30 data and the first pp of 120120 Gaussian features; curves are medians of 5 repetitions. Move pp or drag a graph. Near p=np = n (dotted line), the smallest singular value of Xp\mathbf{X}_p (red spectrum mark) approaches zero according to ∣n−p∣\abs{\sqrt n - \sqrt p}, the norm of w^\hat{\mathbf{w}} shoots up and test error peaks; past p=np = n all fall again. Raise λ\lambda: ridge removes the peak. Change scenario: with distributed signal the largest model wins; with concentrated signal the classical minimum wins.

Three interactive lessons, all consequences of spectral expansion. The peak is not vague “overfitting”: it is division by σmin⁡\sigma_{\min}, visible in the second and third graphs. A little Tikhonov suffices to bound that division and remove it. Whether the overparameterized regime wins depends on the problem: when signal spreads over many features, adding them reduces bias more than the minimum-norm interpolator pays in noise; when concentrated in a few, the classical minimum stays better. Study this in minimum-norm interpolation.

Implementation from scratch

First build the pseudoinverse from SVD with a relative threshold for zero singular values, and check the four Penrose conditions and special cases.

[ ]SVD pseudoinverse and Penrose conditionsBrowser
import numpy as np

def pinv_svd(A, rtol=1e-12):
    """Pseudoinversa de Moore-Penrose a partir de la SVD reducida."""
    U, s, Vt = np.linalg.svd(A, full_matrices=False)
    keep = s > rtol * s[0] if s.size and s[0] > 0 else np.zeros_like(s, dtype=bool)
    s_inv = np.zeros_like(s)
    s_inv[keep] = 1 / s[keep]
    return (Vt.T * s_inv) @ U.T          # V Σ⁺ Uᵀ sin formar matrices diagonales

rng = np.random.default_rng(0)
A = rng.standard_normal((5, 3)) @ rng.standard_normal((3, 4))   # 5×4 de rango 3
X = pinv_svd(A)
penrose = {
    "A X A = A": np.linalg.norm(A @ X @ A - A),
    "X A X = X": np.linalg.norm(X @ A @ X - X),
    "(A X)ᵀ = A X": np.linalg.norm((A @ X).T - A @ X),
    "(X A)ᵀ = X A": np.linalg.norm((X @ A).T - X @ A),
}
for k, v in penrose.items():
    print(f"{k:16s} error {v:.1e}")
print("rango:", np.linalg.matrix_rank(A), " ‖X − np.linalg.pinv(A)‖ =", f"{np.linalg.norm(X - np.linalg.pinv(A)):.1e}")
print("traza de AA⁺ y de A⁺A (= rango):", round(np.trace(A @ X), 10), round(np.trace(X @ A), 10))

B = rng.standard_normal((6, 3))                 # rango de columnas completo
print("columnas completas:", np.allclose(pinv_svd(B), np.linalg.solve(B.T @ B, B.T)))
C = rng.standard_normal((3, 6))                 # rango de filas completo
print("filas completas:   ", np.allclose(pinv_svd(C), C.T @ np.linalg.inv(C @ C.T)))
print("vector (3, 4):     ", pinv_svd(np.array([[3.0], [4.0]])))

An orthogonal projector’s trace is its rank, explaining 3. Now the figure’s 2×32\times 3 example: minimum-norm solution, its orthogonality to the null space and other solutions’ norms.

[ ]The shortest solution del sistema 2×3Browser
A = np.array([[1.0, 1.0, 0.5],
              [-0.5, 1.0, 1.0]])
b = np.array([2.0, 1.0])
x_plus = pinv_svd(A) @ b
n = np.cross(A[0], A[1]); n = n / np.linalg.norm(n)
print("x⁺ =", x_plus, "  65·x⁺ =", 65 * x_plus)
print("‖x⁺‖ =", np.linalg.norm(x_plus), "  nᵀx⁺ =", n @ x_plus)
for t in [-1.0, 0.5, 2.0]:
    x = x_plus + t * n
    print(f"t = {t:4.1f}: ‖Ax − b‖ = {np.linalg.norm(A @ x - b):.1e}, ‖x‖ = {np.linalg.norm(x):.4f}")
x_ls, *_ = np.linalg.lstsq(A, b, rcond=None)
print("lstsq coincide con A⁺b:", np.allclose(x_ls, x_plus))
for eps in [1e-2, 1e-8, 1e-14, 0.0]:
    print(f"ε = {eps:7.0e}:  diag(pinv(diag(1, ε))) = {np.diag(np.linalg.pinv(np.diag([1.0, eps])))}")

The last lines show discontinuity: 1/ε1/\eps grows without bound and at ε=0\eps = 0 jumps to 00.

Lab: deconvolution with spectral filters

The complete Picard-plot problem: blur matrix, noise, naive inverse, default-tolerance pseudoinverse, truncated SVD and Tikhonov with three λ\lambda selection criteria (L-curve, discrepancy and optimum, known only because the signal is synthetic).

[ ]Deconvolution: naive inverse, truncated SVD and Tikhonov with three criteriaBrowser
n, s = 64, 0.04
t = (np.arange(n) + 0.5) / n
A = (1 / n) / (np.sqrt(2 * np.pi) * s) * np.exp(-(t[:, None] - t[None, :])**2 / (2 * s**2))
x_true = np.exp(-((t - 0.28) / 0.07)**2) + 0.7 * ((t > 0.55) & (t < 0.8))
b_exact = A @ x_true
rng = np.random.default_rng(1)
e = 1e-3 * np.sqrt(np.mean(b_exact**2)) * rng.standard_normal(n)   # ruido relativo 10⁻³
b = b_exact + e

U, sig, Vt = np.linalg.svd(A)
c = U.T @ b
print(f"σ₁ = {sig[0]:.3f}, σ₆₄ = {sig[-1]:.1e}, κ(A) = {sig[0] / sig[-1]:.1e}")

def filtered(phi):
    """x_φ = Σ φᵢ (uᵢᵀb / σᵢ) vᵢ."""
    return Vt.T @ (phi * c / sig)

rel = lambda x: np.linalg.norm(x - x_true) / np.linalg.norm(x_true)
print(f"inversa ingenua:          error relativo {rel(np.linalg.solve(A, b)):.1e}")
print(f"pinv (rcond por defecto): error relativo {rel(np.linalg.pinv(A) @ b):.1e}")
errs_k = [rel(filtered((np.arange(n) < k).astype(float))) for k in range(1, n + 1)]
k_best = int(np.argmin(errs_k)) + 1
print(f"SVD truncada, mejor k = {k_best}: error {errs_k[k_best - 1]:.3f}")

lams = np.logspace(-12, 0, 121)
X = np.array([filtered(sig**2 / (sig**2 + l)) for l in lams])
res = np.linalg.norm(X @ A.T - b, axis=1)          # ‖A x_λ − b‖
sol = np.linalg.norm(X, axis=1)                    # ‖x_λ‖
err = np.array([rel(x) for x in X])
# esquina de la curva L: máxima curvatura de (log ‖r‖, log ‖x‖) como curva parametrizada por log λ
lr, lx, ll = np.log(res), np.log(sol), np.log(lams)
d1r, d1x = np.gradient(lr, ll), np.gradient(lx, ll)
d2r, d2x = np.gradient(d1r, ll), np.gradient(d1x, ll)
curv = (d1r * d2x - d2r * d1x) / (d1r**2 + d1x**2)**1.5
i_L = int(np.argmax(curv))
i_D = int(np.argmin(np.abs(res - np.linalg.norm(e))))      # principio de discrepancia
i_O = int(np.argmin(err))
for name, i in [("curva L", i_L), ("discrepancia", i_D), ("óptimo (con x)", i_O)]:
    print(f"{name:15s} λ = {lams[i]:.1e}, error {err[i]:.3f}")

The L-curve and reconstruction proposed by its corner:

[ ]L-curve and reconstructionBrowser
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 2, figsize=(10, 3.6))
ax[0].loglog(res, sol)
for name, i, m in [("curva L", i_L, "o"), ("discrepancia", i_D, "s"), ("óptimo", i_O, "^")]:
    ax[0].loglog(res[i], sol[i], m, label=f"{name}: λ = {lams[i]:.0e}")
ax[0].set_xlabel("‖A x_λ − b‖"); ax[0].set_ylabel("‖x_λ‖"); ax[0].set_title("Curva L"); ax[0].legend()
ax[1].plot(t, x_true, "k--", label="verdadera")
ax[1].plot(t, b, ".", ms=3, label="datos b")
ax[1].plot(t, X[i_L], label="Tikhonov (curva L)")
ax[1].set_ylim(-0.5, 1.5); ax[1].legend(); ax[1].set_title("Deconvolución")
plt.tight_layout(); plt.show()

Inspect the third line of deconvolution output: np.linalg.pinv with default tolerance (10−1510^{-15} relative to σ1\sigma_1) retains all 64 singular values because the smallest is 4.3⋅10−144.3\cdot 10^{-14}, giving the same disaster as inverse. Practical criteria choose λ\lambda values over two orders of magnitude apart (5⋅10−75\cdot 10^{-7} for L-curve, 2⋅10−42\cdot 10^{-4} for discrepancy, optimum 6⋅10−66\cdot 10^{-6}), yet errors lie between 12 %12\,\% and 18 %18\,\% versus 10910^{9} for inverse: the U is broad logarithmically, and avoiding a large order-of-magnitude mistake matters most. Here L-curve under-regularizes (passes some noise) and discrepancy slightly over-regularizes, but its error is within one point of optimum; neither wins every problem.

Lab: verifying implicit bias

Gradient descent on an underdetermined problem of 2020 equations and 5050 unknowns, from zero and three random starts, compared with the theorem’s prediction.

[ ]Gradient descent: A⁺b plus initial null-space projectionBrowser
rng = np.random.default_rng(0)
m_, n_ = 20, 50
A = rng.standard_normal((m_, n_)); b = rng.standard_normal(m_)
A_pinv = np.linalg.pinv(A)
x_plus = A_pinv @ b
P_null = np.eye(n_) - A_pinv @ A
eta = 1 / np.linalg.norm(A, 2)**2          # η = 1/σ₁²

def gd(x0, steps=5000):
    x = x0.copy()
    for _ in range(steps):
        x -= eta * A.T @ (A @ x - b)
    return x

print(f"desde 0:       ‖x − A⁺b‖ = {np.linalg.norm(gd(np.zeros(n_)) - x_plus):.1e}")
for trial in range(3):
    x0 = rng.standard_normal(n_)
    x_inf = gd(x0)
    pred = x_plus + P_null @ x0
    print(f"desde x0 #{trial}:  ‖x − A⁺b‖ = {np.linalg.norm(x_inf - x_plus):.2f},  "
          f"‖x − (A⁺b + P_N x0)‖ = {np.linalg.norm(x_inf - pred):.1e},  residuo {np.linalg.norm(A @ x_inf - b):.1e}")

All four endpoints interpolate data (residual order 10−1510^{-15}), but only the zero start yields x+\vb{x}^+; the others lie distance ∥Pnull⁡x0∥\norm{\mat{P}_{\nullsp}\vb{x}_0} away, exactly as the theorem says.

Verifying the peak formula

Finally, a quick simulation of the inverse Wishart mean explaining the interpolation peak.

[ ]E‖ŵ − w‖² = δ² p / (n − p − 1) in least squares with Gaussian designBrowser
rng = np.random.default_rng(2)
n, delta, trials = 30, 0.5, 2000
for p in [5, 15, 25, 28]:
    w = rng.standard_normal(p)
    sq = []
    for _ in range(trials):
        Xp = rng.standard_normal((n, p))
        y = Xp @ w + delta * rng.standard_normal(n)
        w_hat, *_ = np.linalg.lstsq(Xp, y, rcond=None)
        sq.append(np.sum((w_hat - w)**2))
    print(f"p = {p:2d}: simulado {np.mean(sq):7.3f}   teoría δ²p/(n−p−1) = {delta**2 * p / (n - p - 1):7.3f}")

With p=28p = 28 theory gives 0.25⋅28/1=70.25\cdot 28/1 = 7, about 26 times more than with p=15p = 15 (0.270.27), with the same data count and noise. Simulated mean departs farther from theory as pp nears nn: ∥w^−w∥2\norm{\hat{\vb{w}} - \vb{w}}^2 has a heavy tail there (a few nearly singular matrices dominate the mean), so the interactive shows the median.

The professional version

TaskNumPy / SciPyInternals
Solve min⁡∥Ax−b∥\min\norm{\mat{A}\vb{x} - \vb{b}} at minimum normnp.linalg.lstsq(A, b, rcond=None)SVD (LAPACK gelsd); also returns rank and σi\sigma_i
Same, choosing algorithmscipy.linalg.lstsq(A, b, lapack_driver=...)gelsd (SVD), gelss (SVD) or gelsy (pivoted QR, faster)
Form A+\mat{A}\pinvnp.linalg.pinv(A, rcond=...), scipy.linalg.pinv(A, atol=..., rtol=...)SVD and σi≤\sigma_i \le threshold cutoff
Ridge / Tikhonovsklearn.linear_model.Ridge(alpha=λ, solver="svd") or augmented system with lstsqfactors σi/(σi2+λ)\sigma_i/(\sigma_i^2 + \lambda)
On GPUtorch.linalg.lstsq, torch.linalg.pinvnote: on CUDA, lstsq supports only driver gels, assuming full rank

Correspondence with our implementation is direct. np.linalg.pinv(A, rcond=r) is our pinv_svd with rtol=r: it zeros σi≤r σ1\sigma_i \le r\,\sigma_1, applying truncated SVD with a relative cutoff. Default r=10−15r = 10^{-15} discards rounding zeros, not noise. In an ill-posed problem choosing rcond chooses kk, a modeling decision made from the Picard plot, not by accepting the default.

lstsq with rcond=None uses machine epsilon times max⁡(m,n)\max(m, n) as threshold and returns the minimum-norm solution without forming A+\mat{A}\pinv. That is the correct way to solve a system. Forming A+\mat{A}\pinv (dense n×mn\times m) for one vector costs the same SVD plus a matrix–matrix product and nmnm memory numbers, with no benefit. For many b\vb{b} or λ\lambda, save factorization (U\mat{U}, σ\vb{\sigma}, V⊤\mat{V}\T) and apply it; explicit pseudoinverse is useful when matrix A+\mat{A}\pinv itself is the object of interest (e.g. reusable projector A+A\mat{A}\pinv\mat{A}).

[ ]Libraries versus our implementationBrowser
from scipy import linalg as sla

rng = np.random.default_rng(3)
A = rng.standard_normal((40, 12)) @ rng.standard_normal((12, 60))   # 40×60 de rango 12
b = rng.standard_normal(40)

x1, res, rank, sv = np.linalg.lstsq(A, b, rcond=None)
x2 = sla.lstsq(A, b, lapack_driver="gelsd")[0]
x3 = sla.lstsq(A, b, lapack_driver="gelsy")[0]
x4 = pinv_svd(A) @ b
print("rango detectado por lstsq:", rank)
for name, x in [("scipy gelsd", x2), ("scipy gelsy", x3), ("pinv_svd @ b", x4)]:
    print(f"{name:13s} ‖x − x_lstsq‖ = {np.linalg.norm(x - x1):.1e}")
print(f"‖x_lstsq‖ = {np.linalg.norm(x1):.4f}")

# Tikhonov por tres caminos
lam = 0.5
U, s, Vt = np.linalg.svd(A, full_matrices=False)
x_svd = Vt.T @ (s / (s**2 + lam) * (U.T @ b))
x_aug = np.linalg.lstsq(np.vstack([A, np.sqrt(lam) * np.eye(60)]), np.concatenate([b, np.zeros(60)]), rcond=None)[0]
x_ne = np.linalg.solve(A.T @ A + lam * np.eye(60), A.T @ b)
print(f"Tikhonov: SVD vs aumentado {np.linalg.norm(x_svd - x_aug):.1e},  SVD vs ecuaciones normales {np.linalg.norm(x_svd - x_ne):.1e}")

Common mistakes

Ejercicios

Exercises

ProofA⁺b is the minimum-norm solution
Prove: For every A∈Rm×n\mat{A} \in \R^{m\times n} and every b∈Rm\vb{b} \in \R^m, x+=A+b\vb{x}^+ = \mat{A}^+\vb{b} minimizes ∥Ax−b∥\norm{\mat{A}\vb{x} - \vb{b}} and is the unique minimum-norm minimizer.
0
Let A=UΣV⊤\mat{A} = \mat{U}\mat{\Sigma}\mat{V}\T be a full SVD, r=rank⁡Ar = \rank\mat{A}, and change coordinates using y=V⊤x\vb{y} = \mat{V}\T\vb{x} and c=U⊤b\vb{c} = \mat{U}\T\vb{b}. Make no assumptions about mm, nn or rr.

Step 1 of 4. What does the squared residual become?

ProofPenrose: existence and uniqueness
Prove: X=VΣ+U⊤\mat{X} = \mat{V}\mat{\Sigma}^+\mat{U}\T satisfies the four Penrose conditions, (1) AXA=A\mat{A}\mat{X}\mat{A} = \mat{A}, (2) XAX=X\mat{X}\mat{A}\mat{X} = \mat{X}, (3) (AX)⊤=AX(\mat{A}\mat{X})\T = \mat{A}\mat{X}, (4) (XA)⊤=XA(\mat{X}\mat{A})\T = \mat{X}\mat{A}, and no other matrix does.
0
Let A=UΣV⊤\mat{A} = \mat{U}\mat{\Sigma}\mat{V}\T be an SVD of A∈Rm×n\mat{A} \in \R^{m\times n} with rank rr.

Step 1 of 3. Check (1).

NumericPseudoinverse of a column
For column matrix A=[12]\mat{A} = \begin{bmatrix} 1 \\ 2 \end{bmatrix}, A+\mat{A}^+ is a 1×21\times 2 matrix. What is its second entry?
NumericA Tikhonov factor
With Tikhonov regularization parameter λ=0.01\lambda = 0.01, what filter factor applies to the component with singular value σ=0.1\sigma = 0.1?
NumericStopping early filters
Gradient descent from 0\vb{0} at 12∥Ax−b∥2\tfrac12\norm{\mat{A}\vb{x} - \vb{b}}^2 with step η=1\eta = 1. After m=4m = 4 iterations, what filter factor applies to the component with singular value σ=0.5\sigma = 0.5?
NumericThe shortest solution on a plane
What is the norm of the minimum-norm solution to x1+2x2+2x3=9x_1 + 2x_2 + 2x_3 = 9?
NumericTikhonov’s ceiling
With Tikhonov and λ=10−4\lambda = 10^{-4}, what is the maximum over all σ>0\sigma > 0, of the factor multiplying noise component ui⊤e\vb{u}_i\T\vb{e} in the solution?
QuizGradient descent from another point
Run gradient descent with step 0<η<2/σ120 < \eta < 2/\sigma_1^2 on 12∥Ax−b∥2\tfrac12\norm{\mat{A}\vb{x} - \vb{b}}^2, with A\mat{A} having more columns than rows and full row rank, starting at x0≠0\vb{x}_0 \ne \vb{0}. What does it converge to? Select all correct expressions.

More than one answer may be correct.

QuizWhat survives from the inverse?
Which claims hold for every real matrix A\mat{A} (and B\mat{B} of compatible size)?

More than one answer may be correct.

QuizReading a Picard plot
In an ill-posed problem’s Picard plot, coefficients ∣ui⊤b∣\abs{\vb{u}_i\T\vb{b}} fall alongside σi\sigma_i until i≈20i \approx 20 then plateau around 10−410^{-4}, while σi\sigma_i continues falling to 10−1210^{-12}. Which statements are true?

More than one answer may be correct.

CodeThe Tikhonov path with one SVD
Implement tikhonov_path(A, b, lambdas) returning an array of shape (len(lambdas), n) whose row jj is xλj=arg min⁡x∥Ax−b∥2+λj∥x∥2\vb{x}_{\lambda_j} = \argmin_{\vb{x}} \norm{\mat{A}\vb{x} - \vb{b}}^2 + \lambda_j\norm{\vb{x}}^2. All λj\lambda_j are positive and A∈Rm×n\mat{A} \in \R^{m\times n} may be tall, wide or rank deficient. Compute one SVD and obtain all solutions with filter factors: tests check that you do not solve a system for every λ\lambda.
import numpy as np

def tikhonov_path(A, b, lambdas):
  # 1. Una SVD reducida de A.
  # 2. Para cada lambda, los factores sigma / (sigma**2 + lambda).
  ...
Shift+Enter to run

Summary

  • Pseudoinverse A+=VΣ+U⊤=∑i≤rσi−1viui⊤\mat{A}\pinv = \mat{V}\mat{\Sigma}\pinv\mat{U}\T = \sum_{i \le r}\sigma_i\inv\vb{v}_i\vb{u}_i\T reverses the row-to-column-space bijection and annihilates the left null space. It uniquely satisfies the four Penrose conditions, and AA+\mat{A}\mat{A}\pinv, A+A\mat{A}\pinv\mat{A} are orthogonal projectors onto col⁡(A)\col(\mat{A}) and row⁡(A)\row(\mat{A}).
  • x+=A+b\vb{x}^+ = \mat{A}\pinv\vb{b} is the minimum-norm least-squares solution: the unique minimizer in row⁡(A)\row(\mat{A}), with all others x++null⁡(A)\vb{x}^+ + \nullsp(\mat{A}). It is an inductive-bias choice, not truth, and depends on variable scale.
  • The pseudoinverse is discontinuous and, in ill-posed problems, divides each component’s noise by σi\sigma_i. A Picard plot shows where data coefficients sink into noise and suggests a cutoff.
  • Spectral filters xφ=∑iφi(ui⊤b/σi)vi\vb{x}_\varphi = \sum_i \varphi_i(\vb{u}_i\T\vb{b}/\sigma_i)\vb{v}_i unify truncated SVD (step), Tikhonov or ridge (σ2/(σ2+λ)\sigma^2/(\sigma^2 + \lambda), bounding amplification by 1/(2λ)1/(2\sqrt\lambda)) and early stopping (1−(1−ησ2)m1 - (1 - \eta\sigma^2)^m). The parameter balances bias and noise and is selected by discrepancy, L-curve or validation.
  • Least-squares gradient descent converges to A+b+(I−A+A)x0\mat{A}\pinv\vb{b} + (\mat{I} - \mat{A}\pinv\mat{A})\vb{x}_0: from zero, the minimum-norm solution. Near p=np = n, near-zero design-matrix σmin⁡\sigma_{\min} makes the minimum-norm interpolator explode (double-descent peak), avoided by some ridge.
Key idea
Every linear-system solution is written in the SVD basis as ∑iφi (ui⊤b/σi) vi\sum_i \varphi_i\,(\vb{u}_i\T\vb{b}/\sigma_i)\,\vb{v}_i: the pseudoinverse sets φi=1\varphi_i = 1, regularizers carefully choose φi\varphi_i and gradient descent raises them from 00 to 11 at each step. Solving a system decides component by component how much to trust data.