493
|
1 #!/usr/bin/python
|
|
2
|
|
3 from pylearn import algorithms as models
|
|
4 import theano
|
|
5 import numpy
|
|
6 import time
|
|
7
|
500
|
8 import pylearn.algorithms.logistic_regression
|
493
|
9
|
|
10 def test_train_daa(mode = theano.Mode('c|py', 'fast_run')):
|
|
11
|
|
12 ndaa = 3
|
|
13 daa = models.Stacker([(models.SigmoidXEDenoisingAA, 'hidden')] * ndaa + [(models.BinRegressor, 'output')],
|
|
14 regularize = False)
|
|
15
|
|
16 model = daa.make([4, 20, 20, 20, 1],
|
|
17 lr = 0.01,
|
|
18 mode = mode,
|
|
19 seed = 10)
|
|
20
|
|
21 model.layers[0].noise_level = 0.3
|
|
22 model.layers[1].noise_level = 0.3
|
|
23 model.layers[2].noise_level = 0.3
|
|
24
|
|
25 # Update the first hidden layer
|
|
26 model.local_update[0]([[0, 1, 0, 1]])
|
|
27 model.local_update[1]([[0, 1, 0, 1]])
|
|
28 model.local_update[2]([[0, 1, 0, 1]])
|
|
29
|
|
30 model.update([[0, 1, 0, 1]], [[0]])
|
|
31 print model.classify([[0, 1, 0, 1]])
|
|
32
|
|
33
|
500
|
34 def test_train_daa2(mode = theano.Mode('c|py', 'fast_run')):
|
|
35
|
|
36 ndaa = 3
|
|
37 daa = models.Stacker([(models.SigmoidXEDenoisingAA, 'hidden')] * ndaa + [(pylearn.algorithms.logistic_regression.Module_Nclass, 'output')],
|
|
38 regularize = False)
|
|
39
|
|
40 model = daa.make([4, 20, 20, 20, 1],
|
|
41 lr = 0.01,
|
|
42 mode = mode,
|
|
43 seed = 10)
|
|
44
|
|
45 model.layers[0].noise_level = 0.3
|
|
46 model.layers[1].noise_level = 0.3
|
|
47 model.layers[2].noise_level = 0.3
|
|
48
|
|
49 # Update the first hidden layer
|
|
50 model.local_update[0]([[0, 1, 0, 1]])
|
|
51 model.local_update[1]([[0, 1, 0, 1]])
|
|
52 model.local_update[2]([[0, 1, 0, 1]])
|
|
53
|
|
54 model.update([[0, 1, 0, 1]], [0])
|
|
55 print model.classify([[0, 1, 0, 1]])
|
|
56
|
|
57
|
493
|
58
|
|
59
|
|
60
|
|
61 if __name__ == '__main__':
|
|
62 # print 'optimized:'
|
|
63 # t1 = test_train_daa(theano.Mode('py', 'fast_compile'))
|
|
64 # t1 = test_train_daa(theano.Mode('c|py', 'fast_run'))
|
|
65 # print 'time:',t1
|
|
66 # print
|
|
67
|
|
68 # print 'not optimized:'
|
|
69 # t2 = test_train_daa(theano.Mode('c|py', 'fast_compile'))
|
|
70 ## print 'time:',t2
|
|
71
|
|
72 # test_train_daa(theano.compile.Mode('c&py', 'merge'))
|
|
73 test_train_daa(theano.compile.Mode('c|py', 'merge'))
|
500
|
74 test_train_daa2(theano.compile.Mode('c|py', 'merge'))
|