白化变换不会返回单位协方差矩阵

时间:2019-06-18 17:20:15

标签: python math linear-algebra svd

对于这个问题,我使用以下Wiki definition of Matrix whitening

enter image description here

根据定义,我期望Y的协方差矩阵为恒等矩阵。但是,这远非事实!

这是复制品:

import numpy as np
# random matrix
dim1 = 512 # dimentionality_of_features
dim2 = 100 # no_of_samples

X = np.random.rand(dim1, dim2)
# centering to have mean 0
X = X - np.mean(X, axis=1, keepdims=True)

# covariance of X
Xcov = np.dot(X, X.T) / (X.shape[1] - 1)

# SVD decomposition
# Eigenvecors and eigenvalues
Ec, wc, _ = np.linalg.svd(Xcov)
# get only the first positive ones (for numerical stability)
k_c = (wc > 1e-5).sum()
# Diagonal Matrix of eigenvalues
Dc = np.diag((wc[:k_c]+1e-6)**-0.5)
# E D ET should be the whitening matrix
W = Ec[:,:k_c].dot(Dc).dot(Ec[:,:k_c].T)

# SVD decomposition End




Y = W.dot(X)
# Now apply the same to the whitened X
Ycov = np.dot(Y, Y.T) / (Y.shape[1] - 1)
print(Ycov)

>> [[ 0.19935189 -0.00740203 -0.00152036 ...  0.00133161 -0.03035149
      0.02638468]  ...

除非dim2 >> dim1,否则似乎不会给我单位对角矩阵。

如果我使用dim2=1,那么我会得到一个向量(尽管在示例中由于除以0而导致错误),并且按照Wiki的定义,这是不正确的吗?

0 个答案:

没有答案