changeset 661:d8ad0ce259a6

Added a gradient test for nlpoisson.
author Joseph Turian <turian@iro.umontreal.ca>
date Tue, 10 Mar 2009 15:58:52 -0400
parents 12b1b09ffd2b
children 6c602a86e711
files pylearn/algorithms/sandbox/test_cost.py
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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()