# HG changeset patch # User Pascal Lamblin # Date 1219440799 14400 # Node ID 9cfc2fc0f4d1fb4112aea105fe29707f3ba19c50 # Parent 060c12314734a2e43e1c12a8ca48936ab388f657 New tests for softmax. diff -r 060c12314734 -r 9cfc2fc0f4d1 _test_nnet_ops.py --- a/_test_nnet_ops.py Fri Aug 22 17:33:06 2008 -0400 +++ b/_test_nnet_ops.py Fri Aug 22 17:33:19 2008 -0400 @@ -18,6 +18,59 @@ def test_elemwise(self): TT.verify_grad(self, softplus, [numpy.random.rand(3,4)]) +class T_Softmax(unittest.TestCase): + def setUp(self): + numpy.random.seed(9999) + def test0(self): + class Dummy(object): + def make_node(self, a): + return [softmax(a)[:,0]] + TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4)]) + def test1(self): + class Dummy(object): + def make_node(self, a): + return [softmax(a)[:,1]] + TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4)]) + def test2(self): + class Dummy(object): + def make_node(self, a): + return [softmax(a)[:,2]] + TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4)]) + def test3(self): + class Dummy(object): + def make_node(self, a): + return [softmax(a)[:,3]] + TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4)]) + + +class T_SoftmaxWithBias(unittest.TestCase): + def setUp(self): + numpy.random.seed(9999) + def test0(self): + class Dummy(object): + def make_node(self, a, b): + return [softmax_with_bias(a, b)[:,0]] + TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4), + numpy.random.rand(4)]) + def test1(self): + class Dummy(object): + def make_node(self, a, b): + return [softmax_with_bias(a, b)[:,1]] + TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4), + numpy.random.rand(4)]) + def test2(self): + class Dummy(object): + def make_node(self, a, b): + return [softmax_with_bias(a, b)[:,2]] + TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4), + numpy.random.rand(4)]) + def test3(self): + class Dummy(object): + def make_node(self, a, b): + return [softmax_with_bias(a, b)[:,3]] + TT.verify_grad(self, Dummy(), [numpy.random.rand(3,4), + numpy.random.rand(4)]) + class T_CrossentropySoftmax1Hot(unittest.TestCase): def setUp(self): numpy.random.seed(9999)