Mercurial > pylearn
annotate algorithms/tests/test_daa.py @ 519:b267a8000f92
Added theano.Member to Member variables which were passed in during initialization.
author | Joseph Turian <turian@iro.umontreal.ca> |
---|---|
date | Fri, 14 Nov 2008 02:07:20 -0500 |
parents | 4fb6f7320518 |
children | de974b4fc4ea |
rev | line source |
---|---|
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 | |
501
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
26 for l in range(3): |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
27 for i in range(10): |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
28 model.local_update[l]([[0, 1, 0, 1]]) |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
29 model.local_update[l]([[1, 0, 1, 0]]) |
493 | 30 |
501
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
31 for i in range(1): |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
32 model.update([[0, 1, 0, 1]], [[1]]) |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
33 model.update([[1, 0, 1, 0]], [[0]]) |
493 | 34 print model.classify([[0, 1, 0, 1]]) |
501
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
35 print model.classify([[1, 0, 1, 0]]) |
493 | 36 |
37 | |
500 | 38 def test_train_daa2(mode = theano.Mode('c|py', 'fast_run')): |
39 | |
40 ndaa = 3 | |
501
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
41 daa = models.Stacker([(models.SigmoidXEDenoisingAA, 'hidden')] * ndaa + [(pylearn.algorithms.logistic_regression.Module_Nclass, 'pred')], |
500 | 42 regularize = False) |
43 | |
501
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
44 model = daa.make([4, 20, 20, 20, 10], |
500 | 45 lr = 0.01, |
46 mode = mode, | |
47 seed = 10) | |
48 | |
49 model.layers[0].noise_level = 0.3 | |
50 model.layers[1].noise_level = 0.3 | |
51 model.layers[2].noise_level = 0.3 | |
52 | |
501
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
53 for l in range(3): |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
54 for i in range(10): |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
55 model.local_update[l]([[0, 1, 0, 1]]) |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
56 model.local_update[l]([[1, 0, 1, 0]]) |
500 | 57 |
501
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
58 for i in range(1): |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
59 model.update([[0, 1, 0, 1]], [1]) |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
60 model.update([[1, 0, 1, 0]], [0]) |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
61 print model.apply([[0, 1, 0, 1]]) |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
62 print model.apply([[1, 0, 1, 0]]) |
500 | 63 |
493 | 64 |
65 | |
66 | |
67 if __name__ == '__main__': | |
68 # print 'optimized:' | |
69 # t1 = test_train_daa(theano.Mode('py', 'fast_compile')) | |
70 # t1 = test_train_daa(theano.Mode('c|py', 'fast_run')) | |
71 # print 'time:',t1 | |
72 # print | |
73 | |
74 # print 'not optimized:' | |
75 # t2 = test_train_daa(theano.Mode('c|py', 'fast_compile')) | |
76 ## print 'time:',t2 | |
77 | |
78 # test_train_daa(theano.compile.Mode('c&py', 'merge')) | |
501
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
79 # test_train_daa(theano.compile.Mode('c|py', 'merge')) |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
80 test_train_daa(theano.compile.Mode('py', 'merge')) |
4fb6f7320518
N-class logistic regression top-layer works
Joseph Turian <turian@gmail.com>
parents:
500
diff
changeset
|
81 |
500 | 82 test_train_daa2(theano.compile.Mode('c|py', 'merge')) |