print " number of components to retain: %d" % num_components P = eigv.astype('float32') * np.sqrt(1.0/(eigs + bias)) # PCA whitening P = P[:, -num_components:] # truncate transformation matrix tock() # kmeans print "Learn kmeans" k = settings['num_means'] print " whiten patches" patches_subset_whitened = np.dot(patches_subset_centered, P) print " run kmeans" centroids = kmeans.spherical_kmeans(patches_subset_whitened, k, num_iterations=20, batch_size=10000) tock() # feature extraction and summarisation print "Feature extraction and summarisation" threshold = settings['threshold'] PC = np.dot(P, centroids.T) # def summarise_features(features): # features = features.reshape(features.shape[0], -1, features.shape[3]) # merge time and frequency axes # return np.hstack([features.mean(1), features.std(1), features.min(1), features.max(1)]) # summarize over time axis # # return features.mean(1) # # return features.max(1)
print(" number of components to retain: %d" % num_components) P = eigv.astype('float32') * np.sqrt(1.0 / (eigs + bias)) # PCA whitening P = P[:, -num_components:] # truncate transformation matrix tock() # kmeans print("Learn kmeans") k = settings['num_means'] print(" whiten patches") patches_subset_whitened = np.dot(patches_subset_centered, P) print(" run kmeans") centroids = kmeans.spherical_kmeans(patches_subset_whitened, k, num_iterations=20, batch_size=10000) tock() # feature extraction and summarisation print("Feature extraction and summarisation") threshold = settings['threshold'] PC = np.dot(P, centroids.T) # def summarise_features(features): # features = features.reshape(features.shape[0], -1, features.shape[3]) # merge time and frequency axes # return np.hstack([features.mean(1), features.std(1), features.min(1), features.max(1)]) # summarize over time axis # # return features.mean(1) # # return features.max(1)