PCA Module¶
-
pca.
flatten_feature_vectors
(data, dim=0)[source]¶ Flattens the feature vectors inside a ndarray
- Example:
input: [
[[1, 2], [3, 4], [5, 6]], ... [[1, 2], [3, 4], [5, 6]]] output: [
[1, 2, 3, 4, 5, 6], ... [1, 2, 3, 4, 5, 6]]
- Args:
- data (numpy array): array of feature vectors dim (int): dimension to flatten the data
- return:
- array: (numpy array): array flattened feature vectors
-
pca.
load
(filename)[source]¶ - The model stored by pca.store (see
pca.store
method above) is loaded as: UsVtm = np.load(args.model_file)
Vt = Vtm[0] mean_values = Vtm[1][0]
- Returns:
(tuple): Vt, mean_values
Vt (numpy ndarray): Two dimensional array with dimensions (n_features, n_features) mean_values (numpy ndarray): mean values of the features of the model, this should have dimensions (n_featurs, )
- The model stored by pca.store (see
-
pca.
pca
(data, mean_values, variance_percentage=90)[source]¶ Perform Singlar Value Decomposition
- Returns:
- U (ndarray): U matrix s (ndarray): 1d singular values (diagonal in array form) Vt (ndarray): Vt matrix
-
pca.
reconstruct
(feature_vector, Vt, mean_values, n_components=None)[source]¶ Reconstruct with U, s, Vt
- Args:
- U (numpy ndarray): One feature vector from the reduced SVD.
- U should have shape (n_features,), (i.e., one dimensional)
s (numpy ndarray): The singular values as a one dimensional array Vt (numpy ndarray): Two dimensional array with dimensions (n_features, n_features) mean_values (numpy ndarray): mean values of the features of the model, this should have dimensions (n_features, )
-
pca.
save
(Vt, s, n_components, mean_values, triangles, filename)[source]¶ Store the U, s, Vt and mean of all the asf datafiles given by the asf files.
- It is stored in the following way:
- np.load(filename, np.assary([Vt, [mean_values]])
- And accessed by:
Vtm = np.load(args.model_file)
Vt = Vtm[0] mean_values = Vtm[1][0] triangles = Vtm[2]