matlab 矩阵白化,主成分分析中如何对矩阵进行白化处理

这是我从here得到的矩阵白化的一些Matlab代码的numpy实现。import numpy as np

def whiten(X,fudge=1E-18):

# the matrix X should be observations-by-components

# get the covariance matrix

Xcov = np.dot(X.T,X)

# eigenvalue decomposition of the covariance matrix

d, V = np.linalg.eigh(Xcov)

# a fudge factor can be used so that eigenvectors associated with

# small eigenvalues do not get overamplified.

D = np.diag(1. / np.sqrt(d+fudge))

# whitening matrix

W = np.dot(np.dot(V, D), V.T)

# multiply by the whitening matrix

X_white = np.dot(X, W)

return X_white, W

也可以使用SVD对矩阵进行白化:def svd_whiten(X):

U, s, Vt = np.linalg.svd(X, full_matrices=False)

# U and Vt are the singular matrices, and s contains the singular values.

# Since the rows of both U and Vt are orthonormal vectors, then U * Vt

# will be white

X_white = np.dot(U, Vt)

return X_white

第二种方法比较慢,但数值上可能更稳定。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值