def compute_svd_normalization(samples, Ndiscard, max_rescale):
# S is list of singular values in descending order
# Each row of V is a list of the weights of the features in a given principal component
centered_samples = samples - samples.mean(axis=0) # subtract columnwise means
U, S, V = np.linalg.svd(centered_samples, full_matrices=False)
Nsamp = samples.shape[0]
component_stddevs = S / math.sqrt(Nsamp)
print "singular values ="
print S
print "component standard deviations ="
print component_stddevs
print "V matrix ="
print V
Nfeat = samples.shape[1]
rescaling_factors = np.minimum(np.reciprocal(component_stddevs[:Nfeat-Ndiscard]), max_rescale)
whitening_matrix = np.dot(V[:Nfeat-Ndiscard].T, np.diag(rescaling_factors))
print "Ndiscard =", Ndiscard
print "max_rescale =", max_rescale
print "rescaling_factors ="
print rescaling_factors
print "whitening_matrix ="
print repr(whitening_matrix)
评论列表
文章目录