Skip to content

The pseudo-inverse

Undo a matrix as far as it can be undone, find the shortest least-squares answer, and damp the weak directions with ridge regularisation.

Helps to know first
This topic

First, the picture

A matrix that flattens the plane can’t be undone. Watch the best attempt: it brings back everything that wasn’t crushed.

Undoing a flattening matrix

B = [1 1; 2 2] flattens the plane; its pseudo-inverse brings back what it can.

B = [1 1; 2 2] is about to act on the plane.

best answer B⁺b
–
missed by
–
0.00 / 11.80 s
Describe this picture

One panel and the matrix B2=[1122]\mathbf{B}_2=\begin{bmatrix}1&1\\2&2\end{bmatrix}. After a short rest, over 4 s the grid is flattened onto the line through (1,2)(1,2). After a 1 s pause, over the next 4 s the pseudo-inverse B2+=110[1212]\mathbf{B}_2^+=\tfrac1{10}\begin{bmatrix}1&2\\1&2\end{bmatrix} carries that line back onto the line through (1,1)(1,1), and crushes the perpendicular line through (2,−1)(2,-1) to the origin. Dashed lines mark the three lines. One control after the clip: drag a target b\mathbf{b}, or move it with the arrow keys; the answer B2+b\mathbf{B}_2^+\mathbf{b} appears, with the gap between b\mathbf{b} and what that answer actually reaches. The clip ends on b=(1,0)\mathbf{b}=(1,0), whose answer is (0.1,0.1)(0.1,0.1), missing by (0.8,−0.4)(0.8,-0.4).

Undo what can be undone

The matrix in the picture, B2=[1122]\mathbf{B}_2=\begin{bmatrix}1&1\\2&2\end{bmatrix}, sends every point onto the line of (1,2)(1,2). Points that differ along the null direction, (1,−1)(1,-1), land in the same place, so no matrix can tell them apart afterwards. There is no inverse, as The inverse matrix showed for every flattening map.

But some of the information survives. The SVD of The singular value decomposition says exactly what: B2\mathbf{B}_2 takes the direction v1=(1,1)/2\mathbf{v}_1=(1,1)/\sqrt2, stretches it by σ1=10\sigma_1=\sqrt{10}, and lays it along u1=(1,2)/5\mathbf{u}_1=(1,2)/\sqrt5. Everything along the other direction is multiplied by σ2=0\sigma_2=0 and lost. The best undo reverses the part that survived and leaves the lost part at zero.

Build it from the SVD

In A=UΣV⊤\mathbf{A}=\mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top, swap the two turns and replace each nonzero singular value by its reciprocal, leaving the zeros as zeros. That gives the pseudo-inverse, in full the Moore–Penrose pseudo-inverse:

A+=VΣ+U⊤=∑σk>01σk vkuk⊤.\mathbf{A}^+=\mathbf{V}\boldsymbol{\Sigma}^+\mathbf{U}^\top=\sum_{\sigma_k>0}\frac1{\sigma_k}\,\mathbf{v}_k\mathbf{u}_k^\top.

Here Σ+\boldsymbol{\Sigma}^+ holds 1/σk1/\sigma_k where σk>0\sigma_k>0 and 0 elsewhere, transposed to fit. When A\mathbf{A} is invertible nothing is zero, and A+=A−1\mathbf{A}^+=\mathbf{A}^{-1}.

For B2\mathbf{B}_2 there is one piece:

B2+=110 v1u1⊤=110[1212].\mathbf{B}_2^+=\frac{1}{\sqrt{10}}\,\mathbf{v}_1\mathbf{u}_1^\top=\frac1{10}\begin{bmatrix}1&2\\1&2\end{bmatrix}.

What it does and doesn’t undo

Multiply both ways. B2+B2=12[1111]\mathbf{B}_2^+\mathbf{B}_2=\tfrac12\begin{bmatrix}1&1\\1&1\end{bmatrix}, the projection onto the line of (1,1)(1,1) from Projections. And B2B2+=15[1224]\mathbf{B}_2\mathbf{B}_2^+=\tfrac15\begin{bmatrix}1&2\\2&4\end{bmatrix}, the projection onto the line of (1,2)(1,2). Neither is I\mathbf{I}.

Watch out

The pseudo-inverse does not undo A\mathbf{A}. It can’t bring back what A\mathbf{A} crushed. A+A\mathbf{A}^+\mathbf{A} projects onto the row space, keeping the part that survived, and AA+\mathbf{A}\mathbf{A}^+ projects onto the column space. Only for an invertible matrix are both equal to I\mathbf{I}.

The shortest least-squares answer

Ask B2x=b\mathbf{B}_2\mathbf{x}=\mathbf{b} with b=(3,6)\mathbf{b}=(3,6), which lies on the line of outputs. Every x\mathbf{x} with x1+x2=3x_1+x_2=3 solves it: a whole line of answers, as in The complete solution. The pseudo-inverse picks one:

B2+ (3,6)=110 (3+12,  3+12)=(1.5, 1.5).\begin{aligned} \mathbf{B}_2^+\,(3,6)&=\tfrac1{10}\,(3+12,\;3+12)\\ &=(1.5,\,1.5). \end{aligned}

Its length is 2.121, shorter than (3,0)(3,0) or any other answer. It lies in the row space, with no part along the null direction, and adding a null part can only make an answer longer.

Now a target off the line, b=(1,0)\mathbf{b}=(1,0). No x\mathbf{x} reaches it. The best that can be done is to reach the closest output, the foot of (1,0)(1,0) on the line of (1,2)(1,2), which is 15(1,2)=(0.2, 0.4)\tfrac15(1,2)=(0.2,\,0.4), as in Least squares. The pseudo-inverse gives x+=B2+(1,0)=(0.1, 0.1)\mathbf{x}^+=\mathbf{B}_2^+(1,0)=(0.1,\,0.1), and indeed B2x+=(0.2, 0.4)\mathbf{B}_2\mathbf{x}^+=(0.2,\,0.4).

So in every case A+b\mathbf{A}^+\mathbf{b} is the shortest of all the least-squares answers. When the columns of A\mathbf{A} are independent there is only one, and A+=(A⊤A)−1A⊤\mathbf{A}^+=(\mathbf{A}^\top\mathbf{A})^{-1}\mathbf{A}^\top, the formula of the least-squares page.

Ridge: damping the weak directions

Trouble starts when a singular value is not zero but tiny. Say σ=(2, 0.01)\sigma=(2,\ 0.01). The pseudo-inverse multiplies the two directions by 1/σ1/\sigma: 0.5 and 100. Any noise in the weak direction is magnified a hundred times.

Ridge regularisation adds a small number α>0\alpha>0 before inverting:

xα=(A⊤A+αI)−1A⊤b=∑kσkσk2+α (uk⋅b) vk.\begin{aligned} \mathbf{x}_\alpha&=(\mathbf{A}^\top\mathbf{A}+\alpha\mathbf{I})^{-1}\mathbf{A}^\top\mathbf{b}\\ &=\sum_k\frac{\sigma_k}{\sigma_k^2+\alpha}\,(\mathbf{u}_k\cdot\mathbf{b})\,\mathbf{v}_k. \end{aligned}

Where σk\sigma_k is large, σk/(σk2+α)\sigma_k/(\sigma_k^2+\alpha) is close to 1/σk1/\sigma_k. Where σk\sigma_k is small, it stays small instead of exploding.

Ridge damping

How the pseudo-inverse and ridge treat a strong and a weak direction.

Two singular values: a strong direction, σ = 2, and a weak one, σ = 0.01.

0.00 / 6.80 s
Describe this picture

Three rows of bars for two directions, one with singular value 2 and one with 0.01, appearing row by row. The top row shows the singular values themselves. The middle row shows the pseudo-inverse’s factors, 1/σ1/\sigma: 0.5, and 100, a bar that runs off the top of the scale and is marked with an arrow. The bottom row shows the ridge factors with α=0.01\alpha=0.01, σ/(σ2+α)\sigma/(\sigma^2+\alpha): 0.499 and 0.990. There is no control.

Compare the bars. The strong direction is barely touched, 0.5 against 0.499. The weak one drops from 100 to under 1.

In signal processing · equalising a channel

Channels and equalisation, in the signal processing course, undoes a channel that smears a signal. Where the channel is weak, an exact inverse would amplify the noise enormously, so equalisers use a damped inverse, the same idea as ridge. Signal samples count from n=0n=0, while vector entries count from 1.

Worked example

1. Build it. B2=(1,2) (1,1)⊤\mathbf{B}_2=(1,2)\,(1,1)^\top has σ1=10\sigma_1=\sqrt{10}, u1=(1,2)/5\mathbf{u}_1=(1,2)/\sqrt5 and v1=(1,1)/2\mathbf{v}_1=(1,1)/\sqrt2, so B2+=110[1212]\mathbf{B}_2^+=\tfrac1{10}\begin{bmatrix}1&2\\1&2\end{bmatrix}, and B2B2+B2=B2\mathbf{B}_2\mathbf{B}_2^+\mathbf{B}_2=\mathbf{B}_2.

2. Shortest answer. For b=(3,6)\mathbf{b}=(3,6): (1.5,1.5)(1.5,1.5), length 2.121. For b=(1,0)\mathbf{b}=(1,0): (0.1,0.1)(0.1,0.1), which reaches (0.2,0.4)(0.2,0.4).

3. Ridge with α=1\alpha=1. B2⊤B2+I=[6556]\mathbf{B}_2^\top\mathbf{B}_2+\mathbf{I}=\begin{bmatrix}6&5\\5&6\end{bmatrix}, with inverse 111[6−5−56]\tfrac1{11}\begin{bmatrix}6&-5\\-5&6\end{bmatrix}, and B2⊤(1,0)=(1,1)\mathbf{B}_2^\top(1,0)=(1,1). So xα=1=111(1,1)\mathbf{x}_{\alpha=1}=\tfrac1{11}(1,1), which is 1011\tfrac{10}{11} of x+=(0.1,0.1)\mathbf{x}^+=(0.1,0.1): the factor σ2/(σ2+α)=10/11\sigma^2/(\sigma^2+\alpha)=10/11. As α\alpha shrinks to 0, xα\mathbf{x}_\alpha tends to x+\mathbf{x}^+.

4. Full column rank. For the 3×23\times2 matrix B=[100111]\mathbf{B}=\begin{bmatrix}1&0\\0&1\\1&1\end{bmatrix}, B+=13[2−11−121]\mathbf{B}^+=\tfrac13\begin{bmatrix}2&-1&1\\-1&2&1\end{bmatrix}, and B+(1,2,6)=(2,3)\mathbf{B}^+(1,2,6)=(2,3): the least-squares answer of Projections.

Try these before you read the answers.

  • A+\mathbf{A}^+ of an invertible A\mathbf{A}? A−1\mathbf{A}^{-1}.
  • Is B2+B2=I\mathbf{B}_2^+\mathbf{B}_2=\mathbf{I}? No: it projects onto the line of (1,1)(1,1).
  • What does a larger α\alpha do to the answer’s length? It shrinks it, by σ2/(σ2+α)\sigma^2/(\sigma^2+\alpha) in each direction.
  • A\mathbf{A} has singular values 3 and 0. The matching entries of Σ+\boldsymbol{\Sigma}^+? 1/31/3 and 0.

Where you’ll meet this

Least-squares software. Library routines for least squares and the pseudo-inverse work through the SVD, so a fit with redundant or nearly redundant columns still returns a sensible answer, the shortest one.

Redundant sensors. Calibrating a set of sensors that measure overlapping things gives a system with dependent columns; the pseudo-inverse picks one consistent answer.

Rebuilding a signal from its spectrogram. Inverting the STFT finds the signal whose overlapping frames best match a set of edited frames: a least-squares inverse.

Statistics. Ridge regression fits a model with many inputs by the formula above, trading a little bias for much less noise.

Reference card

QuantityFormulaNotes
Pseudo-inverseA+=VΣ+U⊤\mathbf{A}^+=\mathbf{V}\boldsymbol{\Sigma}^+\mathbf{U}^\topinvert the nonzero σk\sigma_k, keep zeros
As piecesA+=∑σk>0σk−1vkuk⊤\mathbf{A}^+=\sum_{\sigma_k>0}\sigma_k^{-1}\mathbf{v}_k\mathbf{u}_k^\top
InvertibleA+=A−1\mathbf{A}^+=\mathbf{A}^{-1}
Independent columnsA+=(A⊤A)−1A⊤\mathbf{A}^+=(\mathbf{A}^\top\mathbf{A})^{-1}\mathbf{A}^\topthe least-squares formula
ProjectionsAA+\mathbf{A}\mathbf{A}^+ onto C(A)C(\mathbf{A}), A+A\mathbf{A}^+\mathbf{A} onto C(A⊤)C(\mathbf{A}^\top)not I\mathbf{I} in general
Shortest answerx+=A+b\mathbf{x}^+=\mathbf{A}^+\mathbf{b}the least-squares answer in the row space
Ridgexα=(A⊤A+αI)−1A⊤b\mathbf{x}_\alpha=(\mathbf{A}^\top\mathbf{A}+\alpha\mathbf{I})^{-1}\mathbf{A}^\top\mathbf{b}factor σ/(σ2+α)\sigma/(\sigma^2+\alpha) per direction

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look