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