changeset 1421:3dee72c3055d

added some old test_pca file I never committed
author James Bergstra <bergstrj@iro.umontreal.ca>
date Fri, 04 Feb 2011 16:06:36 -0500
parents 7374d676c9b0
children 8c209c847087
files pylearn/preprocessing/tests/test_pca.py
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylearn/preprocessing/tests/test_pca.py	Fri Feb 04 16:06:36 2011 -0500
@@ -0,0 +1,23 @@
+import numpy
+from pylearn.preprocessing.pca import *
+
+def test_max_energy_fraction():
+    rng = numpy.random.RandomState(234)
+    a = rng.randn(10,5)
+    a[:,0] *=2
+    a+= 5
+    (eigvals, eigvecs), centered_a = pca_from_examples(a)
+    assert len(eigvals)==5
+    vartot = eigvals.sum()
+
+    def f(frac, n):
+        (evals, evecs), c_a = pca_from_examples(a, max_energy_fraction=frac)
+        assert len(evals)==n
+        assert evals.sum() <= (frac * vartot + 1e-8)
+
+    f(.87,1)
+    f(.88,2)
+    f(.99999999, 4)
+    f(1.0, 5)
+    f(.5, 0)
+