From aeb37cf4cd2a4cd9d08209b497baf923df6f0c60 Mon Sep 17 00:00:00 2001 From: flatberg Date: Thu, 25 Jan 2007 12:17:16 +0000 Subject: [PATCH] Added supportp for tall X in PCA --- fluents/lib/engines.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fluents/lib/engines.py b/fluents/lib/engines.py index fc3e002..821dc2b 100644 --- a/fluents/lib/engines.py +++ b/fluents/lib/engines.py @@ -17,8 +17,16 @@ def pca(a, aopt, scale='scores', mode='normal'): """ m, n = a.shape - u, s, vt = svd(a, full_matrices=0) - eigvals = (1./m)*s + + if m*10.>n: + v, s, ut = dot(a.T, a) + s = sqrt(s) + eigvals = s + u = u.T + vt = v.T + else: + u, s, vt = svd(a, full_matrices=0) + eigvals = (1./m)*s T = u*s T = T[:,:aopt] P = vt[:aopt,:].T