Skip to content
Snippets Groups Projects
Commit a54d0723 authored by Richard Torenvliet's avatar Richard Torenvliet
Browse files

Perform pca

parent c6bdbd9b
No related branches found
No related tags found
No related merge requests found
......@@ -62,8 +62,9 @@ if __name__ == '__main__':
imm_points.append(imm.get_points())
# imm.show()
imm_points = np.array(imm_points)
mean_values = build_mean_aam(np.array(imm_points))
pca(imm_points, mean_values)
V, S = pca(imm_points, mean_values)
# show immpoints
imm = IMMPoints(points=mean_values)
......
def pca(data, mean_values):
print mean_values
import numpy as np
def preprocess(data):
flattened = []
y, x, dim = data.shape
for i in range(y):
flattened.append(np.ndarray.flatten(data[i]))
return np.array(flattened)
def pca(data, mean_values, n_components):
# subtract mean
zero_mean = data - mean_values
X = preprocess(zero_mean)
observations, dims = X.shape
U, S, V = np.linalg.svd(X)
return V[:n_components], S[:n_components]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment