The Least Squares Problem

The Least Squares Problem is one of the most important problem in numerical approximation. The main idea of the least squares problem is to solve the unknown parameters , so that the sum of the squares of the difference between the predicted value and the observed value (i.e. the error, or residual) is minimized. In short, it can be interpreted as solving the equation of Ax=bAx=b. In linear algebra, there are three common ways to solve the least squares problem, and their introduction and comparison are shown as below.

The normal equations

For an overdetermined systems (mnm*n): Ax=bAx=b such as:

(141213)(x1x2)=(332)(111)x1+(423)x2=(332)\left(\begin{array}{ll} 1 & 4 \\ 1 & 2 \\ 1 & 3 \end{array}\right)\left(\begin{array}{l} x_{1} \\ x_{2} \end{array}\right)=\left(\begin{array}{l} 3 \\ 3 \\ 2 \end{array}\right) \Leftrightarrow\left(\begin{array}{l} 1 \\ 1 \\ 1 \end{array}\right) x_{1}+\left(\begin{array}{l} 4 \\ 2 \\ 3 \end{array}\right) x_{2}=\left(\begin{array}{l} 3 \\ 3 \\ 2 \end{array}\right)

We can’t solve the system by a1x1+a2x2=ba_{1}x_{1}+a_{2}x_{2}=b because we can’t reach bb through a linear combination of a1a_1 and a2a_2. This method only works when bC(A)b \in C(A) (It’s very unlikely when m>nm>n).

Therefore, we find the vector pp closest to bb in the same plane of a1a_1 and a2a_2, and let e=bpe=b-p to be as small as possible and orthogonal to a1a_1 and a2a_2 (C(A)C(A)).

Then find a solution x^\hat{x} such that p=a1x^1+a2x^2p=a_{1}\hat{x}_{1}+a_{2}\hat{x}_{2}, and pp is the projection of bb onto C(A)C(A).

p=a1x^1+a2x^2=Ax^e=bp=bAx^\begin{aligned} &p=a_{1} \hat{x}_{1}+a_{2} \hat{x}_{2}=A \hat{x} \\ &e=b-p=b-A \hat{x} \\ \end{aligned}

Orthogonality yield

{a1ea1Te=0a2ea2Te=0ATe=0AT(bAx^)=0\begin{aligned} &\left\{\begin{array}{l} a_{1} \perp e \Leftrightarrow a_{1}^{T} e=0 \\ a_{2} \perp e \Leftrightarrow a_{2}^{T} e=0 \end{array} \Leftrightarrow A^{T} e=0 \Leftrightarrow A^{T}(b-A \hat{x})=0\right. \end{aligned}

The normal equations is ATAx^=ATbA^{T}A\hat{x}=A^{T}b. It’s a least squares question and normally requires ATAA^{T}A to be non-singular. It can prove that rank(A)=rank(ATA)rank(A)=rank(A^{T}A), so AA must have independent columns. The normal equations can be solved with Cholesky decomposition (ATAA^{T}A symm. pos. def.) but ATAA^{T}A is often ill-conditioned.

The normal equations requires less operation than other methods, but it won’t work when AA is singular it also has a high condition number.

QR decomposition

QR decomposition A=QRA=QR is one way to solve least squares problem. The solution is shown as below.

ATAx=ATb(QR)TQRx=(QR)TbRTQTQRx=RTQTbRTRx=RTQTbRx=QTb\begin{gathered} A^{T} A x=A^{T} b \Rightarrow(Q R)^{T} Q R x=(Q R)^{T} b \Rightarrow \\ R^{T} Q^{T} Q R x=R^{T} Q^{T} b \Rightarrow R^{T} R x=R^{T} Q^{T} b \Rightarrow \\ R x=Q^{T} b \end{gathered}

Solving Rx=QTbR x=Q^{T} b (with backward substitution) gives the least squares solution.

The merit of QR decomposition is that it has nothing to do with condition number. But the operation of QR decomposition is expensive and matrix AA has to be singular otherwise there will be no solution for it.

Persudo-inverse

When AA is a full-rank square matrix, there is a solution for Ax=bAx=b that x=A1bx=A^{-1}b. But when AA isn’t a full-rank square matrix, there is no solution for this equation. So we need to find the approximate solution x=argminAxb=A+bx^{\prime}=\arg \min \|A x-b\|=A^{+} b, and A+A^{+} is a pseudo-inverse matrix.

Let the SVD of AA be

A=U(S000)VT,A=U\left(\begin{array}{ll} S & 0 \\ 0 & 0 \end{array}\right) V^{T},

where U,VU, V are both orthogonal matrices, and SS is a diagonal matrix containing the (positive) singular values of AA on its diagonal.
Then the pseudo-inverse of AA is the n×mn \times m matrix defined as

A+=V(S1000)UT.A^{+}=V\left(\begin{array}{cc} S^{-1} & 0 \\ 0 & 0 \end{array}\right) U^{T} .

Note that A+A^{+} has the same dimension as the transpose of AA.

If AA is square, invertible, then its inverse is A+=A1A^{+}=A^{-1}.

If AA is full column rank, meaning rank(A)=nm\operatorname{rank}(A)=n \leq m, that is, AAA^{\top} A is not singular, then A+A^{+} is a left inverse of AA, in the sense that A+A=InA^{+} A=I_{n}. We have the closed-form expression A+=(AA)1AA^{+}=\left(A^{\top} A\right)^{-1} A^{\top}

If AA is full row rank, meaning rank(A)=mn\operatorname{rank}(A)=m \leq n, that is, AAA A^{\top} is not singular, then A+A^{+} is a right inverse of AA, in the sense that AA+=ImA A^{+}=I_{m}. We have the closed-form expression A+=A(AA)1A^{+}=A^{\top}\left(A A^{\top}\right)^{-1}

The solution to the least-squares problem minxAxb2\min _{x}\|A x-b\|_{2} with minimum norm is x=A+bx^{*}=A^{+} b.

Persudo-inverse will work all the time but its operation is also quite expensive due to the singular value decomposition part.


All articles in this blog adopt the CC BY-SA 4.0 agreement except for special statements. Please indicate the source for reprinting!