PCA 来回均值 subtraction/addition
PCA forth and back mean subtraction/addition
底线问题:当我使用计算出的 PCA 投影矩阵 P 进行投影时一个向量 v 到另一个 space (可能在尺寸方面更低),我应该先 subtract 来自 v 用于创建其主要特征向量形成投影矩阵的协方差矩阵的向量的平均值 P ?
又一个衍生题:如果上题的答案是"correct",那么当我把一个"reduced"向量投影回原来的space,我最后应该加上吗?
现在详细的问题,包括可能引起混淆的步骤:
PCA 流程如下:
取m向量长度d 并计算它们的协方差矩阵。由于(i,j)位置的元素是i[=111的协方差=]的第j'th dimension along all the m vectors, we can get the target (dxd) sized covariance matrix by subtracting the mean from all the vectors, creating a matrix A of size (dxm), in which all the mean-subtracted vectors are placed as column vectors and computing the multiplication: C = AA'.
计算d特征值和特征向量C,对于一些预选的k,创建矩阵 P 大小 (kxd),并放置 k个最大特征值对应的特征向量按降序排列,作为P.[=11的行向量=]
对于原始维度d[的任意向量v =111=],我们想要投影到可能减少的维度 k,我们计算乘法:u = Pv,它产生一个可能降维的向量k.
对于任何向量u已经投影到可能减少的维度k,如果我们想把它投影回(在可能丢失数据之后)到原来的维度d,我们计算乘法:v = P'u,它产生一个原始维度的向量d.
问题是:
- 在步骤(3)中,我们应该首先从v中减去我们的均值在步骤 (1)?
中计算
- 在步骤 (4) 中,我们最终应该添加到 v 我们的均值在步骤 (1)?
中计算
- in step (3), we should first subtract from v the mean we computed in step (1)?
- in step (4), we should finally add to v the mean we computed in step (1)?
是的,是的。
另请注意,如有必要,您可以一次性计算样本的协方差矩阵,方法是:
COV = E[vv'] - E[v]E[v]'
在一些教程中找到了答案。在这里分享,让任何人都可以享受...
根据 this very nice and friendly PCA tutorial, the mean should indeed be subtracted in (3) and added in (4). It also appears to be described in the same way in the very famous and classic eigenfaces 论文。
以下是 PCA 教程中的一些截图,很有意义:
投影到新 space:
投影回原始 space:
底线问题:当我使用计算出的 PCA 投影矩阵 P 进行投影时一个向量 v 到另一个 space (可能在尺寸方面更低),我应该先 subtract 来自 v 用于创建其主要特征向量形成投影矩阵的协方差矩阵的向量的平均值 P ?
又一个衍生题:如果上题的答案是"correct",那么当我把一个"reduced"向量投影回原来的space,我最后应该加上吗?
现在详细的问题,包括可能引起混淆的步骤:
PCA 流程如下:
取m向量长度d 并计算它们的协方差矩阵。由于(i,j)位置的元素是i[=111的协方差=]的第j'th dimension along all the m vectors, we can get the target (dxd) sized covariance matrix by subtracting the mean from all the vectors, creating a matrix A of size (dxm), in which all the mean-subtracted vectors are placed as column vectors and computing the multiplication: C = AA'.
计算d特征值和特征向量C,对于一些预选的k,创建矩阵 P 大小 (kxd),并放置 k个最大特征值对应的特征向量按降序排列,作为P.[=11的行向量=]
对于原始维度d[的任意向量v =111=],我们想要投影到可能减少的维度 k,我们计算乘法:u = Pv,它产生一个可能降维的向量k.
对于任何向量u已经投影到可能减少的维度k,如果我们想把它投影回(在可能丢失数据之后)到原来的维度d,我们计算乘法:v = P'u,它产生一个原始维度的向量d.
问题是:
- 在步骤(3)中,我们应该首先从v中减去我们的均值在步骤 (1)? 中计算
- 在步骤 (4) 中,我们最终应该添加到 v 我们的均值在步骤 (1)? 中计算
- in step (3), we should first subtract from v the mean we computed in step (1)?
- in step (4), we should finally add to v the mean we computed in step (1)?
是的,是的。
另请注意,如有必要,您可以一次性计算样本的协方差矩阵,方法是:
COV = E[vv'] - E[v]E[v]'
在一些教程中找到了答案。在这里分享,让任何人都可以享受...
根据 this very nice and friendly PCA tutorial, the mean should indeed be subtracted in (3) and added in (4). It also appears to be described in the same way in the very famous and classic eigenfaces 论文。
以下是 PCA 教程中的一些截图,很有意义:
投影到新 space:
投影回原始 space: