annotate algorithms/tests/test_daa.py @ 532:34ee3aff3e8f

Improved embedding word preprocessing.
author Joseph Turian <turian@gmail.com>
date Tue, 18 Nov 2008 02:57:50 -0500
parents 4fb6f7320518
children de974b4fc4ea
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
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
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
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
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
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
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
36
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
37
500
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
38 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
39
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
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
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
42 regularize = False)
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
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
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
45 lr = 0.01,
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
46 mode = mode,
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
47 seed = 10)
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 model.layers[0].noise_level = 0.3
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
50 model.layers[1].noise_level = 0.3
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
51 model.layers[2].noise_level = 0.3
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
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
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
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
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
63
493
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
64
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
65
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
66
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
67 if __name__ == '__main__':
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
68 # print 'optimized:'
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
69 # t1 = test_train_daa(theano.Mode('py', 'fast_compile'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
70 # t1 = test_train_daa(theano.Mode('c|py', 'fast_run'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
71 # print 'time:',t1
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
72 # print
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
73
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
74 # print 'not optimized:'
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
75 # t2 = test_train_daa(theano.Mode('c|py', 'fast_compile'))
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
76 ## print 'time:',t2
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
77
32509c479e2d Added test_daa.py
Joseph Turian <turian@gmail.com>
parents:
diff changeset
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
3c60c2db0319 Added new daa test
Joseph Turian <turian@gmail.com>
parents: 493
diff changeset
82 test_train_daa2(theano.compile.Mode('c|py', 'merge'))