最小平方法 2 給定一個矩陣 $A$ 以及一個向量 $b$, 我們想要找到一個向量 $x$ 使得 $\|Ax - b\|^2+\|x\|^2$ 最小.
$$ A\in M_{m\times n}, \quad b \in M_{m\times 1}, \quad x\in M_{n\times 1}. $$
1. Motivation 1.1 Non-uniqueness 最小平方法 $\|Ax-b\|^2$ 問題有時候解並不唯一, 常見的例子例如深度學習裡的神經網路, 他的參數數量通常都遠比資料點數量多非常多. 若我們把 $x$ 看成所有要找的參數的集合, 因此 $n$ 就是參數個數. 然後 $b$ 就是 target 資料集, 所以 $m$ 就是資料個數. 所以常常會有 $m \ll n$ 的情形. 這樣的話 $A$ 的 null space 不為零, 最小平方法的解空間變成了一個 affine subspace, 有無窮多組解.
最小平方法 1 給定一個矩陣 $A$ 以及一個向量 $b$, 我們想要找到一個向量 $x$ 使得 $\|Ax - b\|^2$ 最小.
$$ A\in M_{m\times n}, \quad b \in M_{m\times 1}, \quad x\in M_{m\times 1}. $$
首先我們定義 $\hat{x}$ 為找到的那個解, 也就是說, 我們要解以下這個問題
方陣 A 的行列式等於其特徵值相乘 Determinant of A equals to the product of its eigenvalues
給定一個 $n\times n$ 的方陣 $A$, 我們定義一個變數為 $\lambda$ 的函數 $P(\lambda)$ 如下: $$ \tag{1} P(\lambda) = det(\lambda I-A). $$ 根據行列式的算法我們馬上知道 $P$ 其實就是個 $\lambda$ 的 $n$ 次多項式, 可以寫成 $$ \tag{2} P(\lambda) = \lambda^n + c_{n-1}\lambda^{n-1}\cdots + c_1\lambda + c_0. $$ 因此這個多項式必有 $n$ 個根 $\lambda_1, \cdots, \lambda_n$ (有可能是實根, 虛根, 或重根, 不過必有 $n$ 個), 所以我們可以將 $P$ 改寫為 $$ \tag{3} P(\lambda) = (\lambda - \lambda_1)\cdots (\lambda - \lambda_n). $$
Power 迭代法目錄:
基本概念 Power iteration; inverse power method; shifted inver power method
找第二大的 eigenvalue deflation
Rayleigh Quotient 迭代及其收斂性 Power method with Rayleigh Quotient
假設 $A$ 是一個對稱矩陣 演算法: Power method with Rayleigh Quotient Iterate until convergence: $$ \tag{1} \begin{align} \hat{x}^{(k+1)} &= Ax^{(k)}\\ \lambda^{(k+1)} &= x^{(k)T}\hat{x}^{(k+1)}\\ x^{(k+1)} &= \hat{x}^{(k+1)}/|\hat{x}^{(k+1)}|_2 \end{align} $$
收斂性證明 由於 $A$ 是個對稱矩陣, 因此存在一組 orthonormal 的 eigenvectors $\{v_1, \cdots, v_n\}$, 使得 $v_i^Tv_j=0$ if $i\ne j$, and $v_i^Tv_i=0$.
Power 迭代法目錄:
基本概念 Power iteration; inverse power method; shifted inver power method
找第二大的 eigenvalue deflation
Rayleigh Quotient 迭代及其收斂性 Power method with Rayleigh Quotient
Deflation 對一方陣 $A$, 假設我們以 power iteration 找到了一組 eigenvalue/eigenvector, $\lambda$ and $v$, 使得 $Av = \lambda v$. 那要怎麼找下一組呢?
1. Matrix tranformation 假設能找到一個向量 $x$ 使 $x^T v = 1$, 則我們定義 $$ \tag{1} B = A - \lambda v x^T, $$ 並且以 $B$ 來找 eigenvalue/eigenvector. 那 $A$ 與 $B$ 之間有什麼關係呢?
共軛梯度法 (CG method, conjugate gradient method) 目錄:
CG method - Direct mehtod 直接法
CG method - iterate mehtod 迭代法
For solving $Ax=b$, where $A$ is a square symmetric positive definite matrix.
Assumptions: $A\in M_{n\times n}$ is a symmetric positive definite matrix.
Definition: A-orthogonal (A-conjugate) 假設有兩個向量 $u_1$ 跟 $u_2$ 皆非 $0$ 且 $u_1 \neq u_2$,若這兩個向量滿足 $$ \langle{u_1},A{u_2}\rangle = {u_1}^TA{u_2} = 0, $$ 則稱之為 A-orthogonal (或 A-conjugate). Note : We can define $$ \langle{u_1}, {u_2}\rangle_A = \langle{u_1},A{u_2}\rangle= \langle A{u_1},{u_2}\rangle, $$ then $\langle \cdot\rangle_A$ is an inner product.
Power 迭代法目錄:
基本概念 Power iteration; inverse power method; shifted inver power method
找第二大的 eigenvalue deflation
Rayleigh Quotient 迭代及其收斂性 Power method with Rayleigh Quotient
基本 Power method 求一個方陣最大(in magnitude) 的 eigenvalue.
給定 $A$ 為一個 $n\times n$ 方陣. 我們做以下兩個假設
它的 eigenvalues 滿足 $$ |\lambda_1| > |\lambda_2| \ge |\lambda_3| \cdots |\lambda_n|. $$ 相對應的 eigenvectors, $\{v_1, , v_2, , \cdots, v_n\}$, 會構成 $R^n$ 的一組基底. 則若我們任意取一個 $n\times 1$ 向量 $u$, 它能被寫成 (根據假設 2) $$ u =\sum^{n}_{i=1} c_iv_i. $$
共軛梯度法 (CG method, conjugate gradient method) 目錄:
CG method - Direct mehtod 直接法
CG method - iterate mehtod 迭代法
For solving $Ax=b$, where $A$ is a square symmetric positive definite matrix.
Assumptions: $A\in M_{n\times n}$ is a symmetric positive definite matrix.
Definition: A-orthogonal (A-conjugate) 假設有兩個向量 $u_1$ 跟 $u_2$ 皆非 $0$ 且 $u_1 \neq u_2$,若這兩個向量滿足 $$ \langle{u_1},A{u_2}\rangle = {u_1}^TA{u_2} = 0, $$ 則稱之為 A-orthogonal (或 A-conjugate). A-orthonormal 假設有兩個向量 $u_1$ 跟 $u_2$ 為 A-orthogonal, 並且 $\langle{u_i}, {u_i}\rangle_A = 1$ for $1\le i\le 2$, 則稱之為 A-orthonormal. Recall : ${u_1}$ and ${u_2}$ are orthogonal if ${u_1}^T{u_2} = 0$.
擴散映射, Diffusion maps (以下簡稱 DM), 是個資料分析, 流型學習或是資料降維的工具.
這裡我們要介紹以 julia 來做 diffusion maps 降維.
Algorithm - diffusion maps embeding 先簡單介紹一下作法.
假設我們有 $n$ 筆 $d$ 維的資料, $$ \{x_1, x_2, \cdots, x_n\} \in R^d. $$
延伸閱讀: Julia 學習筆記 - 簡介, 畫圖, 計時
底下的幾個例子我們將學習怎麼使用繪圖指令.
畫圖的時候我們會用到 Plots 這個 package,因此在第一行我們需要加上:
using Plots 以下我們舉幾個簡單的範例來看看如何操作.