主成分分析

From Ufldl

Jump to: navigation, search
 
Line 1: Line 1:
-
初译:@交大基层代表 @Emma_lzhang
+
== 引言 ==
-
一审:@Dr金峰
+
主成分分析(PCA)是一种能够极大提升无监督特征学习速度的数据降维算法。更重要的是,理解PCA算法,对实现'''白化'''算法有很大的帮助,很多算法都先用白化算法作预处理步骤。
-
二审:@破破的桥
+
假设你使用图像来训练算法,因为图像中相邻的像素高度相关,输入数据是有一定冗余的。具体来说,假如我们正在训练的16x16灰度值图像,记为一个256维向量 <math>\textstyle x \in \Re^{256}</math> ,其中特征值 <math>\textstyle x_j</math> 对应每个像素的亮度值。由于相邻像素间的相关性,PCA算法可以将输入向量转换为一个维数低很多的近似向量,而且误差非常小。
-
录入:@Emma_lzhang 邮箱:emma.lzhang@gmail.com
 
 +
== 实例和数学背景 ==
-
== Introduction 引言 ==
+
在我们的实例中,使用的输入数据集表示为 <math>\textstyle \{x^{(1)}, x^{(2)}, \ldots, x^{(m)}\}</math> ,维度 <math>\textstyle n=2</math> <math>\textstyle x^{(i)} \in \Re^2</math> 。假设我们想把数据从2维降到1维。(在实际应用中,我们也许需要把数据从256维降到50维;在这里使用低维数据,主要是为了更好地可视化算法的行为)。下图是我们的数据集:
-
 
+
-
 
+
-
【原文】:Principal Components Analysis (PCA) is a dimensionality reduction algorithm
+
-
that can be used to significantly speed up your unsupervised feature learning
+
-
algorithm.  More importantly, understanding PCA will enable us to later
+
-
implement '''whitening''', which is an important pre-processing step for many
+
-
algorithms.
+
-
 
+
-
【初译】:主成分分析是一种能够极大提升非监督学习速度的数据降维算法。更重要的,理解主成分分析算法对于学习implement whitening有很大的帮助,而implement whitening算法是一种很重要的预处理算法。
+
-
 
+
-
【一审】:主成分分析是一种能够极大提升非监督学习速度的数据降维算法。更重要的,理解主成分分析算法将使我们能使用白化方法,白化处理是一种很重要的预处理算法。
+
-
 
+
-
【二审】:主成分分析(PCA)是一种能够极大提升非监督特征学习速度的数据降维算法。更重要的是,理解PCA算法,对实现白化算法有很大的帮助,很多算法都先用白化算法作预处理步骤。
+
-
 
+
-
 
+
-
【原文】:Suppose you are training your algorithm on images.  Then the input will be
+
-
somewhat redundant, because the values of adjacent pixels in an image are
+
-
highly correlated.  Concretely, suppose we are training on 16x16 grayscale
+
-
image patches.  Then <math>\textstyle x \in \Re^{256}</math> are 256 dimensional vectors, with one
+
-
feature <math>\textstyle x_j</math> corresponding to the intensity of each pixel.  Because of the
+
-
correlation between adjacent pixels, PCA will allow us to approximate the input with
+
-
a much lower dimensional one, while incurring very little error.
+
-
 
+
-
【初译】:假如通过图像输入来训练算法。那么输入数据是有一定冗余的,因为图像中相连的像素是强相关的。具体来说,假如我们正在训练16×16的灰度值图像,那么<math>\textstyle x \in \Re^{256}</math>的数据便是256维的向量,特征值<math>\textstyle x_j</math>表示每个像素的强度值。因为相连像素间具有相关性,PCA算法可以在保证产生很小的误差值的情况下近似的把输入数据投影到更低维的空间里。。
+
-
 
+
-
【一审】:假设你使用图像来训练算法。那么输入数据是有一定冗余的,因为图像中相连的像素是强相关的。具体来说,假如我们正在训练16×16的灰度值图像,那么 <math>\textstyle x \in \Re^{256}</math>的数据便是256维的向量,特征值<math>\textstyle x_j</math>表示每个像素的强度值。因为相连像素间具有相关性,PCA算法可以在保证产生很小的误差值的情况下近似的把输入数据投影到更低维的空间里。
+
-
 
+
-
【二审】:假设你使用图像来训练算法,那么输入数据是有一定冗余的,因为图像中相连的像素是强相关的。具体来说,假如我们正在训练的16x16灰度值图像,那么<math>\textstyle x \in \Re^{256}</math>是个256维向量,其中,特征值<math>\textstyle x_j</math>对应每个像素的亮度值。因为相连像素间具有相关性,PCA算法可以将输入向量转换为一个维数低很多的近似向量,并仅产生极小的误差。
+
-
 
+
-
== Example and Mathematical Background 实例和数学背景 ==
+
-
 
+
-
 
+
-
【原文】:For our running example, we will use a dataset
+
-
<math>\textstyle \{x^{(1)}, x^{(2)}, \ldots, x^{(m)}\}</math> with
+
-
<math>\textstyle n=2</math> dimensional inputs, so that
+
-
<math>\textstyle x^{(i)} \in \Re^2</math>.
+
-
Suppose we want to reduce the data
+
-
from 2 dimensions to 1.  (In practice, we might want to reduce data
+
-
from 256 to 50 dimensions, say; but using lower dimensional data in our example
+
-
allows us to visualize the algorithms better.)  Here is our dataset:
+
-
 
+
-
【初译】:在我们的实例中,输入数据集<math>\textstyle \{x^{(1)}, x^{(2)}, \ldots, x^{(m)}\}</math>是<math>\textstyle n=2</math>维的数据,即<math>\textstyle x^{(i)} \in \Re^2</math>。假如想把数据从2维降到1维。(实际上,我们是想把数据从255维降到50维;但是用低维的数据我们可以用图形来更直观的解释算法)。
+
-
 
+
-
【一审】:在我们的实例中,输入数据集<math>\textstyle \{x^{(1)}, x^{(2)}, \ldots, x^{(m)}\}</math>是<math>\textstyle n=2</math>维的数据,即<math>\textstyle x^{(i)} \in \Re^2</math>。假如想把数据从2维降到1维。(实际上,我们是想把数据从255维降到50维;但是用低维的数据我们可以用图形来更直观的解释算法)。
+
-
 
+
-
【二审】:在我们的实例中,使用的输入数据集表示为<math>\textstyle \{x^{(1)}, x^{(2)}, \ldots, x^{(m)}\}</math>,维度<math>\textstyle n=2</math>,即<math>\textstyle x^{(i)} \in \Re^2</math>。假设我们想把数据从2维降到1维。(在实际应用中,我们往往需要把数据从256维降到50维;但在我们的示例中使用低维数据,可更直观的展现算法),下图是我们的数据集:
+
[[File:PCA-rawdata.png|600px]]
[[File:PCA-rawdata.png|600px]]
 +
这些数据已经进行了预处理,使得每个特征 <math>\textstyle x_1</math> 和 <math>\textstyle x_2</math> 具有相同的均值(零)和方差。
-
【原文】:This data has already been pre-processed so that each of the features <math>\textstyle x_1</math> and <math>\textstyle x_2</math>
+
为方便展示,根据 <math>\textstyle x_1</math> 值的大小,我们将每个点分别涂上了三种颜色之一,但该颜色并不用于算法而仅用于图解。
-
have about the same mean (zero) and variance. 
+
-
 
+
-
For the purpose of illustration, we have also colored each of the points one of
+
-
three colors, depending on their <math>\textstyle x_1</math> value; these colors are not used by the
+
-
algorithm, and are for illustration only.
+
-
 
+
-
【初译】:数据已经进行了预处理,所以特征值<math>\textstyle x_1</math>和<math>\textstyle x_2</math>有相近的平均值(零)和方差。
+
-
 
+
-
为了更直观的区分,根据<math>\textstyle x_1</math>值的大小我们把它们分成了三种颜色。颜色的区分对于算法没有任何影响,仅仅是为了直观表示。
+
-
 
+
-
【一审】:数据已经进行了预处理,所以特征值<math>\textstyle x_1</math>和<math>\textstyle x_2</math>有相近的平均值(零)和方差。
+
-
 
+
-
为了更直观的区分,根据<math>\textstyle x_1</math>值的大小我们把它们分成了三种颜色。颜色的区分对于算法没有任何影响,仅仅是为了直观表示。
+
-
 
+
-
【二审】:这些数据已经进行了预处理,所以每个特征值<math>\textstyle x_1</math>和<math>\textstyle x_2</math>有相同的平均值(零)和方差。
+
-
 
+
-
为方便展示,根据<math>\textstyle x_1</math>值的大小,我们将每个点分别涂上了三种颜色的一种。该颜色并不用于算法而仅用于图解。
+
-
 
+
-
 
+
-
【原文】:PCA will find a lower-dimensional subspace onto which to project our data. 
+
-
From visually examining the data, it appears that <math>\textstyle u_1</math> is the principal direction of
+
-
variation of the data, and <math>\textstyle u_2</math> the secondary direction of variation:
+
-
 
+
-
【初译】:PCA算法的目的是为了选取一个数据投影的低维空间。从下图中可以看出,<math>\textstyle u_1</math>是数据变化的主方向,而<math>\textstyle u_2</math>是次方向。
+
-
 
+
-
【一审】:PCA算法将选取一个低维空间来投影数据投影。从下图中可以看出,<math>\textstyle u_1</math>是数据变化的主方向,而<math>\textstyle u_2</math>是次方向。
+
-
 
+
-
【二审】:PCA算法将选取一个低维空间来投影我们的数据。从下图中可以看出,<math>\textstyle u_1</math>是数据变化的主方向,而<math>\textstyle u_2</math>是次方向。
+
 +
PCA算法将寻找一个低维空间来投影我们的数据。从下图中可以看出, <math>\textstyle u_1</math> 是数据变化的主方向,而 <math>\textstyle u_2</math> 是次方向。
[[File:PCA-u1.png | 600px]]
[[File:PCA-u1.png | 600px]]
-
 
+
也就是说,数据在 <math>\textstyle u_1</math> 方向上的变化要比在 <math>\textstyle u_2</math> 方向上大。为更形式化地找出方向 <math>\textstyle u_1</math> 和 <math>\textstyle u_2</math> ,我们首先计算出矩阵 <math>\textstyle \Sigma</math> ,如下所示:
-
【原文】:I.e., the data varies much more in the direction <math>\textstyle u_1</math> than <math>\textstyle u_2</math>.
+
-
To more formally find the directions <math>\textstyle u_1</math> and <math>\textstyle u_2</math>, we first compute the matrix <math>\textstyle \Sigma</math>
+
-
as follows:
+
-
 
+
-
【初译】:也就是说,<math>\textstyle u_1</math>方向上的数据要比<math>\textstyle u_2</math>方向的变化大。为了计算出方向<math>\textstyle u_1</math>和<math>\textstyle u_2</math>,我们首先要通过如下式子计算出矩阵<math>\textstyle \Sigma</math>:
+
-
 
+
-
【一审】:举例说,<math>\textstyle u_1</math>方向上的数据要比<math>\textstyle u_2</math>方向的变化大。为了计算出方向<math>\textstyle u_1</math>和<math>\textstyle u_2</math>,我们首先计算出矩阵<math>\textstyle \Sigma</math>,如下:
+
-
 
+
-
【二审】:也就是说,<math>\textstyle u_1</math>方向上的数据要比<math>\textstyle u_2</math>方向的变化大。为更正式地计算出方向<math>\textstyle u_1</math>和<math>\textstyle u_2</math>,我们首先计算出矩阵<math>\textstyle \Sigma</math>,如下所示:
+
:<math>\begin{align}
:<math>\begin{align}
Line 107: Line 26:
\end{align}</math>
\end{align}</math>
 +
假设 <math>\textstyle x</math> 的均值为零,那么 <math>\textstyle \Sigma</math> 就是x的协方差矩阵。(符号 <math>\textstyle \Sigma</math> ,读"Sigma",是协方差矩阵的标准符号。虽然看起来与求和符号 <math>\sum_{i=1}^n i</math> 比较像,但它们其实是两个不同的概念。)
-
【原文】:If <math>\textstyle x</math> has zero mean, then <math>\textstyle \Sigma</math> is exactly the covariance matrix of <math>\textstyle x</math>.  (The symbol "<math>\textstyle \Sigma</math>", pronounced "Sigma", is the standard notation for denoting the covariance matrix.  Unfortunately it looks just like the summation symbol, as in <math>\sum_{i=1}^n i</math>; but these are two different things.)
+
可以证明,数据变化的主方向 <math>\textstyle u_1</math> 就是协方差矩阵 <math>\textstyle \Sigma</math> 的主特征向量,而 <math>\textstyle u_2</math> 是次特征向量。
-
 
+
-
It can then be shown that <math>\textstyle u_1</math>---the principal direction of variation of the data---is
+
-
the top (principal) eigenvector of <math>\textstyle \Sigma</math>, and <math>\textstyle u_2</math> is
+
-
the second eigenvector.
+
-
 
+
-
【初译】:假设<math>\textstyle x</math>的均值为零,那么<math>\textstyle \Sigma</math>就是<math>\textstyle x</math>的协方差矩阵。(符号<math>\textstyle \Sigma</math>,读"Sigma",是协方差矩阵的表示符。虽然看起来与求和符号<math>\sum_{i=1}^n i</math>比较像,但他们是两个不同的概念。)
+
-
 
+
-
由此可以得出,数据变化的主方向<math>\textstyle u_1</math>是协方差矩阵<math>\textstyle \Sigma</math>的主特征向量,而<math>\textstyle u_2</math>是次特征向量。
+
-
 
+
-
【一审】:假设<math>\textstyle x</math>的均值为零,那么<math>\textstyle \Sigma</math>就是<math>\textstyle x</math>的协方差矩阵。(符号<math>\textstyle \Sigma</math>,读"Sigma",是协方差矩阵的表示符。虽然看起来与求和符号<math>\sum_{i=1}^n i</math>比较像,但他们是两个不同的概念。)
+
-
 
+
-
可以看出,数据变化的主方向<math>\textstyle u_1</math>是协方差矩阵<math>\textstyle \Sigma</math>的主特征向量,而<math>\textstyle u_2</math>是次特征向量。
+
-
 
+
-
【二审】:假设<math>\textstyle x</math>的均值为零,那么<math>\textstyle \Sigma</math>就是<math>\textstyle x</math>的协方差矩阵。(符号<math>\textstyle \Sigma</math>,读"Sigma",是协方差矩阵的标准符号。虽然看起来与求和符号,如<math>\sum_{i=1}^n i</math>,比较像,但它们是两个不同的概念。)
+
-
 
+
-
可以看出,数据变化的主方向<math>\textstyle u_1</math>,是协方差矩阵<math>\textstyle \Sigma</math>的主特征向量,而<math>\textstyle u_2</math>是次特征向量。
+
-
 
+
-
 
+
-
 
+
-
【原文】:Note: If you are interested in seeing a more formal mathematical derivation/justification of this result, see the CS229 (Machine Learning) lecture notes on PCA (link at bottom of this page).  You won't need to do so to follow along this course, however. 
+
-
 
+
-
【初译】:注意:如果你对这个结果更具体的数学推导过程感兴趣,可以参看CS229(机器学习)PCA部分的课件。如果仅仅是想跟上这门课程,可以不必如此。
+
-
 
+
-
【一审】:注意:如果你对这个结果更具体的数学推导过程感兴趣,可以参看CS229(机器学习)PCA部分的课件。如果仅仅是想跟上这门课程,可以不必如此。
+
-
 
+
-
【二审】:注意:如果你对这个结果更具体的数学推导过程感兴趣,可以参看CS229(机器学习)PCA部分的课件(链接在本页底部)。如果仅仅是想跟上这门课程,可以不必如此。
+
-
 
+
-
 
+
-
【原文】:You can use standard numerical linear algebra software to find these eigenvectors (see Implementation Notes).
+
-
Concretely, let us compute the eigenvectors of <math>\textstyle \Sigma</math>, and stack
+
-
the eigenvectors in columns to form the matrix <math>\textstyle U</math>:
+
-
 
+
-
【初译】:特征向量可以通过专业的线性代数运算软件求得。计算出协方差矩阵<math>\textstyle \Sigma</math>的特征向量值后,排成列组成矩阵<math>\textstyle U</math>:
+
-
【一审】:你可以通过标准的线性代数运算软件求得特征向量,在此,就是计算出协方差矩阵<math>\textstyle \Sigma</math>的特征向量值,并将其排成列组成矩阵<math>\textstyle U</math>:
+
注:如果你对如何得到这个结果的具体数学推导过程感兴趣,可以参看CS229(机器学习)PCA部分的课件(链接在本页底部)。但如果仅仅是想跟上本课,可以不必如此。
-
【二审】:你可以通过标准的线性代数运算软件求得特征向量(见实现说明),在此,让我们计算出协方差矩阵<math>\textstyle \Sigma</math>的特征向量值,并按列排放,组成矩阵<math>\textstyle U</math>:
+
你可以通过标准的数值线性代数运算软件求得特征向量(见实现说明).我们先计算出协方差矩阵<math>\textstyle \Sigma</math>的特征向量,按列排放,而组成矩阵<math>\textstyle U</math>:
:<math>\begin{align}
:<math>\begin{align}
Line 156: Line 43:
\end{align}</math>
\end{align}</math>
 +
此处, <math>\textstyle u_1</math> 是主特征向量(对应最大的特征值), <math>\textstyle u_2</math> 是次特征向量。以此类推,另记 <math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math> 为相应的特征值。
-
【原文】:Here, <math>\textstyle u_1</math> is the principal eigenvector (corresponding to the largest eigenvalue),
+
在本例中,向量 <math>\textstyle u_1</math> <math>\textstyle u_2</math> 构成了一个新基,可以用来表示数据。令 <math>\textstyle x \in \Re^2</math> 为训练样本,那么 <math>\textstyle u_1^Tx</math> 就是样本点 <math>\textstyle x</math> 在维度 <math>\textstyle u_1</math> 上的投影的长度(幅值)。同样的, <math>\textstyle u_2^Tx</math> 是 <math>\textstyle x</math> 投影到 <math>\textstyle u_2</math> 维度上的幅值。
-
<math>\textstyle u_2</math> is the second eigenvector, and so on.
+
-
Also, let <math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math> be the corresponding eigenvalues.
+
-
【初译】:矩阵中<math>\textstyle u_1</math>是主特征向量(相应于最大的特征值),<math>\textstyle u_2</math>是次特征向量。以此类推,<math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math>是相应的特征值。
 
-
【一审】:此处,<math>\textstyle u_1</math>是主特征向量(相应于最大的特征值),<math>\textstyle u_2</math>是次特征向量。以此类推,<math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math>是相应的特征值。
+
== 旋转数据 ==
-
【二审】:此处,<math>\textstyle u_1</math>是主特征向量(对应最大的特征值),<math>\textstyle u_2</math>是次特征向量。以此类推,<math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math>是相应的特征值。
+
至此,我们可以把 <math>\textstyle x</math> <math>\textstyle (u_1, u_2)</math> 基表达为:
-
 
+
-
 
+
-
【原文】:The vectors <math>\textstyle u_1</math> and <math>\textstyle u_2</math> in our example form a new basis in which we
+
-
can represent the data.  Concretely, let <math>\textstyle x \in \Re^2</math> be some training example.  Then <math>\textstyle u_1^Tx</math>
+
-
is the length (magnitude) of the projection of <math>\textstyle x</math> onto the vector <math>\textstyle u_1</math>. 
+
-
 
+
-
Similarly, <math>\textstyle u_2^Tx</math> is the magnitude of <math>\textstyle x</math> projected onto the vector <math>\textstyle u_2</math>.
+
-
 
+
-
【初译】:实例中,向量<math>\textstyle u_1</math>和<math>\textstyle u_2</math>形成了一个我们可以表示数据的新数据基。令<math>\textstyle x \in \Re^2</math>是训练样本,那么<math>\textstyle u_1^Tx</math>就是样本点<math>\textstyle x</math>到向量<math>\textstyle u_1</math>上的长度(幅值)。类似的,<math>\textstyle u_2^Tx</math>是<math>\textstyle x</math>到向量<math>\textstyle u_2</math>上的幅值。
+
-
 
+
-
【一审】:实例中,向量<math>\textstyle u_1</math>和<math>\textstyle u_2</math>形成了一个我们可以表示数据的新数据基。令<math>\textstyle x \in \Re^2</math>是训练样本,那么<math>\textstyle u_1^Tx</math>就是样本点<math>\textstyle x</math>到维度<math>\textstyle u_1</math>上的投影长度(幅值)。同样的,<math>\textstyle u_2^Tx</math>是<math>\textstyle x</math>到维度<math>\textstyle u_2</math>上的幅值。
+
-
 
+
-
【二审】:在我们的示例中,向量<math>\textstyle u_1</math>和<math>\textstyle u_2</math>构成了一个表示数据的新的基。令<math>\textstyle x \in \Re^2</math>为训练样本,那么<math>\textstyle u_1^Tx</math>就是样本点<math>\textstyle x</math>在维度<math>\textstyle u_1</math>上的投影长度(幅值)。同样的,<math>\textstyle u_2^Tx</math>是<math>\textstyle x</math>投影到<math>\textstyle u_2</math>维度上的幅值。
+
-
 
+
-
 
+
-
== Rotating the Data 旋转数据 ==
+
-
 
+
-
 
+
-
【原文】:Thus, we can represent <math>\textstyle x</math> in the <math>\textstyle (u_1, u_2)</math>-basis by computing
+
-
:<math>\begin{align}
+
-
x_{\rm rot} = U^Tx = \begin{bmatrix} u_1^Tx \\ u_2^Tx \end{bmatrix}
+
-
\end{align}</math>
+
-
(The subscript "rot" comes from the observation that this corresponds to
+
-
a rotation (and possibly reflection) of the original data.)
+
-
Lets take the entire training set, and compute
+
-
<math>\textstyle x_{\rm rot}^{(i)} = U^Tx^{(i)}</math> for every <math>\textstyle i</math>.  Plotting this transformed data
+
-
<math>\textstyle x_{\rm rot}</math>, we get:
+
-
 
+
-
【初译】:因此,我们可以计算出以<math>\textstyle (u_1, u_2)</math>为基的<math>\textstyle x</math>的映射表示。
+
-
:<math>\begin{align}
+
-
x_{\rm rot} = U^Tx = \begin{bmatrix} u_1^Tx \\ u_2^Tx \end{bmatrix}
+
-
\end{align}</math>
+
-
(下标“rot”来源于单词“rotation”,意指这是原数据经过旋转(也可以说成映射)得到后得到的结果)数据集中的每个数据<math>\textstyle i</math>经过<math>\textstyle x_{\rm rot}^{(i)} = U^Tx^{(i)}</math>计算后,可以画出如下映射数据<math>\textstyle x_{\rm rot}</math>图:
+
-
 
+
-
【一审】:由此,我们可以计算出以<math>\textstyle (u_1, u_2)</math>为基的<math>\textstyle x</math>的映射表示。
+
-
:<math>\begin{align}
+
-
x_{\rm rot} = U^Tx = \begin{bmatrix} u_1^Tx \\ u_2^Tx \end{bmatrix}
+
-
\end{align}</math>
+
-
(下标“rot”来源于单词“rotation”,意指这是原数据经过旋转(也可以说成映射)得到后得到的结果)数据集中的每个数据<math>\textstyle i</math>经过<math>\textstyle x_{\rm rot}^{(i)} = U^Tx^{(i)}</math>计算后,可以画出如下变换映射数据<math>\textstyle x_{\rm rot}</math>图:
+
-
 
+
-
【二审】:因此,我们可以计算出<math>\textstyle x</math><math>\textstyle (u_1, u_2)</math>基上的映射表示。
+
:<math>\begin{align}
:<math>\begin{align}
x_{\rm rot} = U^Tx = \begin{bmatrix} u_1^Tx \\ u_2^Tx \end{bmatrix}  
x_{\rm rot} = U^Tx = \begin{bmatrix} u_1^Tx \\ u_2^Tx \end{bmatrix}  
\end{align}</math>
\end{align}</math>
(下标“rot”来源于单词“rotation”,意指这是原数据经过旋转(也可以说成映射)后得到的结果)
(下标“rot”来源于单词“rotation”,意指这是原数据经过旋转(也可以说成映射)后得到的结果)
-
对数据集<math>\textstyle x_{\rm rot}^{(i)} = U^Tx^{(i)}</math>中的每个<math>\textstyle i</math>取值经过计算后,根据变换后的数据<math>\textstyle x_{\rm rot}</math>作图,可得:
 
 +
对数据集中的每个样本 <math>\textstyle i</math> 分别进行旋转: <math>\textstyle x_{\rm rot}^{(i)} = U^Tx^{(i)}</math> for every <math>\textstyle i</math> ,然后把变换后的数据 <math>\textstyle x_{\rm rot}</math> 显示在坐标图上,可得:
[[File:PCA-rotated.png|600px]]
[[File:PCA-rotated.png|600px]]
 +
这就是把训练数据集旋转到 <math>\textstyle u_1</math>,<math>\textstyle u_2</math> 基后的结果。一般而言,运算 <math>\textstyle U^Tx</math> 表示旋转到基 <math>\textstyle u_1</math>,<math>\textstyle u_2</math>, ...,<math>\textstyle u_n</math> 之上的训练数据。矩阵 <math>\textstyle U</math> 有正交性,即满足  <math>\textstyle U^TU = UU^T = I</math> ,所以若想将旋转后的向量 <math>\textstyle x_{\rm rot}</math> 还原为原始数据 <math>\textstyle x</math> ,将其左乘矩阵<math>\textstyle U</math>即可: <math>\textstyle x=U x_{\rm rot}</math> , 验算一下: <math>\textstyle U x_{\rm rot} =  UU^T x = x</math>.
-
【原文】:This is the training set rotated into the <math>\textstyle u_1</math>,<math>\textstyle u_2</math> basis. In the general
 
-
case, <math>\textstyle U^Tx</math> will be the training set rotated into the basis
 
-
<math>\textstyle u_1</math>,<math>\textstyle u_2</math>, ...,<math>\textstyle u_n</math>.
 
-
One of the properties of <math>\textstyle U</math> is that it is an "orthogonal" matrix, which means
+
== 数据降维 ==
-
that it satisfies <math>\textstyle U^TU = UU^T = I</math>.
+
-
So if you ever need to go from the rotated vectors <math>\textstyle x_{\rm rot}</math> back to the
+
-
original data <math>\textstyle x</math>, you can compute
+
-
:<math>\begin{align}
+
数据的主方向就是旋转数据的第一维 <math>\textstyle x_{{\rm rot},1}</math> 。因此,若想把这数据降到一维,可令:
-
x = U x_{\rm rot}  ,
+
-
\end{align}</math>
+
-
because <math>\textstyle U x_{\rm rot} =  UU^T x = x</math>.
+
-
 
+
-
【初译】:这就是训练数据集旋转到以<math>\textstyle u_1</math>,<math>\textstyle u_2</math>为基后的数据。但是通常情况下,训练数据集合通过<math>\textstyle U^Tx</math>旋转后会得到的是<math>\textstyle n</math>维的<math>\textstyle u_1</math>,<math>\textstyle u_2</math>, ...,<math>\textstyle u_n</math>。由于矩阵<math>\textstyle U</math>具有正交性,也就是说它满足<math>\textstyle U^TU = UU^T = I</math>,所以假若想从<math>\textstyle x_{\rm rot}</math>中还原<math>\textstyle x</math>,可以通过如下计算:
+
-
 
+
-
:<math>\begin{align}
+
-
x = U x_{\rm rot}  ,
+
-
\end{align}</math>
+
-
 
+
-
因为<math>\textstyle U x_{\rm rot} =  UU^T x = x</math>
+
-
 
+
-
【一审】:这就是训练数据集旋转到以<math>\textstyle u_1</math>,<math>\textstyle u_2</math>为基后的数据。但是通常情况下,训练数据集合通过<math>\textstyle U^Tx</math>旋转后会得到的是<math>\textstyle n</math>维的<math>\textstyle u_1</math>,<math>\textstyle u_2</math>, ...,<math>\textstyle u_n</math>。由于矩阵<math>\textstyle U</math>具有正交性,也就是说它满足<math>\textstyle U^TU = UU^T = I</math>,所以假若想从<math>\textstyle x_{\rm rot}</math>中还原<math>\textstyle x</math>,可以通过如下计算:
+
-
 
+
-
:<math>\begin{align}
+
-
x = U x_{\rm rot}  ,
+
-
\end{align}</math>
+
-
 
+
-
因为<math>\textstyle U x_{\rm rot} =  UU^T x = x</math>
+
-
 
+
-
 
+
-
【二审】:这就是训练数据集旋转到<math>\textstyle u_1</math>,<math>\textstyle u_2</math>基上所得数据。在更一般的情况下,训练数据集<math>\textstyle U^Tx</math>旋转到基<math>\textstyle u_1</math>,<math>\textstyle u_2</math>, ...,<math>\textstyle u_n</math>之上。矩阵<math>\textstyle U</math>具备正交性,也就是说它满足<math>\textstyle U^TU = UU^T = I</math>,所以假若想将旋转矩阵<math>\textstyle x_{\rm rot}</math>还原为原始数据<math>\textstyle x</math>,可以通过如下计算:
+
-
 
+
-
:<math>\begin{align}
+
-
x = U x_{\rm rot}  ,
+
-
\end{align}</math>
+
-
 
+
-
因为<math>\textstyle U x_{\rm rot} =  UU^T x = x</math>
+
-
 
+
-
 
+
-
== Reducing the Data Dimension 数据降维 ==
+
-
 
+
-
 
+
-
【原文】:We see that the principal direction of variation of the data is the first
+
-
dimension <math>\textstyle x_{{\rm rot},1}</math> of this rotated data.  Thus, if we want to
+
-
reduce this data to one dimension, we can set
+
-
 
+
-
【初译】:数据变化的主方向相应于旋转数据的第一维<math>\textstyle x_{{\rm rot},1}</math>。因此,如若想把数据降到一维,我们仅需令:
+
-
 
+
-
【一审】:数据变化的主方向相应于旋转数据的第一维<math>\textstyle x_{{\rm rot},1}</math>。因此,如若想把数据降到一维,我们仅需令:
+
-
 
+
-
【二审】:数据变化的主方向是旋转数据的第一维<math>\textstyle x_{{\rm rot},1}</math>。因此,若想把这数据降到一维,需令:
+
:<math>\begin{align}
:<math>\begin{align}
Line 274: Line 71:
\end{align}</math>
\end{align}</math>
 +
更一般的,假如想把数据 <math>\textstyle x \in \Re^n</math> 降到 <math>\textstyle k</math> 维表示
 +
<math>\textstyle \tilde{x} \in \Re^k</math> (令 <math>\textstyle k < n</math> ),只需选取 <math>\textstyle x_{\rm rot}</math> 的前 <math>\textstyle k</math> 个成分,分别对应前 <math>\textstyle k</math> 个数据变化的主方向。
-
【原文】:More generally, if <math>\textstyle x \in \Re^n</math> and we want to reduce it to
+
PCA的另外一种解释是:<math>\textstyle x_{\rm rot}</math> 是一个 <math>\textstyle n</math> 维向量,其中前几个成分可能比较大(例如,上例中大部分样本第一个成分 <math>\textstyle x_{{\rm rot},1}^{(i)} = u_1^Tx^{(i)}</math> 的取值相对较大),而后面成分可能会比较小(例如,上例中大部分样本的 <math>\textstyle x_{{\rm rot},2}^{(i)} = u_2^Tx^{(i)}</math> 较小)。
-
a <math>\textstyle k</math> dimensional representation <math>\textstyle \tilde{x} \in \Re^k</math> (where <math>\textstyle k < n</math>), we would
+
-
take the first <math>\textstyle k</math> components of <math>\textstyle x_{\rm rot}</math>, which correspond to
+
-
the top <math>\textstyle k</math> directions of variation.
+
-
 
+
-
【初译】:一般情况下,假如想把<math>\textstyle x \in \Re^n</math>的数据降到<math>\textstyle k</math>维,即<math>\textstyle \tilde{x} \in \Re^k</math>(<math>\textstyle k < n</math>),需要选取<math>\textstyle x_{\rm rot}</math>的前<math>\textstyle k</math>个成分,其相应于变量的前<math>\textstyle k</math>个主方向。
+
-
 
+
-
【一审】:一般情况下,假如想把<math>\textstyle x \in \Re^n</math>的数据降到<math>\textstyle k</math>维,即<math>\textstyle \tilde{x} \in \Re^k</math>(<math>\textstyle k < n</math>),需要选取<math>\textstyle x_{\rm rot}</math>的前<math>\textstyle k</math>个成分,其相应于变量的前<math>\textstyle k</math>个方向。
+
-
 
+
-
【二审】:更一般的情况下,假如想把数据<math>\textstyle x \in \Re^n</math>降到<math>\textstyle k</math>维表示<math>\textstyle \tilde{x} \in \Re^k</math>(令<math>\textstyle k < n</math>),需要选取<math>\textstyle x_{\rm rot}</math>的前<math>\textstyle k</math>个成分,对应方差的前<math>\textstyle k</math>个方向。
+
-
 
+
-
 
+
-
【原文】:Another way of explaining PCA is that <math>\textstyle x_{\rm rot}</math> is an <math>\textstyle n</math> dimensional
+
-
vector, where the first few components are likely to
+
-
be large (e.g., in our example, we saw that <math>\textstyle x_{{\rm rot},1}^{(i)} = u_1^Tx^{(i)}</math> takes
+
-
reasonably large values for most examples <math>\textstyle i</math>), and
+
-
the later components are likely to be small (e.g., in our example,
+
-
<math>\textstyle x_{{\rm rot},2}^{(i)} = u_2^Tx^{(i)}</math> was more likely to be small). 
+
-
 
+
-
【初译】:PCA的另外一种解释是:<math>\textstyle x_{\rm rot}</math>是一个<math>\textstyle n</math>维的向量,其中前面几维比较大(例如,上例中对于大部分的样本<math>\textstyle i</math>通过<math>\textstyle x_{{\rm rot},1}^{(i)} = u_1^Tx^{(i)}</math>计算出了比较大的值),后面几维可能会比较小(例如,上例中<math>\textstyle x_{{\rm rot},2}^{(i)} = u_2^Tx^{(i)}</math>计算出了值较小)。
+
-
 
+
-
【一审】:PCA的另外一种解释是:<math>\textstyle x_{\rm rot}</math>是一个<math>\textstyle n</math>维的向量,其中前面几维比较大(例如,上例中对于大部分的样本<math>\textstyle i</math>通过<math>\textstyle x_{{\rm rot},1}^{(i)} = u_1^Tx^{(i)}</math>计算出了比较大的值),后面几维可能会比较小(例如,上例中<math>\textstyle x_{{\rm rot},2}^{(i)} = u_2^Tx^{(i)}</math>计算出了值较小)。
+
-
 
+
-
【二审】:PCA的另外一种解释是:<math>\textstyle x_{\rm rot}</math>是一个<math>\textstyle n</math>维向量,其中前几维比较大(例如,上例中对于大部分样本<math>\textstyle i</math>,通过<math>\textstyle x_{{\rm rot},1}^{(i)} = u_1^Tx^{(i)}</math>计算出了比较大的值),后面的成分可能会比较小(例如,上例中<math>\textstyle x_{{\rm rot},2}^{(i)} = u_2^Tx^{(i)}</math>计算出的值较小)。
+
-
 
+
-
【原文】:What
+
PCA算法做的其实就是丢弃 <math>\textstyle x_{\rm rot}</math> 中后面(取值较小)的成分,就是将这些成分的值近似为零。具体的说,设 <math>\textstyle \tilde{x}</math> <math>\textstyle x_{{\rm rot}}</math> 的近似表示,那么将 <math>\textstyle x_{{\rm rot}}</math> 除了前 <math>\textstyle k</math> 个成分外,其余全赋值为零,就得到:
-
PCA does it it
+
-
drops the the later (smaller) components of <math>\textstyle x_{\rm rot}</math>, and
+
-
just approximates them with 0's.  Concretely, our definition of
+
-
<math>\textstyle \tilde{x}</math> can also be arrived at by using an approximation to
+
-
<math>\textstyle x_{{\rm rot}}</math> where
+
-
all but the first
+
-
<math>\textstyle k</math> components are zeros.  In other words, we have:
+
:<math>\begin{align}
:<math>\begin{align}
Line 332: Line 100:
\end{align}</math>
\end{align}</math>
-
In our example, this gives us the following plot of <math>\textstyle \tilde{x}</math> (using <math>\textstyle n=2, k=1</math>):
+
在本例中,可得 <math>\textstyle \tilde{x}</math> 的点图如下(取 <math>\textstyle n=2, k=1</math> ):
-
 
+
-
【初译】:而PCA算法就是丢弃<math>\textstyle x_{\rm rot}</math>中后面的(较小的)成分,把他们赋值为零。更直观的说就是,<math>\textstyle \tilde{x}</math>也可以用<math>\textstyle x_{{\rm rot}}</math>的除了前<math>\textstyle k</math>个成分,其余全赋值为零来表示。换句话说就是,我们可以运用如下算式:
+
-
:<math>\begin{align}
+
-
\tilde{x} =
+
-
\begin{bmatrix}
+
-
x_{{\rm rot},1} \\
+
-
\vdots \\
+
-
x_{{\rm rot},k} \\
+
-
0 \\
+
-
\vdots \\
+
-
0 \\
+
-
\end{bmatrix}
+
-
\approx
+
-
\begin{bmatrix}
+
-
x_{{\rm rot},1} \\
+
-
\vdots \\
+
-
x_{{\rm rot},k} \\
+
-
x_{{\rm rot},k+1} \\
+
-
\vdots \\
+
-
x_{{\rm rot},n}
+
-
\end{bmatrix}
+
-
= x_{\rm rot}
+
-
\end{align}</math>
+
-
 
+
-
在我们的实验中,得到了如下的<math>\textstyle \tilde{x}</math>的图形(取<math>\textstyle n=2, k=1</math>):
+
-
 
+
-
【一审】:而PCA算法就是丢弃<math>\textstyle x_{\rm rot}</math>中后面的(较小的)成分,把他们赋值为零。更直观地说就是,<math>\textstyle \tilde{x}</math>也可以用<math>\textstyle x_{{\rm rot}}</math>的除了前<math>\textstyle k</math>个成分,其余全赋值为零来表示。换句话说就是,我们可以运用如下算式:
+
-
:<math>\begin{align}
+
-
\tilde{x} =
+
-
\begin{bmatrix}
+
-
x_{{\rm rot},1} \\
+
-
\vdots \\
+
-
x_{{\rm rot},k} \\
+
-
0 \\
+
-
\vdots \\
+
-
0 \\
+
-
\end{bmatrix}
+
-
\approx
+
-
\begin{bmatrix}
+
-
x_{{\rm rot},1} \\
+
-
\vdots \\
+
-
x_{{\rm rot},k} \\
+
-
x_{{\rm rot},k+1} \\
+
-
\vdots \\
+
-
x_{{\rm rot},n}
+
-
\end{bmatrix}
+
-
= x_{\rm rot}
+
-
\end{align}</math>
+
-
 
+
-
在我们的实验中,得到了如下的<math>\textstyle \tilde{x}</math>的图形(取<math>\textstyle n=2, k=1</math>):
+
-
 
+
-
【二审】:PCA算法做的就是丢弃<math>\textstyle x_{\rm rot}</math>后面的(较小的)成分,将其取近似为零。具体的说,<math>\textstyle \tilde{x}</math>可以定义为,<math>\textstyle x_{{\rm rot}}</math>除了前<math>\textstyle k</math>个成分,其余全赋值为零的近似表示。换句话说:
+
-
:<math>\begin{align}
+
-
\tilde{x} =
+
-
\begin{bmatrix}
+
-
x_{{\rm rot},1} \\
+
-
\vdots \\
+
-
x_{{\rm rot},k} \\
+
-
0 \\
+
-
\vdots \\
+
-
0 \\
+
-
\end{bmatrix}
+
-
\approx
+
-
\begin{bmatrix}
+
-
x_{{\rm rot},1} \\
+
-
\vdots \\
+
-
x_{{\rm rot},k} \\
+
-
x_{{\rm rot},k+1} \\
+
-
\vdots \\
+
-
x_{{\rm rot},n}
+
-
\end{bmatrix}
+
-
= x_{\rm rot}
+
-
\end{align}</math>
+
-
在我们的示例中,可得<math>\textstyle \tilde{x}</math>的图形如下(取<math>\textstyle n=2, k=1</math>):
+
[[File:PCA-xtilde.png | 600px]]
[[File:PCA-xtilde.png | 600px]]
 +
然而,由于上面 <math>\textstyle \tilde{x}</math> 的后<math>\textstyle n-k</math>项均为零,没必要把这些零项保留下来。所以,我们仅用前 <math>\textstyle k</math> 个(非零)成分来定义 <math>\textstyle k</math> 维向量 <math>\textstyle \tilde{x}</math> 。
-
【原文】:However, since the final <math>\textstyle n-k</math> components of <math>\textstyle \tilde{x}</math> as defined above would
+
这也解释了我们为什么会以 <math>\textstyle u_1, u_2, \ldots, u_n</math> 为基来表示数据:要决定保留哪些成分变得很简单,只需取前 <math>\textstyle k</math> 个成分即可。这时也可以说,我们“保留了前 <math>\textstyle k</math> 个PCA(主)成分”。
-
always be zero, there is no need to keep these zeros around, and so we
+
-
define <math>\textstyle \tilde{x}</math> as a <math>\textstyle k</math>-dimensional vector with just the first <math>\textstyle k</math> (non-zero) components.
+
-
【初译】:然而,由于上面<math>\textstyle \tilde{x}</math>的后<math>\textstyle n-k</math>项都归为了零,所以也就没必要把这些零项保留下来。因此,我们仅用前<math>\textstyle k</math>个成分来定义<math>\textstyle k</math>维向量的<math>\textstyle \tilde{x}</math>。
 
-
【一审】:然而,由于上面<math>\textstyle \tilde{x}</math>的后<math>\textstyle n-k</math>项都归为了零,所以也就没必要把这些零项保留下来。因此,我们仅用前<math>\textstyle k</math>个成分来定义<math>\textstyle k</math>维向量的<math>\textstyle \tilde{x}</math>。
+
== 还原近似数据 ==
-
【二审】:然而,由于上面<math>\textstyle \tilde{x}</math>的后<math>\textstyle n-k</math>项均为零,所以没必要把这些零项保留下来。因此,我们仅用前<math>\textstyle k</math>个(非零)成分来定义<math>\textstyle k</math>维向量<math>\textstyle \tilde{x}</math>。
+
现在,我们得到了原始数据 <math>\textstyle x \in \Re^n</math> 的低维“压缩”表征量 <math>\textstyle \tilde{x} \in \Re^k</math> , 反过来,如果给定 <math>\textstyle \tilde{x}</math> ,我们应如何还原原始数据 <math>\textstyle x</math> 呢?查看[[#旋转数据|以往章节]]以往章节可知,要转换回来,只需 <math>\textstyle x = U x_{\rm rot}</math> 即可。进一步,我们把 <math>\textstyle \tilde{x}</math> 看作将 <math>\textstyle x_{\rm rot}</math> 的最后 <math>\textstyle n-k</math> 个元素被置0所得的近似表示,因此如果给定 <math>\textstyle \tilde{x} \in \Re^k</math> ,可以通过在其末尾添加 <math>\textstyle n-k</math> 个0来得到对 <math>\textstyle x_{\rm rot} \in \Re^n</math> 的近似,最后,左乘 <math>\textstyle U</math> 便可近似还原出原数据 <math>\textstyle x</math> 。具体来说,计算如下:
-
 
+
-
 
+
-
【原文】:This also explains why we wanted to express our data in the <math>\textstyle u_1, u_2, \ldots, u_n</math> basis:
+
-
Deciding which components to keep becomes just keeping the top <math>\textstyle k</math> components.  When we
+
-
do this, we also say that we are "retaining the top <math>\textstyle k</math> PCA (or principal) components."
+
-
 
+
-
【初译】:这也解释了为什么会以<math>\textstyle u_1, u_2, \ldots, u_n</math>为基来表示我们的数据:任务从决定哪些成分需要保留变成了只需简单选取<math>\textstyle k</math>个成分。这种运算我们也可以描述为“我们保留了<math>\textstyle k</math>个PCA(主)成分”。
+
-
 
+
-
【一审】:这也解释了为什么会以<math>\textstyle u_1, u_2, \ldots, u_n</math>为基来表示我们的数据:从决定哪些成分需要保留演变成了只需简单选取<math>\textstyle k</math>个关键成分。这种运算我们也可以描述为“我们保留了<math>\textstyle k</math>个PCA(主)成分”。
+
-
 
+
-
【二审】:这也解释了我们为什么会以<math>\textstyle u_1, u_2, \ldots, u_n</math>为基来表示数据:从决定哪些成分需要保留,变成只需简单选取前<math>\textstyle k</math>个成分。当我们这么做的时候,可以描述为我们“保留了前<math>\textstyle k</math>个PCA(主)成分”。
+
-
 
+
-
 
+
-
== Recovering an Approximation of the Data 数据还原 ==
+
-
 
+
-
 
+
-
【原文】:Now, <math>\textstyle \tilde{x} \in \Re^k</math> is a lower-dimensional, "compressed" representation
+
-
of the original <math>\textstyle x \in \Re^n</math>.  Given <math>\textstyle \tilde{x}</math>, how can we recover an approximation <math>\textstyle \hat{x}</math> to
+
-
the original value of <math>\textstyle x</math>?  From an [[#Rotating the Data|earlier section]], we know that <math>\textstyle x = U x_{\rm rot}</math>.  Further,
+
-
we can think of <math>\textstyle \tilde{x}</math> as an approximation to <math>\textstyle x_{\rm rot}</math>, where we have
+
-
set the last <math>\textstyle n-k</math> components to zeros.  Thus, given <math>\textstyle \tilde{x} \in \Re^k</math>, we can
+
-
pad it out with <math>\textstyle n-k</math> zeros to get our approximation to <math>\textstyle x_{\rm rot} \in \Re^n</math>.  Finally, we pre-multiply
+
-
by <math>\textstyle U</math> to get our approximation to <math>\textstyle x</math>.  Concretely, we get
+
-
 
+
-
【初译】:经过上一步骤,我们得到了对应原始数据<math>\textstyle x \in \Re^n</math>的低维“压缩”表征量<math>\textstyle \tilde{x} \in \Re^k</math>,反过来,如果给定<math>\textstyle \tilde{x}</math>,我们应如何尽可能地还原原始数据<math>\textstyle \hat{x}</math>呢?由本章第三节可知<math>\textstyle x = U x_{\rm rot}</math>,且<math>\textstyle \tilde{x}</math>可以看作<math>\textstyle x_{\rm rot}</math>的近似值,因为<math>\textstyle \tilde{x}</math>只是将<math>\textstyle x_{\rm rot}</math>最后的<math>\textstyle n-k</math>个元素用0代替并省略而得到,因此如果给定<math>\textstyle \tilde{x} \in \Re^k</math>,可以通过在其末尾添加<math>\textstyle n-k</math>个0来得到<math>\textstyle x_{\rm rot} \in \Re^n</math>的近似,接着用<math>\textstyle U</math>左乘该<math>\textstyle x_{\rm rot}</math>近似值便可得到对原数据<math>\textstyle x</math>的近似还原。具体来说,我们需进行如下计算:
+
-
 
+
-
【一审】:现在,<math>\textstyle \tilde{x} \in \Re^k</math>成为<math>\textstyle x \in \Re^n</math>在低维空间的一个“压缩”表征。 反过来,如果给定<math>\textstyle \tilde{x}</math>,我们应如何尽可能地还原原始数据<math>\textstyle \hat{x}</math>呢?由本章第三节可知<math>\textstyle x = U x_{\rm rot}</math>,且<math>\textstyle \tilde{x}</math>可以看作<math>\textstyle x_{\rm rot}</math>的近似值,因为<math>\textstyle \tilde{x}</math>只是将<math>\textstyle x_{\rm rot}</math>最后的<math>\textstyle n-k</math>个元素用0代替并省略而得到,因此如果给定<math>\textstyle \tilde{x} \in \Re^k</math>,可以通过在其末尾添加<math>\textstyle n-k</math>个0来得到<math>\textstyle x_{\rm rot} \in \Re^n</math>的近似,接着用<math>\textstyle U</math>左乘该<math>\textstyle x_{\rm rot}</math>近似值便可得到对原数据<math>\textstyle x</math>的近似还原。具体来说,我们需进行如下计算:
+
-
 
+
-
【二审】:现在,我们得到了原始数据<math>\textstyle x \in \Re^n</math>的低维“压缩”表征量<math>\textstyle \tilde{x} \in \Re^k</math>, 反过来,如果给定<math>\textstyle \tilde{x}</math>,我们应如何还原原始数据<math>\textstyle \hat{x}</math>呢?查看以往章节可知<math>\textstyle x = U x_{\rm rot}</math>,且可把<math>\textstyle \tilde{x}</math>看作将<math>\textstyle x_{\rm rot}</math>的最后<math>\textstyle n-k</math>个元素置0所得的近似值,因此如果给定<math>\textstyle \tilde{x} \in \Re^k</math>,可以通过在其末尾添加<math>\textstyle n-k</math>个0来得到<math>\textstyle x_{\rm rot} \in \Re^n</math>的近似,最后,左乘<math>\textstyle U</math>便可得原数据<math>\textstyle x</math>的近似。具体来说,计算如下:
+
:<math>\begin{align}
:<math>\begin{align}
Line 455: Line 118:
\end{align}</math>
\end{align}</math>
-
 
+
上面的等式基于[[#实例和数学背景|先前]]<math>\textstyle U</math> 的定义。在实现时,我们实际上并不先给 <math>\textstyle \tilde{x}</math> 填0然后再左乘 <math>\textstyle U</math> ,因为这意味着大量的乘0运算。我们可用 <math>\textstyle \tilde{x} \in \Re^k</math> 来与 <math>\textstyle U</math> 的前 <math>\textstyle k</math> 列相乘,即上式中最右项,来达到同样的目的。将该算法应用于本例中的数据集,可得如下关于重构数据 <math>\textstyle \hat{x}</math> 的点图:
-
【原文】:The final equality above comes from the definition of <math>\textstyle U</math> [[#Example and Mathematical Background|given earlier]].
+
-
(In a practical implementation, we wouldn't actually zero pad <math>\textstyle \tilde{x}</math> and then multiply
+
-
by <math>\textstyle U</math>, since that would mean multiplying a lot of things by zeros; instead, we'd just
+
-
multiply <math>\textstyle \tilde{x} \in \Re^k</math> with the first <math>\textstyle k</math> columns of <math>\textstyle U</math> as in the final expression above.)
+
-
Applying this to our dataset, we get the following plot for <math>\textstyle \hat{x}</math>:
+
-
 
+
-
【初译】:该式中的第二个等号由先前对<math>\textstyle U</math>的定义可知成立,(在实际应用时,我们不倾向于先给<math>\textstyle \tilde{x}</math>填0然后再左乘<math>\textstyle U</math>,因为这样意味着大量的乘0运算,相反我们选择用<math>\textstyle U</math>的前<math>\textstyle k</math>列来乘<math>\textstyle \tilde{x} \in \Re^k</math>,其结果也即等于上面式子中最右边项。)将该算法应用到本章节的样例数据集,我们可以得到以下关于<math>\textstyle \hat{x}</math>的作图:
+
-
 
+
-
【一审】:上面的等式来源于先前对<math>\textstyle U</math>的定义,(在实际应用时,我们不倾向于先给<math>\textstyle \tilde{x}</math>填0然后再左乘<math>\textstyle U</math>,因为这样意味着大量的乘0运算,相反我们选择用<math>\textstyle U</math>的前<math>\textstyle k</math>列来乘<math>\textstyle \tilde{x} \in \Re^k</math>,其结果也即等于上面式子中最右边项。)将该算法应用到本章节的样例数据集,我们可以得到以下关于<math>\textstyle \hat{x}</math>的图示:
+
-
 
+
-
【二审】:上面的等式来源于先前对<math>\textstyle U</math>的定义,(在实际应用时,我们不倾向于先给<math>\textstyle \tilde{x}</math>填0然后再左乘<math>\textstyle U</math>,因为这意味着大量的乘0运算,相反我们选择用<math>\textstyle \tilde{x} \in \Re^k</math>的前<math>\textstyle k</math>列来乘<math>\textstyle U</math>,即上式中最右项。)将该算法应用于本例中的数据集,我们可得如下关于 <math>\textstyle \hat{x}</math>的图示:
+
-
 
+
[[File:PCA-xhat.png | 600px]]
[[File:PCA-xhat.png | 600px]]
 +
由图可见,我们得到的是对原始数据集的一维近似重构。
-
【原文】:We are thus using a 1 dimensional approximation to the original dataset.
+
在训练自动编码器或其它无监督特征学习算法时,算法运行时间将依赖于输入数据的维数。若用 <math>\textstyle \tilde{x} \in \Re^k</math> 取代 <math>\textstyle x</math> 作为输入数据,那么算法就可使用低维数据进行训练,运行速度将显著加快。对于很多数据集来说,低维表征量 <math>\textstyle \tilde{x}</math> 是原数据集的极佳近似,因此在这些场合使用PCA是很合适的,它引入的近似误差的很小,却可显著地提高你算法的运行速度。
-
If you are training an autoencoder or other unsupervised feature learning algorithm,
 
-
the running time of your algorithm will depend on the dimension of the input.  If you feed <math>\textstyle \tilde{x} \in \Re^k</math>
 
-
into your learning algorithm instead of <math>\textstyle x</math>, then you'll be training on a lower-dimensional
 
-
input, and thus your algorithm might run significantly faster.  For many datasets,
 
-
the lower dimensional <math>\textstyle \tilde{x}</math> representation can be an extremely good approximation
 
-
to the original, and using PCA this way can significantly speed up your algorithm while
 
-
introducing very little approximation error.
 
-
【初译】:由图可看出我们实际上得到的是对原始数据的一维近似。
+
== 选择主成分个数 ==
-
如果要训练一个自动编码器(autoencoder)或其它无监督特征学习算法,运算时间将直接依赖于输入数据的维数。若用<math>\textstyle \tilde{x} \in \Re^k</math>取代<math>\textstyle x</math>作为输入数据,那么算法将使用该低维数据进行训练,运行速度也大大加快。对于很多数据集来说,低维表征量<math>\textstyle \tilde{x}</math>都可达到对原数据集的完美近似,因此对这些数据集使用PCA算法将可保证在只产生较小近似误差的同时极大地提速程序。
+
我们该如何选择 <math>\textstyle k</math> ,即保留多少个PCA主成分?在上面这个简单的二维实验中,保留第一个成分看起来是自然的选择。对于高维数据来说,做这个决定就没那么简单:如果 <math>\textstyle k</math> 过大,数据压缩率不高,在极限情况 <math>\textstyle k=n</math> 时,等于是在使用原始数据(只是旋转投射到了不同的基);相反地,如果 <math>\textstyle k</math> 过小,那数据的近似误差太太。
-
【一审】:由上图可看出我们实际上得到的是对原始数据的一维近似。
+
决定 <math>\textstyle k</math> 值时,我们通常会考虑不同 <math>\textstyle k</math> 值可保留的方差百分比。具体来说,如果 <math>\textstyle k=n</math> ,那么我们得到的是对数据的完美近似,也就是保留了100%的方差,即原始数据的所有变化都被保留下来;相反,如果 <math>\textstyle k=0</math> ,那等于是使用零向量来逼近输入数据,也就是只有0%的方差被保留下来。
-
如果要训练一个自动编码器(autoencoder)或其它无监督特征学习算法,运算时间将直接依赖于输入数据的维度数。若用<math>\textstyle \tilde{x} \in \Re^k</math>取代<math>\textstyle x</math>作为输入数据,那么算法将使用该低维数据进行训练,运行速度也大大加快。对于很多数据集来说,低维表征量<math>\textstyle \tilde{x}</math>都可达到对原数据集的完美近似,因此对这些数据集使用PCA算法将可保证在只产生较小近似误差的同时极大地提速程序。
+
一般而言,设 <math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math> 表示 <math>\textstyle \Sigma</math> 的特征值(按由大到小顺序排列),使得 <math>\textstyle \lambda_j</math> 为对应于特征向量 <math>\textstyle u_j</math> 的特征值。那么如果我们保留前 <math>\textstyle k</math> 个成分,则保留的方差百分比可计算为:
-
 
+
-
【二审】:由图可知我们得到的是对原始数据集的一维近似。
+
-
 
+
-
如果要训练一个自动编码器或其它无监督特征学习算法,算法运行时间将依赖于输入数据的维数。若用<math>\textstyle \tilde{x} \in \Re^k</math>取代<math>\textstyle x</math>作为输入数据,那么算法将使用低维数据进行训练,运行速度将显著加快。对于很多数据集来说,低维表征量<math>\textstyle \tilde{x}</math>即为原数据集的极佳近似,如此使用PCA算法可在只产生极小近似误差的同时,显著地提高运行速度。
+
-
 
+
-
 
+
-
== Number of components to retain 选择主成分个数 ==
+
-
 
+
-
 
+
-
【原文】:How do we set <math>\textstyle k</math>; i.e., how many PCA components should we retain?  In our
+
-
simple 2 dimensional example, it seemed natural to retain 1 out of the 2
+
-
components, but for higher dimensional data, this decision is less trivial.  If <math>\textstyle k</math> is
+
-
too large, then we won't be compressing the data much; in the limit of <math>\textstyle k=n</math>,
+
-
then we're just using the original data (but rotated into a different basis).
+
-
Conversely, if <math>\textstyle k</math> is too small, then we might be using a very bad
+
-
approximation to the data.
+
-
 
+
-
【初译】:接下来的问题是我们如何选择<math>\textstyle k</math>,即有多少个PCA主成分值得保留?在我们这个简单的二维实验中,保留第一个成分是十分自然的选择,但对于高维数据来说,做这个决定就没那么简单:如果<math>\textstyle k</math>过大,我们便没有多少有效压缩,如果是极限情况<math>\textstyle k=n</math>,我们等同于在使用原始数据(只是旋转投射到了一组不同的基);相反地,如果<math>\textstyle k</math>过小,那我们使用的近似值也可能带来很大的近似误差。
+
-
 
+
-
【一审】:接下来的问题是我们如何选择<math>\textstyle k</math>,即有多少个PCA主成分值得保留?在我们这个简单的二维实验中,保留一个成分是十分自然的选择,但对于高维数据来说,做这个决定就没那么简单:如果<math>\textstyle k</math>过大,我们便没有多少有效压缩,如果是极限情况<math>\textstyle k=n</math>,我们等同于在使用原始数据(只是旋转投射到了一组不同的基);相反地,如果<math>\textstyle k</math>过小,那我们很可能比较差的近似数据。
+
-
 
+
-
【二审】:我们如何选择<math>\textstyle k</math>,即有多少个PCA主成分应该保留?在我们这个简单的二维实验中,保留第一个成分看起来是自然的选择,但对于高维数据来说,做这个决定就没那么简单:如果<math>\textstyle k</math>过大,数据压缩率不高,在极限情况<math>\textstyle k=n</math>时,等于是在使用原始数据(只是旋转投射到了不同的基);相反地,如果<math>\textstyle k</math>过小,那我们可能使用很差的近似数据。
+
-
 
+
-
 
+
-
【原文】:To decide how to set <math>\textstyle k</math>, we will usually look at the '''percentage of variance retained'''
+
-
for different values of <math>\textstyle k</math>.  Concretely, if <math>\textstyle k=n</math>, then we have
+
-
an exact approximation to the data, and we say that 100% of the variance is
+
-
retained.  I.e., all of the variation of the original data is retained. 
+
-
Conversely, if <math>\textstyle k=0</math>, then we are approximating all the data with the zero vector,
+
-
and thus 0% of the variance is retained.
+
-
 
+
-
【初译】:在决定<math>\textstyle k</math>的过程中,我们通常会计算不同<math>\textstyle k</math>值可保留的方差百分比,具体来说,如果<math>\textstyle k=n</math>,那么我们得到的是对数据的完美近似,也就是保留了100%的方差,即原始数据的所有变化特性(variation)都被保留下来;如果<math>\textstyle k=0</math>,那么我们是在使用零向量来近似输入数据,因此也就只有0%的方差可以被保留。
+
-
 
+
-
【一审】:为了决定<math>\textstyle k</math>值,我们通常会计算不同<math>\textstyle k</math>值可保留的方差百分比,具体来说,如果<math>\textstyle k=n</math>,那么我们得到的是对数据的完美近似,也就是保留了100%的方差,即原始数据的所有变化特性(variation)都被保留下来;如果<math>\textstyle k=0</math>,那么我们是在使用零向量来近似输入数据,因此也就只有0%的方差可以被保留。
+
-
 
+
-
【二审】:在决定<math>\textstyle k</math>值设置的过程中,我们通常会计算不同<math>\textstyle k</math>值可保留的方差百分比,具体来说,如果<math>\textstyle k=n</math>,那么我们得到的是对数据的完美近似,也就是保留了100%的方差,即原始数据的所有变化都被保留下来;相反,如果<math>\textstyle k=0</math>,那么我们是在使用零向量来近似输入数据,因此也就只有0%的方差可以被保留。
+
-
 
+
-
 
+
-
【原文】:More generally, let <math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math> be the eigenvalues
+
-
of <math>\textstyle \Sigma</math> (sorted in decreasing order), so that <math>\textstyle \lambda_j</math> is the eigenvalue
+
-
corresponding to the eigenvector <math>\textstyle u_j</math>.  Then if we retain <math>\textstyle k</math> principal components,
+
-
the percentage of variance retained is given by:
+
-
 
+
-
【初译】:更一般的情况,假设<math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math>表示<math>\textstyle \Sigma</math>的特征值(按由大到小顺序排列),则<math>\textstyle \lambda_j</math>为对应于特征向量<math>\textstyle u_j</math>的特征值,如果我们保留前<math>\textstyle k</math>个成分,则保留的方差百分比可计算为:
+
-
 
+
-
【一审】:更一般的情况,假设<math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math>表示<math>\textstyle \Sigma</math>的特征值(按由大到小降序排列),则<math>\textstyle \lambda_j</math>为对应于特征向量<math>\textstyle u_j</math>的特征值,如果我们保留前<math>\textstyle k</math>个主成分,则保留的方差百分比可计算为:
+
-
 
+
-
【二审】:更一般的情况,假设<math>\textstyle \lambda_1, \lambda_2, \ldots, \lambda_n</math>表示<math>\textstyle \Sigma</math>的特征值(按由大到小顺序排列),则<math>\textstyle \lambda_j</math>为对应于特征向量<math>\textstyle u_j</math>的特征值,如果我们保留前<math>\textstyle k</math>个成分,则保留的方差百分比可计算为:
+
:<math>\begin{align}
:<math>\begin{align}
Line 542: Line 139:
\end{align}</math>
\end{align}</math>
 +
在上面简单的二维实验中,<math>\textstyle \lambda_1 = 7.29</math> ,<math>\textstyle \lambda_2 = 0.69</math> 。因此,如果保留 <math>\textstyle k=1</math> 个主成分,等于我们保留了 <math>\textstyle 7.29/(7.29+0.69) = 0.913</math> ,即91.3%的方差。
-
【原文】:In our simple 2D example above, <math>\textstyle \lambda_1 = 7.29</math>, and <math>\textstyle \lambda_2 = 0.69</math>.  Thus,
+
对保留方差的百分比进行更正式的定义已超出了本教程的范围,但很容易证明,<math>\textstyle \lambda_j =
-
by keeping only <math>\textstyle k=1</math> principal components, we retained <math>\textstyle 7.29/(7.29+0.69) = 0.913</math>,
+
\sum_{i=1}^m x_{{\rm rot},j}^2</math> 。因此,如果 <math>\textstyle \lambda_j \approx 0</math> ,则说明 <math>\textstyle x_{{\rm rot},j}</math> 也就基本上接近于0,所以用0来近似它并不会产生多大损失。这也解释了为什么要保留前面的主成分(对应的 <math>\textstyle \lambda_j</math> 值较大)而不是末尾的那些。 这些前面的主成分 <math>\textstyle x_{{\rm rot},j}</math> 变化性更大,取值也更大,如果将其设为0势必引入较大的近似误差。
-
or 91.3% of the variance.
+
-
【初译】:在我们的二维实验中,<math>\textstyle \lambda_1 = 7.29</math>,<math>\textstyle \lambda_2 = 0.69</math>,保留前<math>\textstyle k=1</math>个主成分,也等于我们保留了<math>\textstyle 7.29/(7.29+0.69) = 0.913</math>,即91.3%的方差。
+
以处理图像数据为例,一个惯常的经验法则是选择 <math>\textstyle k</math> 以保留99%的方差,换句话说,我们选取满足以下条件的最小 <math>\textstyle k</math> 值:
-
【一审】:上面我们的二维实验中,<math>\textstyle \lambda_1 = 7.29</math>,<math>\textstyle \lambda_2 = 0.69</math>,保留前<math>\textstyle k=1</math>个主成分,也等于我们保留了<math>\textstyle 7.29/(7.29+0.69) = 0.913</math>,即91.3%的方差。
 
-
 
-
【二审】:上面我们简单的二维实验中,<math>\textstyle \lambda_1 = 7.29</math>,<math>\textstyle \lambda_2 = 0.69</math>,因此,仅保留<math>\textstyle k=1</math>个主成分,等于我们保留了<math>\textstyle 7.29/(7.29+0.69) = 0.913</math>,即91.3%的方差。
 
-
 
-
 
-
【原文】:A more formal definition of percentage of variance retained is beyond the scope
 
-
of these notes.  However, it is possible to show that <math>\textstyle \lambda_j =
 
-
\sum_{i=1}^m x_{{\rm rot},j}^2</math>.  Thus, if <math>\textstyle \lambda_j \approx 0</math>, that shows that
 
-
<math>\textstyle x_{{\rm rot},j}</math> is usually near 0 anyway, and we lose relatively little by
 
-
approximating it with a constant 0.  This also explains why we retain the top principal
 
-
components (corresponding to the larger values of <math>\textstyle \lambda_j</math>) instead of the bottom
 
-
ones.  The top principal components
 
-
<math>\textstyle x_{{\rm rot},j}</math> are the ones that're more variable and that take on larger values,
 
-
and for which we would incur a greater approximation error if we were to set them to zero.
 
-
 
-
【初译】:虽然对保留方差的百分比进行更规范的定义已超出了本教程的范围,但退一步说,因可以证明<math>\textstyle \lambda_j =
 
-
\sum_{i=1}^m x_{{\rm rot},j}^2</math>,如果<math>\textstyle \lambda_j \approx 0</math>,则说明<math>\textstyle x_{{\rm rot},j}</math>基本接近于0,将其赋值为常数0因而并不会产生较大损失,这也解释了为什么要保留排名靠前的主成分(对应值较大的<math>\textstyle \lambda_j</math>)而不是末尾的那些, 这些排名靠前的主成分<math>\textstyle x_{{\rm rot},j}</math>方差更大,值也较大,如果设为0将引入较大的近似误差。
 
-
 
-
【一审】:虽然对保留方差的百分比进行更规范的定义已超出了本笔记的范围,但很容易判断,<math>\textstyle \lambda_j =
 
-
\sum_{i=1}^m x_{{\rm rot},j}^2</math>,如果<math>\textstyle \lambda_j \approx 0</math>,则说明<math>\textstyle x_{{\rm rot},j}</math>基本接近于0,将其赋值为常数0因而并不会产生较大损失,这也解释了为什么要保留排名靠前的主成分(对应值较大的<math>\textstyle \lambda_j</math>)而不是末尾的那些, 这些排名靠前的主成分<math>\textstyle x_{{\rm rot},j}</math>方差更大,值也较大,如果设为0将引入较大的近似误差。
 
-
 
-
【二审】:虽然对保留方差的百分比进行更规范的定义已超出了本教程的范围,但很容易判断<math>\textstyle \lambda_j =
 
-
\sum_{i=1}^m x_{{\rm rot},j}^2</math>,,因可以证明,如果<math>\textstyle \lambda_j \approx 0</math>,则说明<math>\textstyle x_{{\rm rot},j}</math>基本接近于0,将其赋值为常数0因而并不会产生较大损失,这也解释了为什么要保留排名靠前的主成分(对应<math>\textstyle \lambda_j</math>值较大的)而不是末尾的那些,这些排名靠前的主成分<math>\textstyle x_{{\rm rot},j}</math>变动更大,因此值也更大,如果设为0将引入较大的近似误差。
 
-
 
-
 
-
【原文】:In the case of images, one common heuristic is to choose <math>\textstyle k</math> so as to retain 99% of
 
-
the variance.  In other words, we pick the smallest value of <math>\textstyle k</math> that satisfies
 
:<math>\begin{align}
:<math>\begin{align}
\frac{\sum_{j=1}^k \lambda_j}{\sum_{j=1}^n \lambda_j} \geq 0.99.  
\frac{\sum_{j=1}^k \lambda_j}{\sum_{j=1}^n \lambda_j} \geq 0.99.  
\end{align}</math>
\end{align}</math>
-
Depending on the application, if you are willing to incur some
 
-
additional error, values in the 90-98% range are also sometimes used.  When you
 
-
describe to others how you applied PCA, saying that you chose <math>\textstyle k</math> to retain 95% of
 
-
the variance will also be a much more easily interpretable description than saying
 
-
that you retained 120 (or whatever other number of) components.
 
-
【初译】:处理图像数据时,一个惯常的经验法则是选择<math>\textstyle k</math>以保留99%的方差,换一句话说,我们选择所有满足以下条件的<math>\textstyle k</math>中的最小值:
+
对其它应用,如不介意引入稍大的误差,有时也保留90-98%的方差范围。若向他人介绍PCA算法详情,告诉他们你选择的 <math>\textstyle k</math> 保留了95%的方差,比告诉他们你保留了前120个(或任意某个数字)主成分更好理解。
-
:<math>\begin{align}
+
-
\frac{\sum_{j=1}^k \lambda_j}{\sum_{j=1}^n \lambda_j} \geq 0.99.
+
-
\end{align}</math>
+
-
对于其它的应用,如果不介意引入的误差稍大,那保留方差百分比在90-98%范围内可能都合理。若向他人介绍PCA算法,告诉他们你选择的<math>\textstyle k</math>是为了保留95%的方差相较于直接告诉他们你保留了前120个(或任意某个数字)主成分也更便于他人理解。
+
-
【一审】:处理图像数据时,一个惯常的经验法则是选择<math>\textstyle k</math>以保留99%的方差,换一句话说,我们选择所有满足以下条件的<math>\textstyle k</math>中的最小值:
 
-
:<math>\begin{align}
 
-
\frac{\sum_{j=1}^k \lambda_j}{\sum_{j=1}^n \lambda_j} \geq 0.99.
 
-
\end{align}</math>
 
-
对于其它的应用,如果不介意引入的误差稍大,那保留方差百分比在90-98%范围内可能都合理。若向他人介绍PCA算法,告诉他们你选择的<math>\textstyle k</math>是为了保留95%的方差相较于直接告诉他们你保留了前120个(或任意某个数字)主成分也更便于他人理解。
 
-
【二审】:以处理图像数据为例,一个惯常的经验法则是选择<math>\textstyle k</math>以保留99%的方差,换句话说,我们选取满足以下条件的最小<math>\textstyle k</math>值:
+
== 对图像数据应用PCA算法 ==
-
:<math>\begin{align}
+
-
\frac{\sum_{j=1}^k \lambda_j}{\sum_{j=1}^n \lambda_j} \geq 0.99.
+
-
\end{align}</math>
+
-
对其它应用,如不介意引入稍大的误差,有时也仅保留90-98%的方差范围。若向他人介绍PCA算法,告诉他们你选择的<math>\textstyle k</math>是为保留95%的方差,比告诉他们你保留了前120个(或任意某个数字)主成分更便于他人理解。
+
 +
为使PCA算法能有效工作,通常我们希望所有的特征 <math>\textstyle x_1, x_2, \ldots, x_n</math> 都有相似的取值范围(并且均值接近于0)。如果你曾在其它应用中使用过PCA算法,你可能知道有必要单独对每个特征做预处理,即通过估算每个特征 <math>\textstyle x_j</math> 的均值和方差,而后将其取值范围规整化为零均值和单位方差。但是,对于大部分图像类型,我们却不需要进行这样的预处理。假定我们将在自然图像上训练算法,此时特征 <math>\textstyle x_j</math> 代表的是像素 <math>\textstyle j</math> 的值。所谓“自然图像”,不严格的说,是指人或动物在他们一生中所见的那种图像。
-
== PCA on Images 对图像数据应用PCA算法 ==
+
注:通常我们选取含草木等内容的户外场景图片,然后从中随机截取小图像块(如16x16像素)来训练算法。在实践中我们发现,大多数特征学习算法对训练图片的确切类型并不敏感,所以大多数用普通照相机拍摄的图片,只要不是特别的模糊或带有非常奇怪的人工痕迹,都可以使用。
 +
在自然图像上进行训练时,对每一个像素单独估计均值和方差意义不大,因为(理论上)图像任一部分的统计性质都应该和其它部分相同,图像的这种特性被称作平稳性(stationarity)。
-
【原文】:For PCA to work, usually we want each of the features <math>\textstyle x_1, x_2, \ldots, x_n</math>
+
具体而言,为使PCA算法正常工作,我们通常需要满足以下要求:(1)特征的均值大致为0;(2)不同特征的方差值彼此相似。对于自然图片,即使不进行方差归一化操作,条件(2)也自然满足,故而我们不再进行任何方差归一化操作(对音频数据,如声谱,或文本数据,如词袋向量,我们通常也不进行方差归一化)。实际上,PCA算法对输入数据具有缩放不变性,无论输入数据的值被如何放大(或缩小),返回的特征向量都不改变。更正式的说:如果将每个特征向量 <math>\textstyle x</math> 都乘以某个正数(即所有特征量被放大或缩小相同的倍数),PCA的输出特征向量都将不会发生变化。
-
to have a similar range of values to the others (and to have a mean close to
+
-
zero).  If you've used PCA on other applications before, you may therefore have
+
-
separately pre-processed each feature to have zero mean and unit variance, by
+
-
separately estimating the mean and variance of each feature <math>\textstyle x_j</math>.  However,
+
-
this isn't the pre-processing that we will apply to most types of images.  Specifically,
+
-
suppose we are training our algorithm on '''natural images''', so that <math>\textstyle x_j</math> is
+
-
the value of pixel <math>\textstyle j</math>.  By "natural images," we informally mean the type of image that
+
-
a typical animal or person might see over their lifetime.
+
-
【初译】:为使PCA算法能正常工作,通常我们希望所有的特征<math>\textstyle x_1, x_2, \ldots, x_n</math>都有相似的取值范围(并且均值接近于0)。如果你曾对其它数据应用过PCA算法,你可能知道有必要单独对每个特征<math>\textstyle x_j</math>做预处理,估算其均值和方差以将其规范为零均值和单位方差。对于大部分的图像文件,我们却不进行这样的预处理,尤其是在我们使用“自然图像”(natural images)来训练算法时——“自然图像”可不正规的定义为通常动物或者人类可肉眼看到的图像类型——此时特征<math>\textstyle x_j</math>代表的是像素<math>\textstyle j</math>的值。
+
既然我们不做方差归一化,唯一还需进行的规整化操作就是均值规整化,其目的是保证所有特征的均值都在0附近。根据应用,在大多数情况下,我们并不关注所输入图像的整体明亮程度。比如在对象识别任务中,图像的整体明亮程度并不会影响图像中存在的是什么物体。更为正式地说,我们对图像块的平均亮度值不感兴趣,所以可以减去这个值来进行均值规整化。
-
【一审】:为使PCA算法能有效,通常我们希望所有的特征<math>\textstyle x_1, x_2, \ldots, x_n</math>都有相似的取值范围(并且均值接近于0)。如果你曾在其它应用使用过PCA算法,你可能知道有必要单独对每个特征<math>\textstyle x_j</math>做预处理,估算其均值和方差以将其规范为零均值和单位方差。对于大部分的图像文件,我们却不进行这样的预处理,尤其是在我们使用“自然图像”(natural images)来训练算法时,此时特征<math>\textstyle x_j</math>代表的是像素<math>\textstyle j</math>的值。“自然图像”含义是典型的动物或人,在平常生活中所看到的那样。
+
具体的步骤是,如果 <math>\textstyle x^{(i)} \in \Re^{n}</math> 代表16x16的图像块的亮度(灰度)值( <math>\textstyle n=256</math> ),可用如下算法来对每幅图像进行零均值化操作:
-
【二审】:为使PCA算法能有效,通常我们希望所有的特征<math>\textstyle x_1, x_2, \ldots, x_n</math>都有相似的取值范围(并且均值接近于0)。如果你曾在其它应用中使用过PCA算法,你可能知道有必要单独对每个特征做预处理,估算每个特征<math>\textstyle x_j</math>,将其规范为零均值和单位方差。但是,对于大部分图像文件,我们却不进行这样的预处理,尤其是当我们使用“自然图像”来训练算法时,此时特征<math>\textstyle x_j</math>代表的是像素<math>\textstyle j</math>的值,“自然图像”的含义是典型的动物或人的图像,如日常生活中所看到的那些。
+
<math>\mu^{(i)} := \frac{1}{n} \sum_{j=1}^n x^{(i)}_j</math>
 +
<math>x^{(i)}_j := x^{(i)}_j - \mu^{(i)}</math>, for all <math>\textstyle j</math>
-
【原文】:Note: Usually we use images of outdoor scenes with grass, trees, etc., and cut out small (say 16x16) image patches randomly from these to train the algorithm.  But in practice most feature learning algorithms are extremely robust to the exact type of image  it is trained on, so most images taken with a normal camera, so long as they aren't excessively blurry or have strange artifacts, should work. 
 
-
【初译】:注:通常我们使用户外拍摄草木等场景的照片,并从中随机截取小图像块(大小为16乘16像素)来训练算法,实际应用中我们发现,大多数特征学习算法对于训练的图片类型都具有极大的鲁棒性(robust),普通照相机拍摄的图片,只要不是特别的模糊或者有非常奇怪的人工痕迹,都应可以使用。
+
请注意:1)对每个输入图像块 <math>\textstyle x^{(i)}</math> 都要单独执行上面两个步骤,2)这里的  <math>\textstyle \mu^{(i)}</math> 是指图像块 <math>\textstyle x^{(i)}</math> 的平均亮度值。尤其需要注意的是,这和为每个像素 <math>\textstyle x_j</math> 单独估算均值是两个完全不同的概念。
-
【一审】:注:通常我们使用户外拍摄草木等场景的照片,并从中随机截取小图像块(大小为16乘16像素)来训练算法,实际应用中我们发现,大多数特征学习算法对于训练的图片类型都具有极大的鲁棒性(robust),普通照相机拍摄的图片,只要不是特别的模糊或者有非常奇怪的人工痕迹,都应可以使用。
+
如果你处理的图像并非自然图像(比如,手写文字,或者白背景正中摆放单独物体),其他规整化操作就值得考虑了,而哪种做法最合适也取决于具体应用场合。但对自然图像而言,对每幅图像进行上述的零均值规整化,是默认而合理的处理。
-
【二审】:注:通常我们使用户外拍摄草木等场景的照片,并从中随机截取小图像块(如16x16像素)来训练算法。但实际应用中我们发现,大多数特征学习算法对于训练的图片类型都具有极大的鲁棒性,普通照相机拍摄的图片,只要不是特别的模糊或者有非常奇怪的人工痕迹,都应可以使用。
 
 +
== 参考文献 ==
 +
http://cs229.stanford.edu
-
【原文】:When training on natural images, it makes little sense to estimate a separate mean and
 
-
variance for each pixel, because the statistics in one part
 
-
of the image should (theoretically) be the same as any other. 
 
-
This property of images is called '''stationarity.'''
 
-
【初译】:在自然图片上训练时,对每一个像素估计一个单独的均值和方差意义不大,因为理论上,图像任一部分的统计数据都应该和任意其它部分相同,图像的这种特性被称作平稳性(stationarity)。
+
==中英文对照==
-
【一审】:在自然图片上训练时,对每一个像素估计一个单独的均值和方差意义不大,因为理论上,图像任一部分的统计数据都应该和任意其它部分相同,图像的这种特性被称作平稳性(stationarity)。
+
Principal Components Analysis 主成份分析
-
【二审】:在自然图片上训练时,对每一个像素估计一个单独的均值和方差意义不大,因为(理论上)图像某一部分的统计数据都应该和任意其它部分相同,图像的这种特性被称作平稳性。
+
whitening 白化
 +
intensity 亮度
-
【原文】:In detail, in order for PCA to work well, informally we require that (i) The
+
mean 平均值
-
features have approximately zero mean, and (ii) The different features have
+
-
similar variances to each other.  With natural images, (ii) is already
+
-
satisfied even without variance normalization, and so we won't perform any
+
-
variance normalization. 
+
-
(If you are training on audio data---say, on
+
-
spectrograms---or on text data---say, bag-of-word vectors---we will usually not perform
+
-
variance normalization either.) 
+
-
In fact, PCA is invariant to the scaling of
+
-
the data, and will return the same eigenvectors regardless of the scaling of
+
-
the input.  More formally, if you multiply each feature vector <math>\textstyle x</math> by some
+
-
positive number (thus scaling every feature in every training example by the
+
-
same number), PCA's output eigenvectors will not change. 
+
-
【初译】:具体操作中,为使PCA算法正常工作,我们通常需要满足以下要求:(1) 特征的均值大致为0; (2) 不同的特征的方差相似。对于自然图片,即使不进行方差归一化操作,条件(2)也永远满足,故而我们不进行任何方差归一化操作 (当处理音频文件时,比如声谱,或者文本文件,比如bag-of-word向量,我们通常也不做方差归一化处理)。实际上,PCA算法对于输入数据具有放大(scaling)不变性,无论输入数据的值被如何放大(或缩小),返回的特征值都不改变。下面给出这一说法更规范的描述:如果将每个特征量<math>\textstyle x</math>都乘以同一个正数(即所有特征量被放大或缩小了相同的倍数),PCA的输出特征向量将不会发生变化。
+
variance 方差
-
【一审】:具体操作中,为使PCA算法正常工作,我们通常需要满足以下要求:(1) 特征的均值大致为0; (2) 不同的特征的方差相似。对于自然图片,即使不进行方差归一化操作,条件(2)也永远满足,故而我们不进行任何方差归一化操作 (当处理音频数据时,比如声谱,或者文本数据,比如词袋向量,我们通常也不做方差归一化处理)。实际上,PCA算法对于输入数据具有放大(scaling)不变性,无论输入数据的值被如何放大(或缩小),返回的特征值都不改变。下面给出这一说法更规范的描述:如果将每个特征量<math>\textstyle x</math>都乘以同一个正数(即所有特征量被放大或缩小了相同的倍数),PCA的输出特征向量将不会发生变化。
+
covariance matrix 协方差矩阵
-
【二审】:具体操作中,为使PCA算法正常工作,我们通常需要满足以下要求:(1) 特征的均值大致为0; (2) 不同特征具备相似的方差。对于自然图片,即使不进行方差归一化操作,条件(2)也永远满足,故而我们不进行任何方差归一化操作 (当处理如声谱等音频数据,或如词袋向量等文本数据时,我们通常也不做方差归一化处理)。实际上,PCA算法对输入数据具有缩放不变性,无论输入数据的值被如何放大(或缩小),返回的特征向量都不改变。更规范的说:如果将每个特征向量<math>\textstyle x</math>都乘以同一个正数(即所有特征量被放大或缩小相同的倍数),PCA的输出特征向量将不会发生变化。
+
basis 基
 +
magnitude  幅值
-
【原文】:So, we won't use variance normalization.  The only normalization we need to
+
stationarity 平稳性
-
perform then is mean normalization, to ensure that the features have a mean
+
-
around zero.  Depending on the application, very often we are not interested
+
-
in how bright the overall input image is.  For example, in object recognition
+
-
tasks, the overall brightness of the image doesn't affect what objects
+
-
there are in the image.  More formally, we are not interested in the
+
-
mean intensity value of an image patch; thus, we can subtract out this value,
+
-
as a form of mean normalization.  
+
-
【初译】:既然我们不做方差归一化,唯一还需进行的规范化操作就是均值规范化,其目的是保证所有特征的均值都在0附近。根据不同的应用,很多情况下我们并不关注所输入的图像文件的明亮程度,比如对于物体识别,图像的整体明亮程度并不影响图像中存在的是什么物体。更为规范地说,我们对某一个图像的平均强度值不感兴趣,因此我们可以减去这个值来进行均值规范化(即零均值化)。
+
normalization  归一化
-
【一审】:既然我们不做方差归一化,唯一还需进行的规范化操作就是均值规范化,其目的是保证所有特征的均值都在0附近。根据不同的应用,很多情况下我们并不关注所输入的图像文件的明亮程度,比如对于物体识别,图像的整体明亮程度并不影响图像中存在的是什么物体。更为规范地说,我们对某一个图像的平均强度值不感兴趣,因此我们可以减去这个值来进行均值规范化(即零均值化)。
+
eigenvector  特征向量
-
【二审】:既然我们不做方差归一化,唯一还需进行的规范化操作就是均值规范化,其目的是保证所有特征均值都在0附近。根据不同的应用,很多情况下我们并不关注所输入的图像文件的明亮程度,比如对于物体识别,图像的整体明亮程度并不影响图像中存在的是什么物体。更为规范地说,我们对某一块图像的平均亮度值不感兴趣,因此我们可以减去这个值来进行均值规范化。
+
eigenvalue  特征值
-
【原文】:Concretely, if <math>\textstyle x^{(i)} \in \Re^{n}</math> are the (grayscale) intensity values of
+
==中文译者==
-
a 16x16 image patch (<math>\textstyle n=256</math>), we might normalize the intensity of each image
+
-
<math>\textstyle x^{(i)}</math> as follows:
+
-
<math>\mu^{(i)} := \frac{1}{n} \sum_{j=1}^n x^{(i)}_j</math>
+
郭亮(guoliang2248@gmail.com),张力(emma.lzhang@gmail.com),金峰(jinfengb@gmail.com), @破破的桥(新浪微博), 谭晓阳(x.tan@nuaa.edu.cn)
-
<math>x^{(i)}_j := x^{(i)}_j - \mu^{(i)}</math>, for all <math>\textstyle j</math>
 
-
【初译】:具体的步骤是,如果<math>\textstyle x^{(i)} \in \Re^{n}</math>代表16乘16的图像块的灰度值(<math>\textstyle n=256</math>),我们可以应用如下算法来对每一个图像块<math>\textstyle x^{(i)}</math>的(灰度)强度值进行零均值化操作:
+
{{预处理:主成分分析与白化}}
-
<math>\mu^{(i)} := \frac{1}{n} \sum_{j=1}^n x^{(i)}_j</math>
 
-
<math>x^{(i)}_j := x^{(i)}_j - \mu^{(i)}</math> (对所有的<math>\textstyle j</math>)
+
{{Languages|PCA|English}}
-
 
+
-
【一审】:具体的步骤是,如果<math>\textstyle x^{(i)} \in \Re^{n}</math>代表16乘16的图像块的灰度值(<math>\textstyle n=256</math>),我们可以应用如下算法来对每一个图像块<math>\textstyle x^{(i)}</math>的(灰度)强度值进行零均值化操作:
+
-
 
+
-
<math>\mu^{(i)} := \frac{1}{n} \sum_{j=1}^n x^{(i)}_j</math>
+
-
 
+
-
<math>x^{(i)}_j := x^{(i)}_j - \mu^{(i)}</math> (对所有的<math>\textstyle j</math>)
+
-
 
+
-
 
+
-
【二审】:具体的步骤是,如果<math>\textstyle x^{(i)} \in \Re^{n}</math>代表16x16的图像块的亮度(灰度)值(<math>\textstyle n=256</math>),我们可以应用如下算法来对每一个图像块的亮度值进行零均值化操作:
+
-
 
+
-
<math>\mu^{(i)} := \frac{1}{n} \sum_{j=1}^n x^{(i)}_j</math>
+
-
 
+
-
<math>x^{(i)}_j := x^{(i)}_j - \mu^{(i)}</math> (对所有的<math>\textstyle j</math>)
+
-
 
+
-
 
+
-
【原文】:Note that the two steps above are done separately for each image <math>\textstyle x^{(i)}</math>,
+
-
and that <math>\textstyle \mu^{(i)}</math> here is the mean intensity of the image <math>\textstyle x^{(i)}</math>.  In particular,
+
-
this is not the same thing as estimating a mean value separately for each pixel <math>\textstyle x_j</math>.
+
-
 
+
-
【初译】:请注意上面两个步骤需要单独对每个输入图像块<math>\textstyle x^{(i)}</math>应用,且<math>\textstyle \mu^{(i)}</math>计算的是每个图像块<math>\textstyle x^{(i)}</math>的平均强度值,尤其需要注意的是,这和试图为每一个像素<math>\textstyle x_j</math>单独估算均值是完全不同的概念。
+
-
 
+
-
【一审】:请注意上面两个步骤需要单独对每个输入图像块<math>\textstyle x^{(i)}</math>应用,且<math>\textstyle \mu^{(i)}</math>计算的是每个图像块<math>\textstyle x^{(i)}</math>的平均强度值,尤其需要注意的是,这和试图为每一个像素<math>\textstyle x_j</math>单独估算均值是完全不同的概念。
+
-
 
+
-
【二审】:请注意上面两个步骤需要单独对每个输入图像块<math>\textstyle x^{(i)}</math>应用,且计算的是每个图像块<math>\textstyle x^{(i)}</math>的平均亮度值<math>\textstyle \mu^{(i)}</math>,尤其需要注意的是,这和试图为每一个像素<math>\textstyle x_j</math>单独估算均值是完全不同的概念。
+
-
 
+
-
 
+
-
【原文】:If you are training your algorithm on images other than natural images (for example, images of handwritten characters, or images of single isolated objects centered against a white background), other types of normalization might be worth considering, and the best choice may be application dependent. But when training on natural images, using the per-image mean normalization method as given in the equations above would be a reasonable default.
+
-
 
+
-
【初译】:如果你处理的图像并非自然图像(比如,手写文字,或者白背景正中摆放单独物体),其他规范化操作可能就值得引入,哪种做法最合适也将依赖于具体应用场合,但是对自然图像进行训练时,使用如上所述的整个图像块范围内的均值规范化操作可以放心假定为合理的办法。
+
-
 
+
-
【一审】:如果你处理的图像并非自然图像(比如,手写文字,或者白背景正中摆放单独物体),其他规范化操作可能就值得考虑了,哪种做法最合适也将依赖于具体应用场合,但是对自然图像进行训练时,使用如上所述的整个图像块范围内的均值规范化操作可以放心假定为合理的办法。
+
-
 
+
-
【二审】:如果你处理的图像并非自然图像(比如,手写文字,或者白背景正中摆放单独物体),其他规范化操作可能就值得考虑了,哪种做法最合适也将依赖于具体应用场合,但是对自然图像进行训练时,使用如上所述的整个图像块范围内的均值规范化操作可以放心假定为合理的办法。
+
-
 
+
-
 
+
-
== References 参考文献 ==
+
-
http://cs229.stanford.edu
+

Latest revision as of 05:04, 8 April 2013

Personal tools