def pca(Y, input_dim):
if not np.allclose(Y.mean(axis=<NUM_LIT:0>), <NUM_LIT:0.0>):<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>Z = linalg.svd(Y - Y.mean(axis=<NUM_LIT:0>), full_matrices=False)<EOL>[X, W] = [Z[<NUM_LIT:0>][:, <NUM_LIT:0>:input_dim], np.dot(np.diag(Z[<NUM_LIT:1>]), Z[<NUM_LIT:2>]).T[:, <NUM_LIT:0>:input_dim]]<EOL>v = X.std(axis=<NUM_LIT:0>)<EOL>X /= v<EOL>W *= v<EOL>return X, W.T<EOL>
Principal component analysis: maximum likelihood solution by SVD

:param Y: NxD np.array of data
:param input_dim: int, dimension of projection


:rval X: - Nxinput_dim np.array of dimensionality reduced data
:rval W: - input_dimxD mapping from X to Y