annotate algorithms/tests/test_daa.py @ 500:3c60c2db0319

Added new daa test
author Joseph Turian <turian@gmail.com>
date Tue, 28 Oct 2008 13:36:27 -0400
parents 32509c479e2d
children 4fb6f7320518
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
500
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
8 import pylearn.algorithms.logistic_regression
493
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
9
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
10 def test_train_daa(mode = theano.Mode('c|py', 'fast_run')):
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
11
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
12 ndaa = 3
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
13 daa = models.Stacker([(models.SigmoidXEDenoisingAA, 'hidden')] * ndaa + [(models.BinRegressor, 'output')],
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
14 regularize = False)
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
15
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
16 model = daa.make([4, 20, 20, 20, 1],
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
17 lr = 0.01,
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
18 mode = mode,
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
19 seed = 10)
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
20
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
21 model.layers[0].noise_level = 0.3
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
22 model.layers[1].noise_level = 0.3
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
23 model.layers[2].noise_level = 0.3
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
24
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
25 # Update the first hidden layer
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
26 model.local_update[0]([[0, 1, 0, 1]])
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
27 model.local_update[1]([[0, 1, 0, 1]])
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
28 model.local_update[2]([[0, 1, 0, 1]])
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
29
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
30 model.update([[0, 1, 0, 1]], [[0]])
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
31 print model.classify([[0, 1, 0, 1]])
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
500
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
34 def test_train_daa2(mode = theano.Mode('c|py', 'fast_run')):
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
35
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
36 ndaa = 3
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
37 daa = models.Stacker([(models.SigmoidXEDenoisingAA, 'hidden')] * ndaa + [(pylearn.algorithms.logistic_regression.Module_Nclass, 'output')],
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
38 regularize = False)
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
39
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
40 model = daa.make([4, 20, 20, 20, 1],
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
41 lr = 0.01,
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
42 mode = mode,
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
43 seed = 10)
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
44
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
45 model.layers[0].noise_level = 0.3
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
46 model.layers[1].noise_level = 0.3
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
47 model.layers[2].noise_level = 0.3
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
48
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
49 # Update the first hidden layer
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
50 model.local_update[0]([[0, 1, 0, 1]])
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
51 model.local_update[1]([[0, 1, 0, 1]])
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
52 model.local_update[2]([[0, 1, 0, 1]])
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
53
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
54 model.update([[0, 1, 0, 1]], [0])
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
55 print model.classify([[0, 1, 0, 1]])
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
56
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
57
493
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
58
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
59
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
60
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
61 if __name__ == '__main__':
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
62 # print 'optimized:'
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
63 # t1 = test_train_daa(theano.Mode('py', 'fast_compile'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
64 # t1 = test_train_daa(theano.Mode('c|py', 'fast_run'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
65 # print 'time:',t1
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
66 # print
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
67
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
68 # print 'not optimized:'
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
69 # t2 = test_train_daa(theano.Mode('c|py', 'fast_compile'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
70 ## print 'time:',t2
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
71
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
72 # test_train_daa(theano.compile.Mode('c&py', 'merge'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
73 test_train_daa(theano.compile.Mode('c|py', 'merge'))
500
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
74 test_train_daa2(theano.compile.Mode('c|py', 'merge'))