Mercurial > pylearn
annotate _test_nnet_ops.py @ 380:c2f17f231960
added function to load amat file
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Wed, 09 Jul 2008 16:55:27 -0400 |
parents | 2ee53bae9ee0 |
children | 43d9aa93934e |
rev | line source |
---|---|
24 | 1 |
2 import unittest | |
3 import theano._test_tensor as TT | |
4 import numpy | |
5 | |
6 from nnet_ops import * | |
7 | |
8 class T_sigmoid(unittest.TestCase): | |
9 def setUp(self): | |
10 numpy.random.seed(9999) | |
11 def test_elemwise(self): | |
117
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
12 TT.verify_grad(self, sigmoid, [numpy.random.rand(3,4)]) |
24 | 13 |
69
8c2607f387e6
added softplus, elaborated sigmoid
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
30
diff
changeset
|
14 class T_softplus(unittest.TestCase): |
8c2607f387e6
added softplus, elaborated sigmoid
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
30
diff
changeset
|
15 def setUp(self): |
8c2607f387e6
added softplus, elaborated sigmoid
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
30
diff
changeset
|
16 numpy.random.seed(9999) |
8c2607f387e6
added softplus, elaborated sigmoid
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
30
diff
changeset
|
17 def test_elemwise(self): |
117
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
18 TT.verify_grad(self, softplus, [numpy.random.rand(3,4)]) |
24 | 19 |
20 class T_CrossentropySoftmax1Hot(unittest.TestCase): | |
21 def setUp(self): | |
22 numpy.random.seed(9999) | |
23 def test0(self): | |
24 y_idx = [0,1,3] | |
117
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
25 class Dummy(object): |
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
26 def make_node(self, a,b): |
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
27 return crossentropy_softmax_1hot_with_bias(a, b, y_idx)[0:1] |
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
28 TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4), |
30
bf0145fa73e8
added c implementation for CrossentropySoftmax1Hot
bergstrj@iro.umontreal.ca
parents:
25
diff
changeset
|
29 numpy.random.rand(4)]) |
24 | 30 |
70
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
31 def test1(self): |
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
32 y_idx = [0,1,3] |
117
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
33 class Dummy(object): |
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
34 def make_node(self, a): |
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
35 return crossentropy_softmax_1hot(a, y_idx)[0:1] |
3ef569b92fba
ported nnet_ops to new theano
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
70
diff
changeset
|
36 TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4)]) |
70
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
37 |
24 | 38 |
39 | |
40 if __name__ == '__main__': | |
41 unittest.main() |