What & How & Why

差别

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

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
math:linear_algebra:matrix_engineers:week3 [2024/01/10 14:29] – [Normal Equation] codingharemath:linear_algebra:matrix_engineers:week3 [2024/02/02 06:27] (当前版本) – [The Least-squares problem] codinghare
行 459: 行 459:
 \] \]
 很明显,这是一个 linear system。在这个 Linear system 中,$x$, $y$ 都是已知的,而 $\beta_0, \beta_1$ 是未知的。因此可以做下面的变型: 很明显,这是一个 linear system。在这个 Linear system 中,$x$, $y$ 都是已知的,而 $\beta_0, \beta_1$ 是未知的。因此可以做下面的变型:
 +\\ \\ 
 {{ :math:linear_algebra:matrix_engineers:least_problem_axb.svg?200 |}} {{ :math:linear_algebra:matrix_engineers:least_problem_axb.svg?200 |}}
 \\ \\  \\ \\ 
行 488: 行 489:
 \end{align*}  \end{align*} 
 \] \]
-\\  
 记作: 记作:
 >$$ >$$
行 496: 行 496:
 这个公式被称为 //Normal Equation//,是计算 Best fit line 的重要手段。 这个公式被称为 //Normal Equation//,是计算 Best fit line 的重要手段。
 </WRAP> </WRAP>
 +==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$