1. 最小二乘

A x = b Ax=b Ax=b 经常会没有解,当方程个数大于未知数个数,也即 m > n m>n m>n 时,列空间并不是 R m R^m Rm 空间的全部,因此 b b b 可能不在列空间中,这时候方程组就无解,但我们不应该就此而停止。

也就是误差 e = b A x e = b-Ax e=bAx 并不总是能得到 0,这时候,如果误差 e e e 的长度尽可能的小,那我们就得到了最小二乘解 <mover accent="true"> x ^ </mover> \hat x x^

A x = b Ax=b Ax=b 无解的时候,我们乘以 A T A^T AT 来求解 A T A x = A T b A^TAx=A^Tb ATAx=ATb

假如我们要找到一条直线,让它距离 (0, 6) ,(1, 0),(2, 0) 这三点最近。没有直线 b = C + D t b = C+Dt b=C+Dt 同时穿过这三点,我们要找的两个常数 C C C D D D

<mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> C + </mstyle> <mstyle displaystyle="true" scriptlevel="0"> D </mstyle> <mstyle displaystyle="true" scriptlevel="0"> 0 = 6 </mstyle> <mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> C + </mstyle> <mstyle displaystyle="true" scriptlevel="0"> D </mstyle> <mstyle displaystyle="true" scriptlevel="0"> 1 = 0 </mstyle> <mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> C + </mstyle> <mstyle displaystyle="true" scriptlevel="0"> D </mstyle> <mstyle displaystyle="true" scriptlevel="0"> 2 = 0 </mstyle> \begin{alignedat}{3} &amp;C\quad+ \quad&amp;D&amp;\cdot 0 \quad=\quad 6 \\ &amp;C\quad + \quad&amp;D&amp;\cdot 1 \quad=\quad 0 \\ &amp;C\quad + \quad&amp;D&amp;\cdot 2 \quad=\quad 0 \end{alignedat} C+C+C+DDD0=61=02=0

A = [ <mstyle displaystyle="false" scriptlevel="0"> 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 0 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 2 </mstyle> ] x = [ <mstyle displaystyle="false" scriptlevel="0"> C </mstyle> <mstyle displaystyle="false" scriptlevel="0"> D </mstyle> ] b = [ <mstyle displaystyle="false" scriptlevel="0"> 6 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 0 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 0 </mstyle> ] A = \begin{bmatrix}1&amp;0\\1&amp;1\\ 1&amp;2 \end{bmatrix} \quad x = \begin{bmatrix}C\\D \end{bmatrix} \quad b = \begin{bmatrix}6\\0\\0 \end{bmatrix} A=111012x=[CD]b=600

由于 b = ( 6 , 0 , 0 ) b = (6, 0, 0) b=(6,0,0) 不是 A A A 的列的一个线性组合,因此方程组无解。

A T A x = A T b [ <mstyle displaystyle="false" scriptlevel="0"> 3 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 3 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 3 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 5 </mstyle> ] [ <mstyle displaystyle="false" scriptlevel="0"> C </mstyle> <mstyle displaystyle="false" scriptlevel="0"> D </mstyle> ] [ <mstyle displaystyle="false" scriptlevel="0"> 6 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> 0 </mstyle> ] A^TAx=A^Tb \to \begin{bmatrix}3&amp;3\\3&amp;5\end{bmatrix} \begin{bmatrix}C\\D \end{bmatrix}\begin{bmatrix}6\\0 \end{bmatrix} ATAx=ATb[3335][CD][60]

<mstyle displaystyle="true" scriptlevel="0"> C = 5 </mstyle> <mstyle displaystyle="true" scriptlevel="0"> D = 3 </mstyle> \begin{alignedat}{2} C = 5 \\ D =-3 \end{alignedat} C=5D=3

因此,距离这三点最近的一条直线为 b = 5 3 t b = 5-3t b=53t

2. 最小化误差

  • 几何理解

任何 A x Ax Ax 都是 A A A 的列的一个线性组合,它们都位于以 A A A 的列为基的一个平面中。因此,我们要找的就是平面中的一个距离 b b b 最近的向量,而这个向量就是 b b b 在这个平面中的投影 p p p

  • 代数理解

A x = b = p + e Ax=b=p+e Ax=b=p+e 是不可解的,但 A <mover accent="true"> x ^ </mover> = p A\hat x = p Ax^=p 是可解的。我们需要最小化下面这个误差

A x b 2 = A x p 2 + e 2 ||Ax-b||^2 = ||Ax-p||^2 + ||e||^2 Axb2=Axp2+e2

当取 x = <mover accent="true"> x ^ </mover> x = \hat x x=x^,$ ||Ax-p||^2 = 0$,因此最小误差为 e 2 |e||^2 e2

  • 微积分理解

误差函数可以表示为

两个未知数有两个导数,当导数分别为零时,我们就得到了误差函数的最小值。

整理后我们得到

可以看到,这和 A T A x = A T b A^TAx=A^Tb ATAx=ATb 得到的结果是一样的。也就是说当 A T A x = A T b A^TAx=A^Tb ATAx=ATb 的时候 A x b 2 ||Ax-b||^2 Axb2 的偏导数为零。

在四个基本子空间中,这次我们将 b b b 分解为 b = p + e b=p+e b=p+e,这时候 A T A x = A T b A^TAx=A^Tb ATAx=ATb 的零空间解只有零向量,因此最优解只有一个 A <mover accent="true"> x ^ </mover> = p A\hat x=p Ax^=p

获取更多精彩,请关注「seniusen」!