annotate algorithms/tests/test_daa.py @ 493:32509c479e2d

Added test_daa.py
author Joseph Turian <turian@gmail.com>
date Tue, 28 Oct 2008 11:40:31 -0400
parents
children 3c60c2db0319
rev   line source
493
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
2
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
3 from pylearn import algorithms as models
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
4 import theano
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
5 import numpy
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
6 import time
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
7
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
8
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
9 def test_train_daa(mode = theano.Mode('c|py', 'fast_run')):
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
10
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
11 ndaa = 3
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
12 daa = models.Stacker([(models.SigmoidXEDenoisingAA, 'hidden')] * ndaa + [(models.BinRegressor, 'output')],
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
13 regularize = False)
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
14
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
15 model = daa.make([4, 20, 20, 20, 1],
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
16 lr = 0.01,
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
17 mode = mode,
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
18 seed = 10)
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
19
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
20 model.layers[0].noise_level = 0.3
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
21 model.layers[1].noise_level = 0.3
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
22 model.layers[2].noise_level = 0.3
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
23
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
24 # Update the first hidden layer
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
25 model.local_update[0]([[0, 1, 0, 1]])
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
26 model.local_update[1]([[0, 1, 0, 1]])
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
27 model.local_update[2]([[0, 1, 0, 1]])
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
28
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
29 model.update([[0, 1, 0, 1]], [[0]])
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
30 print model.classify([[0, 1, 0, 1]])
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
31
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
32
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
33
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
34
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
35
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
36 if __name__ == '__main__':
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
37 # print 'optimized:'
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
38 # t1 = test_train_daa(theano.Mode('py', 'fast_compile'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
39 # t1 = test_train_daa(theano.Mode('c|py', 'fast_run'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
40 # print 'time:',t1
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
41 # print
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
42
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
43 # print 'not optimized:'
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
44 # t2 = test_train_daa(theano.Mode('c|py', 'fast_compile'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
45 ## print 'time:',t2
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
46
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
47 # test_train_daa(theano.compile.Mode('c&py', 'merge'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
48 test_train_daa(theano.compile.Mode('c|py', 'merge'))