changeset 769:0ff7ac3253b3

added test for FillMissing op.
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Tue, 09 Jun 2009 21:37:58 -0400
parents bd95e8ea99d8
children 742972b6906a
files pylearn/sandbox/test_scan_inputs_groups.py
diffstat 1 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylearn/sandbox/test_scan_inputs_groups.py	Tue Jun 09 21:37:58 2009 -0400
@@ -0,0 +1,44 @@
+import sys, time, unittest
+
+import numpy
+import numpy as N
+
+from theano.tests import unittest_tools as utt
+
+from theano import function, Mode
+import theano.tensor as T
+from pylearn.sandbox.scan_inputs_groups import FillMissing
+
+
+if __name__ == '__main__':
+    t = TestConvOp("test_convolution")
+    t.test_convolution()
+    t.test_multilayer_conv()
+    from theano.tests import main
+    main("test_sp")
+
+class TestFillMissing(unittest.TestCase):
+    def setUp(self):
+        utt.seed_rng()
+
+    def test_base(self):
+        v=T.dvector()
+        op=FillMissing()(v)
+        fct=function([v],op)
+        
+        prob=N.random.random(1000)
+        val=N.random.random(len(prob))
+        nb_missing=0
+        for i in range(len(val)):
+            if prob[i]<0.1:
+                nb_missing+=1
+                val[i]=N.nan
+
+        out=fct(val)
+        for i in range(len(prob)):
+            if N.isnan(val[i]):
+                assert out[0][i]==0
+                assert out[1][i]==0
+            else:
+                assert out[1][i]==1
+