Mercurial > pylearn
annotate _nnet_ops.py @ 113:b6bc1e769b36
Automated merge with ssh://p-omega1@lgcm.iro.umontreal.ca/tlearn
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Wed, 07 May 2008 12:12:48 -0400 |
parents | 76e5c0f37165 |
children | 3ef569b92fba |
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): | |
12 TT.verify_grad(self, Sigmoid, [numpy.random.rand(3,4)]) | |
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): |
8c2607f387e6
added softplus, elaborated sigmoid
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
30
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] | |
30
bf0145fa73e8
added c implementation for CrossentropySoftmax1Hot
bergstrj@iro.umontreal.ca
parents:
25
diff
changeset
|
25 def output1(a,b): |
70
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
26 return crossentropy_softmax_1hot_with_bias(a, b, y_idx)[0:1] |
30
bf0145fa73e8
added c implementation for CrossentropySoftmax1Hot
bergstrj@iro.umontreal.ca
parents:
25
diff
changeset
|
27 TT.verify_grad(self, output1, [numpy.random.rand(3,4), |
bf0145fa73e8
added c implementation for CrossentropySoftmax1Hot
bergstrj@iro.umontreal.ca
parents:
25
diff
changeset
|
28 numpy.random.rand(4)]) |
24 | 29 |
70
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
30 def test1(self): |
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
31 y_idx = [0,1,3] |
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
32 def output1(a): |
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
33 return crossentropy_softmax_1hot(a, y_idx)[0:1] |
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
34 TT.verify_grad(self, output1, [numpy.random.rand(3,4)]) |
76e5c0f37165
better docs & precondition testing for cross_entropy_softmax_1hot & friends
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
69
diff
changeset
|
35 |
24 | 36 |
37 | |
38 if __name__ == '__main__': | |
39 unittest.main() |