lines that call matplotlib were commented

This commit is contained in:
Ricardo 2014-01-28 13:43:33 +00:00
parent bb0e2a6237
commit 064a57f851

View file

@ -279,14 +279,14 @@ def ppca(Y, Q, iterations=100):
def ppca_missing_data_at_random(Y, Q, iters=100): def ppca_missing_data_at_random(Y, Q, iters=100):
""" """
EM implementation of Probabilistic pca for when there is missing data. EM implementation of Probabilistic pca for when there is missing data.
Taken from <SheffieldML, https://github.com/SheffieldML> Taken from <SheffieldML, https://github.com/SheffieldML>
.. math: .. math:
\\mathbf{Y} = \mathbf{XW} + \\epsilon \\text{, where} \\mathbf{Y} = \mathbf{XW} + \\epsilon \\text{, where}
\\epsilon = \\mathcal{N}(0, \\sigma^2 \mathbf{I}) \\epsilon = \\mathcal{N}(0, \\sigma^2 \mathbf{I})
:returns: X, W, sigma^2 :returns: X, W, sigma^2
""" """
from numpy.ma import dot as madot from numpy.ma import dot as madot
import diag import diag
@ -300,19 +300,21 @@ def ppca_missing_data_at_random(Y, Q, iters=100):
nu = 1. nu = 1.
#num_obs_i = 1./Y.count() #num_obs_i = 1./Y.count()
Ycentered = Y - Y.mean(0) Ycentered = Y - Y.mean(0)
X = np.zeros((N,Q)) X = np.zeros((N,Q))
cs = common_subarrays(Y.mask) cs = common_subarrays(Y.mask)
cr = common_subarrays(Y.mask, 1) cr = common_subarrays(Y.mask, 1)
Sigma = np.zeros((N, Q, Q)) Sigma = np.zeros((N, Q, Q))
Sigma2 = np.zeros((N, Q, Q)) Sigma2 = np.zeros((N, Q, Q))
mu = np.zeros(D) mu = np.zeros(D)
"""
if debug: if debug:
import matplotlib.pyplot as pylab import matplotlib.pyplot as pylab
fig = pylab.figure("FIT MISSING DATA"); fig = pylab.figure("FIT MISSING DATA");
ax = fig.gca() ax = fig.gca()
ax.cla() ax.cla()
lines = pylab.plot(np.zeros((N,Q)).dot(W)) lines = pylab.plot(np.zeros((N,Q)).dot(W))
"""
W2 = np.zeros((Q,D)) W2 = np.zeros((Q,D))
for i in range(iters): for i in range(iters):
@ -358,6 +360,7 @@ def ppca_missing_data_at_random(Y, Q, iters=100):
nu2 /= N nu2 /= N
nu4 = (((Ycentered - X.dot(W))**2).sum(0) + W.T.dot(Sigma.sum(0).dot(W)).sum(0)).sum()/N nu4 = (((Ycentered - X.dot(W))**2).sum(0) + W.T.dot(Sigma.sum(0).dot(W)).sum(0)).sum()/N
import ipdb;ipdb.set_trace() import ipdb;ipdb.set_trace()
"""
if debug: if debug:
#print Sigma[0] #print Sigma[0]
print "nu:", nu, "sum(X):", X.sum() print "nu:", nu, "sum(X):", X.sum()
@ -368,6 +371,7 @@ def ppca_missing_data_at_random(Y, Q, iters=100):
ax.set_ylim(pred_y.min(), pred_y.max()) ax.set_ylim(pred_y.min(), pred_y.max())
fig.canvas.draw() fig.canvas.draw()
time.sleep(.3) time.sleep(.3)
"""
return np.asarray_chkfinite(X), np.asarray_chkfinite(W), nu return np.asarray_chkfinite(X), np.asarray_chkfinite(W), nu