annotate _test_xlogx.py @ 526:242efecefd70

corrected import.
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Fri, 14 Nov 2008 16:52:24 -0500
parents 117e5b09cf31
children 4e3629a894fa
rev   line source
450
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
1 from xlogx import xlogx
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
2
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
3 import unittest
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
4 from theano import compile
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
5 from theano import gradient
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
6
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
7 from theano.tensor import as_tensor
526
242efecefd70 corrected import.
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 450
diff changeset
8 import theano.tensor.basic as TT
450
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
9
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
10 import random
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
11 import numpy.random
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
12
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
13 class T_XlogX(unittest.TestCase):
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
14 def test0(self):
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
15 x = as_tensor([1, 0])
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
16 y = xlogx(x)
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
17 y = compile.eval_outputs([y])
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
18 self.failUnless(numpy.all(y == numpy.asarray([0, 0.])))
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
19 def test1(self):
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
20 class Dummy(object):
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
21 def make_node(self, a):
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
22 return [xlogx(a)[:,2]]
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
23 TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4)])
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
24
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
25
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
26 if __name__ == '__main__':
117e5b09cf31 Added an XlogX op.
Joseph Turian <turian@gmail.com>
parents:
diff changeset
27 unittest.main()