SVD的一些理解

来源:互联网 发布:boox和kindle 知乎 编辑:程序博客网 时间:2024/05/16 11:13

PCA一章结束后,书中介绍了SVD,中文名为奇异值分解,全称singular value decomposition,是一种针对矩阵分解的方法。

按照我个人的理解,SVD可以消除多余的信息,保留最主要的信息。

“we can see it as a method for transforming correlated variables into a set of uncorrelated ones that better expose the various relationships among the original data items. At the same time, SVD is a method for identifying and ordering the dimensions along which data points exhibit the most variation. This ties in to the third way of viewing SVD, which is that once we have identi ed where the most variation is, it's possible to nd the best approximation of the original data points using fewer dimensions. Hence, SVD can be seen as a method for data reduction”

优点:简化数据,减少噪音,可能提高其他算法效果

缺点:数据集在经过处理后不容易理解。

SVD的应用场景有很多,这里不具体的去展开,这里以图片中的应用来直观的解释SVD。

https://rorasa.wordpress.com/2012/05/13/l0-norm-l1-norm-l2-norm-l-infinity-norm/


一个m x n 的矩阵Data可以被分解为以上这样的形式,其中,sigma是一个对角矩阵,对角元素都被称为奇异值(singular values),这个有点类似PCA中的特征值,表明特征的重要性。这些奇异值是特征值的平方根,U的列向量则是的特征向量(eigenvectors)而则是的特征向量。

现在那一张图片来稍微直观的做下演示:

图片是从网上找到的,现在是自己PC的桌面。


为了方便处理,将其转化灰度图片,然后对其使用SVD,看看效果。

当sigma取第一个最大的奇异值。

得到的图片是这样的:


基本上看不出有啥。

选取前俩个奇异值:


仍然看不出跟原图片有多大关联,分别选取前5、10个奇异值:



可以明显看到,远距离看5D的,能够看到一个模糊的轮廓,10D的就已经比较清晰了,接着看20D和50D的。



随着奇异值的个数越多,效果越明显。


但是很明显,比如70D以后的,每增加一个奇异值所带来的变化或者影响越来越小,也就是后面的的奇异值对整体图片的贡献远远没有前面贡献大。

PS:python代码片段:

from PIL import Imageimport numpy as npop=Image.open('./a.jpg').convert('L')img=np.array(op)img=img[:-30,:660]s,sigm,v=np.linalg.svd(img)print s.shape,sigm.shape,v.shapeDem=[1,2,5,10,20,50,70,100,200,500,600,660]for D in Dem:    dlg=np.diag(sigm[0:D]) #选取D个奇异值    pic_data=np.dot(s[:,0:D],dlg) #重新构造矩阵    pic_data=np.dot(pic_data,v[0:D,:])    #print type(pic_data[1][1])    im=Image.fromarray(pic_data.astype(np.uint8)) #将数据保存到图片    filename='%s-D.jpg'%(D)    im.save(filename)

以上应该比较直观的了解SVD到底干了什么。

下一篇文章准备写写,SVD在推荐系统中的应用。

0 0
原创粉丝点击