1、特征值分解（EVD）

实对称矩阵

$A = Q\Sigma Q^T= Q\left[ \begin{matrix} \lambda_1 & \cdots & \cdots & \cdots\\ \cdots & \lambda_2 & \cdots & \cdots\\ \cdots & \cdots & \ddots & \cdots\\ \cdots & \cdots & \cdots & \lambda_m\\ \end{matrix} \right]Q^T \tag{1-1}$

2、奇异值分解（SVD）

2.1 奇异值分解定义

$A = U\Sigma V^T \tag{2-1}$

$\Sigma = \left[ \begin{matrix} \sigma_1 & 0 & 0 & 0 & 0\\ 0 & \sigma_2 & 0 & 0 & 0\\ 0 & 0 & \ddots & 0 & 0\\ 0 & 0 & 0 & \ddots & 0\\ \end{matrix} \right]_{m\times n}$

2.2 奇异值求解

$AA^T=U\Sigma V^TV\Sigma^TU^T=U\Sigma \Sigma^TU^T \tag{2-2}$

$A^TA=V\Sigma^TU^TU\Sigma V^T=V\Sigma^T\Sigma V^T \tag{2-3}$

$\Sigma\Sigma^T = \left[ \begin{matrix} \sigma_1^2 & 0 & 0 & 0\\ 0 & \sigma_2^2 & 0 & 0\\ 0 & 0 & \ddots & 0 \\ 0 & 0 & 0 & \ddots \\ \end{matrix} \right]_{m\times m}\quad \Sigma^T\Sigma = \left[ \begin{matrix} \sigma_1^2 & 0 & 0 & 0\\ 0 & \sigma_2^2 & 0 & 0\\ 0 & 0 & \ddots & 0\\ 0 & 0 & 0 & \ddots\\ \end{matrix} \right]_{n\times n}$

3、奇异值分解应用

3.1 纯数学例子

$A = \left[ \begin{matrix} ​ 1 & 5 & 7 & 6 & 1 \cr ​ 2 & 1 & {10} & 4 & 4 \cr ​ 3 & 6 & 7 & 5 & 2 \cr \end{matrix} \right]$

$AA^T = \left[ \begin{matrix} ​ 112 & 105 & 114 \cr ​ 105 & 137 & 110 \cr ​ 114 & 110 & 123 \cr \end{matrix} \right] \quad A^TA = \left[ \begin{matrix} ​ 14 & 25 & 48 & 29 & 15 \\ ​ 25 & 62 & 87 & 64 & 21 \\ ​ 48 & 87 & 198 & 117 & 61 \\ ​ 29&64&117&77&32\\ ​ 15&21&61&32&21 \end{matrix} \right]$

U =
[[-0.55572489, -0.72577856,  0.40548161],
[-0.59283199,  0.00401031, -0.80531618],
[-0.58285511,  0.68791671,  0.43249337]]

V =
[[-0.18828164, -0.01844501,  0.73354812,  0.65257661,  0.06782815],
[-0.37055755, -0.76254787,  0.27392013, -0.43299171, -0.17061957],
[-0.74981208,  0.4369731 , -0.12258381, -0.05435401, -0.48119142],
[-0.46504304, -0.27450785, -0.48996859,  0.39500307,  0.58837805],
[-0.22080294,  0.38971845,  0.36301365, -0.47715843,  0.62334131]]


3.2 在图像压缩中的应用

SVD（Python）

①读取图片

%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

print(img_eg.shape)


②奇异值分解

img_temp = img_eg.reshape(600, 400 * 3)
U,Sigma,VT = np.linalg.svd(img_temp)


③取前部分奇异值重构图片

# 取前60个奇异值
sval_nums = 60
img_restruct1 = (U[:,0:sval_nums]).dot(np.diag(Sigma[0:sval_nums])).dot(VT[0:sval_nums,:])
img_restruct1 = img_restruct1.reshape(600,400,3)

# 取前120个奇异值
sval_nums = 120
img_restruct2 = (U[:,0:sval_nums]).dot(np.diag(Sigma[0:sval_nums])).dot(VT[0:sval_nums,:])
img_restruct2 = img_restruct2.reshape(600,400,3)


fig, ax = plt.subplots(1,3,figsize = (24,32))

ax[0].imshow(img_eg)
ax[0].set(title = "src")
ax[1].imshow(img_restruct1.astype(np.uint8))
ax[1].set(title = "nums of sigma = 60")
ax[2].imshow(img_restruct2.astype(np.uint8))
ax[2].set(title = "nums of sigma = 120")


总结

posted @ 2018-11-28 18:30  EndlessCoding  阅读(180519)  评论(27编辑  收藏  举报