def ppca(Y, Q, iterations=<NUM_LIT:100>):
from numpy.ma import dot as madot<EOL>N, D = Y.shape<EOL>W = np.random.randn(D, Q) * <NUM_LIT><EOL>Y = np.ma.masked_invalid(Y, copy=<NUM_LIT:0>)<EOL>mu = Y.mean(<NUM_LIT:0>)<EOL>Ycentered = Y - mu<EOL>try:<EOL><INDENT>for _ in range(iterations):<EOL><INDENT>exp_x = np.asarray_chkfinite(np.linalg.solve(W.T.dot(W), madot(W.T, Ycentered.T))).T<EOL>W = np.asarray_chkfinite(np.linalg.solve(exp_x.T.dot(exp_x), madot(exp_x.T, Ycentered))).T<EOL><DEDENT><DEDENT>except np.linalg.linalg.LinAlgError:<EOL><INDENT>pass<EOL><DEDENT>return np.asarray_chkfinite(exp_x), np.asarray_chkfinite(W)<EOL>
EM implementation for probabilistic pca.

:param array-like Y: Observed Data
:param int Q: Dimensionality for reduced array
:param int iterations: number of iterations for EM