99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2020-06-12 閱讀量: 2317
SVD-矩陣奇異值分解 —— 原理與幾何意義

1.簡介

SVD 全稱:Singular Value Decomposition。SVD 是一種提取信息的強大工具,它提供了一種非常便捷的矩陣分解方式,能夠發(fā)現(xiàn)數(shù)據(jù)中十分有意思的潛在模式。

主要應用領(lǐng)域包括:

  • 隱性語義分析 (Latent Semantic Analysis, LSA) 或隱性語義索引 (Latent Semantic Indexing, LSI);
  • 推薦系統(tǒng) (Recommender system),可以說是最有價值的應用點;
  • 矩陣形式數(shù)據(jù)(主要是圖像數(shù)據(jù))的壓縮。

2.線性變換

3. SVD 推導

.4 實現(xiàn)代碼

以下是基于 python 的 numpy 庫實現(xiàn)的 SVD 矩陣分解的代碼,用于實現(xiàn)圖像壓縮的功能。

代碼鏈接 : https://github.com/zlxy9892/ml_

# -*- coding: utf-8 -*-

import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
from sklearn import datasets
from skimage import io

def getImgAsMat(index):
ds = datasets.fetch_olivetti_faces()
return np.mat(ds.images[index])

def getImgAsMatFromFile(filename):
img = io.imread(filename, as_grey=True)
return np.mat(img)

def plotImg(imgMat):
plt.imshow(imgMat, cmap=plt.cm.gray)
plt.show()

def recoverBySVD(imgMat, k):
# singular value decomposition
U, s, V = la.svd(imgMat)
# choose top k important singular values (or eigens)
Uk = U[:, 0:k]
Sk = np.diag(s[0:k])
Vk = V[0:k, :]
# recover the image
imgMat_new = Uk * Sk * Vk
return imgMat_new


# -------------------- main --------------------- #
A = getImgAsMatFromFile('D:/pic.jpg')
plotImg(A)
A_new = recoverBySVD(A, 30)
plotImg(A_new)

這里用小黃人的大頭照做個例子看看:

原圖:

設置 k = 10,得到的壓縮圖:

k = 20:

k = 30:

繼續(xù)增加 k 值,將會得到越來越接近原始圖的壓縮圖。

5 參考資料

  1. We Recommend a Singular Value Decomposition (AMS 上一篇非常經(jīng)典的關(guān)于SVD幾何意義的介紹)
  2. 奇異值分解 (SVD) 的幾何意義中文翻譯

40.2133
5
關(guān)注作者
收藏
評論(0)

發(fā)表評論

暫無數(shù)據(jù)
推薦帖子