Commit a54d0723 authored by Richard Torenvliet's avatar Richard Torenvliet

Perform pca

parent c6bdbd9b
...@@ -62,8 +62,9 @@ if __name__ == '__main__': ...@@ -62,8 +62,9 @@ if __name__ == '__main__':
imm_points.append(imm.get_points()) imm_points.append(imm.get_points())
# imm.show() # imm.show()
imm_points = np.array(imm_points)
mean_values = build_mean_aam(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 # show immpoints
imm = IMMPoints(points=mean_values) imm = IMMPoints(points=mean_values)
......
def pca(data, mean_values): import numpy as np
print mean_values
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]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment