Mercurial > pylearn
annotate pylearn/preprocessing/tests/test_pca.py @ 1484:83d3c9ee6d65
* changed MNIST dataset to use config.get_filepath_in_roots mechanism
author | gdesjardins |
---|---|
date | Tue, 05 Jul 2011 11:01:51 -0400 |
parents | 3dee72c3055d |
children |
rev | line source |
---|---|
1421
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
1 import numpy |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
2 from pylearn.preprocessing.pca import * |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
3 |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
4 def test_max_energy_fraction(): |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
5 rng = numpy.random.RandomState(234) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
6 a = rng.randn(10,5) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
7 a[:,0] *=2 |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
8 a+= 5 |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
9 (eigvals, eigvecs), centered_a = pca_from_examples(a) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
10 assert len(eigvals)==5 |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
11 vartot = eigvals.sum() |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
12 |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
13 def f(frac, n): |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
14 (evals, evecs), c_a = pca_from_examples(a, max_energy_fraction=frac) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
15 assert len(evals)==n |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
16 assert evals.sum() <= (frac * vartot + 1e-8) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
17 |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
18 f(.87,1) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
19 f(.88,2) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
20 f(.99999999, 4) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
21 f(1.0, 5) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
22 f(.5, 0) |
3dee72c3055d
added some old test_pca file I never committed
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
23 |