ZCA python实现

版权声明:任意转载 https://blog.csdn.net/Z609834342/article/details/84747989
def ZCA(data, reg=1e-6):
    mean = np.mean(data, axis=0)
    mdata = data - mean
    sigma = np.dot(mdata.T, mdata) / mdata.shape[0]
    U, S, V = linalg.svd(sigma)
    components = np.dot(np.dot(U, np.diag(1 / np.sqrt(S) + reg)), U.T)
    whiten = np.dot(data - mean, components.T)
    return components, mean, whiten

components, mean, x = ZCA(x)
y = np.dot(y - mean, components.T)

这里输入的x和y是向量,即如果是一张图要转为向量形式表示。

猜你喜欢

转载自blog.csdn.net/Z609834342/article/details/84747989