標籤:class http 類 表 line c
這節主要是回顧了下線性代數的一些簡單知識。
矩陣與向量矩陣
由$m\times n$個數$a _{ij}(i=1,2,...,m;j=1,2,...,n)$排成的$m$行$n$列的數表,稱為$m$行$n$列的矩陣,簡稱$m\times n$矩陣,記作:
$$\matrix{A}=\begin{bmatrix}a _{11} & a _{12} & \cdots & a _{1n} \cra _{21} & a _{22} & \cdots & a _{2n} \cr\vdots & \vdots & & \vdots \cra _{m1} & a _{m2} & \cdots & a _{mn} \cr\end{bmatrix}$$
簡記為:$\matrix{A}=\matrix{A} _{m \times n}=(a _{ij}) _{m \times n}$
$\matrix{A} _{ij}=$"$i,j$ entry" in the $i ^{th}$ row,$j ^{th}$ column.
向量
所謂$n$維向量,就是$n \times 1$的矩陣:
$$\matrix{x}=\begin{bmatrix}x _1 \crx _2 \cr\vdots \crx _n \cr\end{bmatrix}$$
向量兩種起始方式:
$$\matrix{y}=\begin{bmatrix}y _1 \cry _2 \cr\vdots \cry _n \cr\end{bmatrix}\matrix{y}=\begin{bmatrix}y _0 \cry _1 \cr\vdots \cry _{n-1} \cr\end{bmatrix}$$
搞數學的可能更喜歡第一類表述,程式員可能更喜歡第二類表述。
矩陣基本運算加減
$$\matrix{A \pm B}=\begin{bmatrix}a _{11} \pm b _{11} & a _{12} \pm b _{12} & \cdots & a _{1n} \pm b _{1n} \cra _{21} \pm b _{21} & a _{22} \pm b _{22} & \cdots & a _{2n} \pm b _{2n} \cr\vdots & \vdots & & \vdots \cra _{m1} \pm b _{m1} & a _{m2} \pm b _{m2} & \cdots & a _{mn} \pm b _{mn} \cr\end{bmatrix}$$
數與矩陣相乘
$$\lambda \times \matrix{A}=\matrix{A} \times \lambda=\begin{bmatrix}\lambda \times a _{11} & \lambda \times a _{12} & \cdots & \lambda \times a _{1n} \cr\lambda \times a _{21} & \lambda \times a _{22} & \cdots & \lambda \times a _{2n} \cr\vdots & \vdots & & \vdots \cr\lambda \times a _{m1} & \lambda \times a _{m2} & \cdots & \lambda \times a _{mn} \cr\end{bmatrix}$$
除法的話,無非就是乘以$\frac{1}{\lambda}$,都是一樣的。
矩陣向量乘法
$$\begin{bmatrix}a _{11} & a _{12} & \cdots & a _{1n} \cra _{21} & a _{22} & \cdots & a _{2n} \cr\vdots & \vdots & & \vdots \cra _{m1} & a _{m2} & \cdots & a _{mn} \cr\end{bmatrix}\times\begin{bmatrix}x _1 \crx _2 \cr\vdots \crx _n \cr\end{bmatrix} =\begin{bmatrix}a _{11} \times x _1 + a _{12} \times x _2 + \cdots + a _{1n} \times x _n \cra _{21} \times x _1 + a _{22} \times x _2 + \cdots + a _{2n} \times x _n \cr\vdots \cra _{m1} \times x _1 + a _{m2} \times x _2 + \cdots + a _{mn} \times x _n \cr\end{bmatrix}$$
簡記為:$\matrix{A} \times \matrix{x} = \matrix{y}$
其實仔細看,就是方程組的另一種表達方式罷了:
$$\begin{cases}a _{11} \times x _1 + a _{12} \times x _2 + \cdots + a _{1n} \times x _n = y _1 \cra _{21} \times x _1 + a _{22} \times x _2 + \cdots + a _{2n} \times x _n = y _2 \cr\vdots \cra _{m1} \times x _1 + a _{m2} \times x _2 + \cdots + a _{mn} \times x _n = y _m \cr\end{cases}$$
矩陣相乘
$\matrix{A} \times \matrix{B}$
$\matrix{B}$其實可以看作是:$$\begin{bmatrix} \begin{bmatrix} x _{11} \cr x _{21} \cr \vdots \cr x _{n1} \cr \end{bmatrix} & \begin{bmatrix} x _{12} \cr x _{22} \cr \vdots \cr x _{n2} \cr \end{bmatrix} & \cdots & \begin{bmatrix} x _{1k} \cr x _{2k} \cr \vdots \cr x _{nk} \cr \end{bmatrix}\end{bmatrix} = \begin{bmatrix} \matrix{x _1} & \matrix{x _2} & \cdots & \matrix{x _k}\end{bmatrix}$$
$$\matrix{A} \times \matrix{B} =\begin{bmatrix} A \times \matrix{x _1} & A \times \matrix{x _2} & \cdots & A \times \matrix{x _k}\end{bmatrix}$$
$\matrix{A _{m \times n}} \times \matrix{B _{n \times k}} = \matrix{C _{m \times k}}$
主要關注點是下標,不匹配的話不能相乘。
矩陣乘法運算規律
$(\matrix{A} \times \matrix{B}) \times \matrix{C} = \matrix{A} \times (\matrix{B} \times \matrix{C})$
$\matrix{A} \times (\matrix{B} + \matrix{C}) = \matrix{A} \times \matrix{B} + \matrix{A} \times \matrix{C}$
$(\matrix{B} + \matrix{C}) \times \matrix{A} = \matrix{B} \times \matrix{A} + \matrix{C} \times \matrix{A}$
一般情況下,乘法不滿足交換律:
$\matrix{A} \times \matrix{B} \not = \matrix{B} \times \matrix{A}$
特殊矩陣
$$\matrix{I}=\matrix{I _{n \times n}}=\begin{bmatrix}1 & 0 & \cdots & 0 & 0 \cr0 & 1 & \cdots & 0 & 0 \cr\vdots & \vdots & & \vdots & \vdots \cr0 & 0 & \cdots & 1 & 0 \cr0 & 0 & \cdots & 0 & 1 \cr\end{bmatrix}$$
對任何矩陣$\matrix{A}$:
$\matrix{A} \times \matrix{I}=\matrix{I} \times \matrix{A}=\matrix{A}$
逆矩陣、倒置矩陣逆矩陣
$\matrix{A} \times \matrix{A ^{-1}}=\matrix{A ^{-1}} \times \matrix{A}=\matrix{I}$
倒置矩陣
$\matrix{B} = \matrix{A ^T}$
$\matrix{B _{ij}} = \matrix{A _{ji}}$
參考資訊
本篇主要參考了以下資料:
- Andrew Ng,Machine Learning