<转>机器学习笔记之奇异值分解的几何解释与简单应用

看到的一篇比较好的关于SVD几何解释与简单应用的文章,其实是有中文译本的,但是翻译的太烂,还不如直接看英文原文的。课本上学的往往是知其然不知其所以然,希望这篇文能为所有初学svd的童鞋提供些直观的认识吧。

A sigular value decomposition

目录(?)[-]

  1. Introduction
  2. The geometry of linear transformations
  3. The singular value decomposition
  4. How do we find the singular decomposition
  5. Another example
  6. Data compression
  7. Noise reduction
  8. Data analysis
  9. Summary
  10. References

Introduction

The topic of this article, the singular value decomposition, is one that should be a part of the standard mathematics undergraduate curriculum but all too often slips between the cracks. Besides being rather intuitive, these decompositions are incredibly useful. For instance, Netflix, the online movie rental company, is currently offering a $1 million prize for anyone who can improve the accuracy of its movie recommendation system by 10%. Surprisingly, this seemingly modest problem turns out to be quite challenging, and the groups involved are now using rather sophisticated techniques. At the heart of all of them is the singular value decomposition.

A singular value decomposition provides a convenient way for breaking a matrix, which perhaps contains some data we are interested in, into simpler, meaningful pieces. In this article, we will offer a geometric explanation of singular value decompositions and look at some of the applications of them.

The geometry of linear transformations

Let us begin by looking at some simple matrices, namely those with two rows and two columns. Our first example is the diagonal matrix

Geometrically, we may think of a matrix like this as taking a point (x, y) in the plane and transforming it into another point using matrix multiplication:

The effect of this transformation is shown below: the plane is horizontally stretched by a factor of 3, while there is no vertical change.

Now let‘s look at

which produces this effect

It is not so clear how to describe simply the geometric effect of the transformation. However, let‘s rotate our grid through a 45 degree angle and see what happens.

Ah ha. We see now that this new grid is transformed in the same way that the original grid was transformed by the diagonal matrix: the grid is stretched by a factor of 3 in one direction.

This is a very special situation that results from the fact that the matrix M is symmetric; that is, the transpose of M, the matrix obtained by flipping the entries about the diagonal, is equal to M. If we have a symmetric 2  2 matrix, it turns out that we may always rotate the grid in the domain so that the matrix acts by stretching and perhaps reflecting in the two directions. In other words, symmetric matrices behave like diagonal matrices.

Said with more mathematical precision, given a symmetric matrix M, we may find a set of orthogonal vectors vi so that Mvi is a scalar multiple of vi; that is

Mvi = λivi

where λi is a scalar. Geometrically, this means that the vectors vi are simply stretched and/or reflected when multiplied by M. Because of this property, we call the vectors vi eigenvectors of M; the scalars λi are called eigenvalues. An important fact, which is easily verified, is that eigenvectors of a symmetric matrix corresponding to different eigenvalues are orthogonal.

If we use the eigenvectors of a symmetric matrix to align the grid, the matrix stretches and reflects the grid in the same way that it does the eigenvectors.

The geometric description we gave for this linear transformation is a simple one: the grid is simply stretched in one direction. For more general matrices, we will ask if we can find an orthogonal grid that is transformed into another orthogonal grid. Let‘s consider a final example using a matrix that is not symmetric:

This matrix produces the geometric effect known as a shear.

It‘s easy to find one family of eigenvectors along the horizontal axis. However, our figure above shows that these eigenvectors cannot be used to create an orthogonal grid that is transformed into another orthogonal grid. Nonetheless, let‘s see what happens when we rotate the grid first by 30 degrees,

Notice that the angle at the origin formed by the red parallelogram on the right has increased. Let‘s next rotate the grid by 60 degrees.

Hmm. It appears that the grid on the right is now almost orthogonal. In fact, by rotating the grid in the domain by an angle of roughly 58.28 degrees, both grids are now orthogonal.

The singular value decomposition

This is the geometric essence of the singular value decomposition for 2  2 matrices: for any 2  2 matrix, we may find an orthogonal grid that is transformed into another orthogonal grid.

We will express this fact using vectors: with an appropriate choice of orthogonal unit vectors v1 and v2, the vectors Mv1 andMv2 are orthogonal.

We will use u1 and u2 to denote unit vectors in the direction of Mv1 and Mv2. The lengths of Mv1 and Mv2--denoted by σ1 and σ2--describe the amount that the grid is stretched in those particular directions. These numbers are called the singular valuesof M. (In this case, the singular values are the golden ratio and its reciprocal, but that is not so important here.)

We therefore have

Mv1 = σ1u1 
Mv2 = σ2u2

We may now give a simple description for how the matrix M treats a general vector x. Since the vectors v1 and v2 are orthogonal unit vectors, we have

x = (v1xv1 + (v2xv2

This means that

Mx = (v1xMv1 + (v2xMv2 
Mx = (v1x) σ1u1 + (v2x) σ2u2

Remember that the dot product may be computed using the vector transpose

vx = vTx

which leads to

Mx = u1σ1 v1Tx + u2σ2 v2Tx 
M = u1σ1 v1T + u2σ2 v2T

This is usually expressed by writing

M = UΣVT

where U is a matrix whose columns are the vectors u1 and u2, Σ is a diagonal matrix whose entries are σ1 and σ2, and V is a matrix whose columns are v1 and v2. The superscript T on the matrix V denotes the matrix transpose of V.

This shows how to decompose the matrix M into the product of three matrices: V describes an orthonormal basis in the domain, and U describes an orthonormal basis in the co-domain, and Σ describes how much the vectors in V are stretched to give the vectors in U.

How do we find the singular decomposition?

The power of the singular value decomposition lies in the fact that we may find it for any matrix. How do we do it? Let‘s look at our earlier example and add the unit circle in the domain. Its image will be an ellipse whose major and minor axes define the orthogonal grid in the co-domain.

Notice that the major and minor axes are defined by Mv1 and Mv2. These vectors therefore are the longest and shortest vectors among all the images of vectors on the unit circle.

In other words, the function |Mx| on the unit circle has a maximum at v1 and a minimum at v2. This reduces the problem to a rather standard calculus problem in which we wish to optimize a function over the unit circle. It turns out that the critical points of this function occur at the eigenvectors of the matrix MTM. Since this matrix is symmetric, eigenvectors corresponding to different eigenvalues will be orthogonal. This gives the family of vectors vi.

The singular values are then given by σi = |Mvi|, and the vectors ui are obtained as unit vectors in the direction of Mvi. But why are the vectors ui orthogonal?

To explain this, we will assume that σi and σj are distinct singular values. We have

Mvi = σiui 
Mvj = σjuj.

Let‘s begin by looking at the expression MviMvj and assuming, for convenience, that the singular values are non-zero. On one hand, this expression is zero since the vectors vi, which are eigenvectors of the symmetric matrix MTM are orthogonal to one another:

Mvi Mvj = viTMT Mvj = vi MTMvj = λjvi vj = 0.

On the other hand, we have

Mvi Mvj = σiσj ui uj = 0

Therefore, ui and uj are othogonal so we have found an orthogonal set of vectors vi that is transformed into another orthogonal set ui. The singular values describe the amount of stretching in the different directions.

In practice, this is not the procedure used to find the singular value decomposition of a matrix since it is not particularly efficient or well-behaved numerically.

Another example

Let‘s now look at the singular matrix

The geometric effect of this matrix is the following:

In this case, the second singular value is zero so that we may write:

M = u1σ1 v1T.

In other words, if some of the singular values are zero, the corresponding terms do not appear in the decomposition for M. In this way, we see that the rank of M, which is the dimension of the image of the linear transformation, is equal to the number of non-zero singular values.

Data compression

Singular value decompositions can be used to represent data efficiently. Suppose, for instance, that we wish to transmit the following image, which consists of an array of 15  25 black or white pixels.

Since there are only three types of columns in this image, as shown below, it should be possible to represent the data in a more compact form.

  

We will represent the image as a 15  25 matrix in which each entry is either a 0, representing a black pixel, or 1, representing white. As such, there are 375 entries in the matrix.

If we perform a singular value decomposition on M, we find there are only three non-zero singular values.

σ1 = 14.72 
σ2 = 5.22 
σ3 = 3.31

Therefore, the matrix may be represented as

M=u1σ1 v1T + u2σ2 v2T + u3σ3 v3T

This means that we have three vectors vi, each of which has 15 entries, three vectors ui, each of which has 25 entries, and three singular values σi. This implies that we may represent the matrix using only 123 numbers rather than the 375 that appear in the matrix. In this way, the singular value decomposition discovers the redundancy in the matrix and provides a format for eliminating it.

Why are there only three non-zero singular values? Remember that the number of non-zero singular values equals the rank of the matrix. In this case, we see that there are three linearly independent columns in the matrix, which means that the rank will be three.

Noise reduction

The previous example showed how we can exploit a situation where many singular values are zero. Typically speaking, the large singular values point to where the interesting information is. For example, imagine we have used a scanner to enter this image into our computer. However, our scanner introduces some imperfections (usually called "noise") in the image.

We may proceed in the same way: represent the data using a 15  25 matrix and perform a singular value decomposition. We find the following singular values:

σ1 = 14.15 
σ2 = 4.67 
σ3 = 3.00 
σ4 = 0.21 
σ5 = 0.19 
... 
σ15 = 0.05

Clearly, the first three singular values are the most important so we will assume that the others are due to the noise in the image and make the approximation

M  u1σ1 v1T + u2σ2 v2T + u3σ3 v3T

This leads to the following improved image.


Noisy image


Improved image

Data analysis

Noise also arises anytime we collect data: no matter how good the instruments are, measurements will always have some error in them. If we remember the theme that large singular values point to important features in a matrix, it seems natural to use a singular value decomposition to study data once it is collected.

As an example, suppose that we collect some data as shown below:

We may take the data and put it into a matrix:

-1.03 0.74 -0.02 0.51 -1.31 0.99 0.69 -0.12 -0.72 1.11
-2.23 1.61 -0.02 0.88 -2.39 2.02 1.62 -0.35 -1.67 2.46

and perform a singular value decomposition. We find the singular values

σ1 = 6.04 
σ2 = 0.22

With one singular value so much larger than the other, it may be safe to assume that the small value of σ2 is due to noise in the data and that this singular value would ideally be zero. In that case, the matrix would have rank one meaning that all the data lies on the line defined by ui.

This brief example points to the beginnings of a field known as principal component analysis, a set of techniques that uses singular values to detect dependencies and redundancies in data.

In a similar way, singular value decompositions can be used to detect groupings in data, which explains why singular value decompositions are being used in attempts to improve Netflix‘s movie recommendation system. Ratings of movies you have watched allow a program to sort you into a group of others whose ratings are similar to yours. Recommendations may be made by choosing movies that others in your group have rated highly.

Summary

As mentioned at the beginning of this article, the singular value decomposition should be a central part of an undergraduate mathematics major‘s linear algebra curriculum. Besides having a rather simple geometric explanation, the singular value decomposition offers extremely effective techniques for putting linear algebraic ideas into practice. All too often, however, a proper treatment in an undergraduate linear algebra course seems to be missing.

This article has been somewhat impressionistic: I have aimed to provide some intuitive insights into the central idea behind singular value decompositions and then illustrate how this idea can be put to good use. More rigorous accounts may be readily found.

References:

  • Gilbert Strang, Linear Algebra and Its Applications. Brooks Cole.

    Strang‘s book is something of a classic though some may find it to be a little too formal.

  • William H. Press et alNumercial Recipes in C: The Art of Scientific Computing. Cambridge University Press. 

    Authoritative, yet highly readable. Older versions are available online.

  • Dan Kalman, A Singularly Valuable Decomposition: The SVD of a Matrix, The College Mathematics Journal 27 (1996), 2-23. 

    Kalman‘s article, like this one, aims to improve the profile of the singular value decomposition. It also a description of how least-squares computations are facilitated by the decomposition.

  • If You Liked This, You‘re Sure to Love ThatThe New York Times, November 21, 2008. 

    This article describes Netflix‘s prize competition as well as some of the challenges associated with it.

David Austin
Grand Valley State University 
david at merganser.math.gvsu.edu

Those who can access JSTOR can find at least of the papers mentioned above there. For those with access, the American Mathematical Society‘s MathSciNet can be used to get additional bibliographic information and reviews of some these materials. Some of the items above can be accessed via the ACM Portal , which also provides bibliographic services.

时间: 2024-10-10 21:14:56

<转>机器学习笔记之奇异值分解的几何解释与简单应用的相关文章

机器学习笔记

下载链接:斯坦福机器学习笔记 这一系列笔记整理于2013年11月至2014年7月.所有内容均是个人理解,做笔记的原因是为了以后回顾相应方法时能快速记起,理解错误在所难免,不合适的地方敬请指正. 笔记按照斯坦福机器学习公开课的notes整理,其中online学习部分没有整理,reinforcement learning还没接触,有时间补上. 这份笔记主要记录自己学习过程中理解上的难点,所以对于初学者来说可能不容易理解,更详细和全面的说明可以参照JerryLead等的机器学习博文. 水哥@howde

机器学习笔记(1)

今天按照<机器学习实战>学习 k-邻近算法,输入KNN.classify0([0,0],group,labels,3)的时候总是报如下的错误: Traceback (most recent call last): File "<pyshell#75>", line 1, in <module> KNN.classify0([0,0],group,labels,3) File "KNN.py", line 16, in classi

机器学习笔记——K-means

K-means是一种聚类算法,其要求用户设定聚类个数k作为输入参数,因此,在运行此算法前,需要估计需要的簇的个数. 假设有n个点,需要聚到k个簇中.K-means算法首先从包含k个中心点的初始集合开始,即随机初始化簇的中心.随后,算法进行多次迭代处理并调整中心位置,知道达到最大迭代次数或中性收敛于固定点. k-means聚类实例.选择三个随机点用作聚类中心(左上),map阶段(右上)将每个点赋给离其最近的簇.在reduce阶段(左下),取相互关联的点的均值,作为新的簇的中心位置,得到本轮迭代的最

机器学习笔记 贝叶斯学习(上)

机器学习笔记(一) 今天正式开始机器学习的学习了,为了激励自己学习,也为了分享心得,决定把自己的学习的经验发到网上来让大家一起分享. 贝叶斯学习 先说一个在著名的MLPP上看到的例子,来自于Josh Tenenbaum 的博士论文,名字叫做数字游戏. 用我自己的话叙述就是:为了决定谁洗碗,小明和老婆决定玩一个游戏.小明老婆首先确定一种数的性质C,比如说质数或者尾数为3:然后给出一系列此类数在1至100中的实例D= {x1,...,xN} :最后给出任意一个数x请小明来预测x是否在D中.如果小明猜

机器学习笔记——人工神经网络

人工神经网络(Artificial Neural Networks,ANN)提供了一种普遍而实用的方法从样例中学习值为实数.离散值或向量的函数. 人工神经网络由一系列简单的单元相互密集连接构成,其中每一个单元有一定数量的实值输入(可能是其他单元的输出),并产生单一的实数值输出(可能成为其他单元的输入). 适合神经网络学习的问题: 实例是很多"属性-值"对表示的 目标函数的输出可能是离散值.实数值或者由若干实数或离散属性组成的向量 训练数据可能包含错误 可容忍长时间的训练 可能需要快速求

机器学习笔记04:逻辑回归(Logistic regression)、分类(Classification)

之前我们已经大概学习了用线性回归(Linear Regression)来解决一些预测问题,详见: 1.<机器学习笔记01:线性回归(Linear Regression)和梯度下降(Gradient Decent)> 2.<机器学习笔记02:多元线性回归.梯度下降和Normal equation> 3.<机器学习笔记03:Normal equation及其与梯度下降的比较> 说明:本文章所有图片均属于Stanford机器学课程,转载请注明出处 面对一些类似回归问题,我们可

机器学习笔记之基础概念

本文基本按照<统计学习方法>中第一章的顺序来写,目录如下: 1. 监督学习与非监督学习 2. 统计学习三要素 3. 过拟合与正则化(L1.L2) 4. 交叉验证 5. 泛化能力 6. 生成模型与判别模型 7. 机器学习主要问题 8. 提问 正文: 1. 监督学习与非监督学习 从标注数据中学习知识的规律以及训练模型的方法叫做监督学习,但由于标注数据获取成本较高,训练数据的数量往往不够,所以就有了从非标注数据,也就是非监督数据中学习的方法. 由于非监督数据更容易获取,所以非监督学习方法更适合于互联

cs229 斯坦福机器学习笔记(一)

前言 说到机器学习,很多人推荐的学习资料就是斯坦福Andrew Ng的cs229,有相关的视频和讲义.不过好的资料 != 好入门的资料,Andrew Ng在coursera有另外一个机器学习课程,更适合入门.课程有video,review questions和programing exercises,视频虽然没有中文字幕,不过看演示的讲义还是很好理解的(如果当初大学里的课有这么好,我也不至于毕业后成为文盲..).最重要的就是里面的programing exercises,得理解透才完成得来的,毕

机器学习笔记——SVM之一

SVM(Support Vector Machine),中文名为 支持向量机,就像自动机一样,听起来异常神气,最初总是纠结于不是机器怎么能叫"机",后来才知道其实此处的"机"实际上是算法的意思. 支持向量机一般用于分类,基本上,在我的理解范围内,所有的机器学习问题都是分类问题.而据说,SVM是效果最好而成本最低的分类算法. SVM是从线性可分的情况下最优分类面发展而来的,其基本思想可以用下图表示: (最优分类面示意图) 图中空心点和实心点代表两类数据样本,H为分类线