What & How & Why

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
上一修订版两侧同时换到之后的修订记录
math:linear_algebra:matrix_engineers:week3 [2024/01/10 14:31] – [Normal Equation] codingharemath:linear_algebra:matrix_engineers:week3 [2024/01/10 14:51] – [利用 normal equation 计算 best fit line] codinghare
行 488: 行 488:
 \end{align*}  \end{align*} 
 \] \]
-\\  
 记作: 记作:
 >$$ >$$
行 497: 行 496:
 </WRAP> </WRAP>
 ==Projection matrix== ==Projection matrix==
 +当 $col(A)$ 中的向量是线性无关的时候,$A^TA$ 的结果是一个方阵,是可逆的。因此,对 //Normal Equation// 可以做出进一步的变形:
 +\\ 
 +\[
 +\begin{align*}
 +&A^TAx  = A^Tb \\
 +\Rightarrow & = (A^TA)^{-1}A^Tb \\
 +\Rightarrow &Ax = {\color{Red} A(A^TA)^{-1}A^T} b = b_{proj_{Col(A)}}
 +\end{align*}
 +\]
 +标红的部分被称为 //Projection matrix//。该矩阵将 $b$ 投影到 $Col(A)$ 上。
 +==利用 normal equation 计算 best fit line==
 +//假设有数据点:$(1,1), (2,3),(3,2)$,求过这几点的 best fit line。//\\ \\ 
 +首先,根据数据点,以 $y = \beta_0 + \beta_1x$ 为模板,建立 linear system。通过 linear system 确定 $A$:
 +
 +\[
 +
 +\begin{pmatrix}
 +  1&1 \\
 +  1& 2\\
 +  1&3
 +\end{pmatrix}
 +\begin{pmatrix}
 +\beta_0\\
 +\beta_1
 +
 +\end{pmatrix}
 +=
 +\begin{pmatrix}
 + 1\\
 + 3\\
 +2
 +\end{pmatrix}
 +\]
 +将 $A$ 带入 normal equation:
 +\[
 +\begin{pmatrix*}
 +  1&  1& 1\\
 +  1&  2&3
 +\end{pmatrix*}
 +\begin{pmatrix*}
 +  1&1 \\
 +  1& 2\\
 +  1&3
 +\end{pmatrix*}
 +\begin{pmatrix*}
 +\beta_0\\
 +\beta_1
 +
 +\end{pmatrix*}
 +=
 +\begin{pmatrix*}
 +  1&  1& 1\\
 +  1&  2&3
 +\end{pmatrix*}
 +\begin{pmatrix*}
 + 1\\
 + 3\\
 +2
 +\end{pmatrix*}
 +\]
 +\\ 
 +计算后得到关于 $\beta_0$ 和 $\beta_1$ 的 linear system。此时的未知数与等式数量相同,因此可以求解:
 +\\ 
 +\[
 +\begin{pmatrix*}
 + 3 &6 \\
 + 6 &14
 +\end{pmatrix*}
 +\begin{pmatrix*}
 +\beta_0\\
 +\beta_1
 +
 +\end{pmatrix*}
 +=
 +\begin{pmatrix*}
 + 6\\
 +13
 +\end{pmatrix*}
 +
 +\]
 +\\ 解得 $\beta_0 = 1$,$\beta_1 = 1/2$,因此得到的直线方程为 $y = 1 + 1/2 * x$