Corrected the PCA implementation
@@ -201,8 +201,6 @@ def PCA_reduce(X, Q):
:return: PCA projection array of size N x Q.
"""
assert Q <= X.shape[1], 'Cannot have more latent dimensions than observed'
- evecs, evals = np.linalg.eigh(np.cov(X.T))
- i = np.argsort(evecs)[::-1]
- W = evals[:, i]
- W = W[:, :Q]
+ evals, evecs = np.linalg.eigh(np.cov(X.T))
+ W = evecs[:, -Q:]
return (X - X.mean(0)).dot(W)
