# HG changeset patch # User Joseph Turian # Date 1236715132 14400 # Node ID d8ad0ce259a6fd12f2098402fc9634af7a2eec4d # Parent 12b1b09ffd2b32349b0c507331b736d00c0453de Added a gradient test for nlpoisson. diff -r 12b1b09ffd2b -r d8ad0ce259a6 pylearn/algorithms/sandbox/test_cost.py --- a/pylearn/algorithms/sandbox/test_cost.py Mon Mar 09 03:11:20 2009 -0400 +++ b/pylearn/algorithms/sandbox/test_cost.py Tue Mar 10 15:58:52 2009 -0400 @@ -30,12 +30,13 @@ f = T.function([],o) self.failUnless(f() - 33751.7816277 < 1e-5) -# def test_gradient(self): -# target = TT.as_tensor([0, 0, 1, 1, 2, 2, 100, 100]) -# output = TT.as_tensor([0., 1, 1., 0, 1, 0, 5, 1]) -# o = cost.nlpoisson(target, output) -# f = T.function([],o) -# self.failUnless(f() - 33751.7816277 < 1e-5) + def test_gradient(self): + target = TT.as_tensor([0, 0, 1, 1, 2, 2, 100, 100]) + output = TT.as_tensor([0., 1, 1., 0, 1, 0, 5, 1]) + loss = cost.nlpoisson(target, output) + (goutput) = TT.grad(loss, [output]) + f = T.function([], goutput) + self.failUnless(f() - 33751.7816277 < 1e-5) if __name__ == '__main__': unittest.main()