线性代数之——最小二乘

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」!

全部评论

相关推荐

04-02 10:09
门头沟学院 Java
用微笑面对困难:这里面问题还是很多的,我也不清楚为啥大家会感觉没啥问题。首先就是全栈开发实习9个月的内容都没有java实习生的内容多,1整个技术栈没看出太核心和难点的内容,感觉好像被拉过去打杂了,而且全栈基本上很容易被毙。里面能问的bug是在太多了比如L:继承 BaseMapper 可直接使用内置方法’。请问你的 BaseMapper 是如何扫描实体类注解如果瞬时产生 100 个上传任务,MySQL 的索引设计是否会有瓶颈?你做过分库分表或者索引优化吗?全栈的内容可以针对动态难点去搞,技能特长写在下面吧,你写了这么多技能,项目和实习体现了多少?你可以在项目里多做文章然后把这个放下去,从大致来看实习不算太水,有含金量你也要写上内容针对哨兵里面的节点变化能问出一万个问题,这个很容易就爆了。
提前批简历挂麻了怎么办
点赞 评论 收藏
分享
03-24 17:57
门头沟学院 Java
yakuso:你这头像哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务