对于这个问题,我使用以下Wiki 定义的 Matrix whitening:
认为是具有非奇异协方差矩阵的随机(列)向量并且均值为 0。那么变换带有美白矩阵 满足条件产生白化的随机向量具有单位对角协方差。
根据定义,我期望协方差矩阵为单位矩阵。然而,这远非事实!
这是复制品:
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 的定义,这是不正确的吗?