changeset 179:9911d2cc3c01

merged
author James Bergstra <bergstrj@iro.umontreal.ca>
date Tue, 13 May 2008 15:14:04 -0400
parents 4090779e39a9 (current diff) 6ee54861134e (diff)
children 2698c0feeb54
files mlp.py
diffstat 3 files changed, 37 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/misc.py	Tue May 13 15:12:20 2008 -0400
+++ b/misc.py	Tue May 13 15:14:04 2008 -0400
@@ -1,3 +1,24 @@
+
+import theano
+
+class Print(theano.Op):
+    def __init__(self,message=""):
+        self.message=message
+        self.view_map={0:[0]}
+
+    def make_node(self,xin):
+        xout = xin.type.make_result()
+        return theano.Apply(op = self, inputs = [xin], outputs=[xout])
+
+    def perform(self,node,inputs,output_storage):
+        xin, = inputs
+        xout, = output_storage
+        xout[0] = xin
+        print self.message,xin
+
+    def grad(self,input,output_gradients):
+        return output_gradients
+
 
 def unique_elements_list_intersection(list1,list2):
     """
--- a/mlp.py	Tue May 13 15:12:20 2008 -0400
+++ b/mlp.py	Tue May 13 15:14:04 2008 -0400
@@ -9,22 +9,7 @@
 from theano import tensor as t
 from nnet_ops import *
 import math
-
-def sum_l2_cost(*params):
-    p = params[0]
-    rval = t.sum(p*p)
-    for p in params[1:]:
-        rval = rval + t.sum(p*p)
-    return rval
-
-def activation(w, b, v, c, x):
-    return t.dot(t.tanh(t.dot(x, w) + b), v) + c
-def nll(w, b, v, c, x, y):
-    return  crossentropy_softmax_1hot(prediction(w, b, v, c, x), y)[0]
-def output(w, b, v, c, x, y):
-    return  crossentropy_softmax_1hot(prediction(w, b, v, c, x), y)[1]
-
-
+from misc import *
 
 class OneHiddenLayerNNetClassifier(OnlineGradientTLearner):
     """
@@ -102,7 +87,7 @@
         self._b2 = t.row('b2')
         self._regularization_term = self._L2_regularizer * (t.sum(self._W1*self._W1) + t.sum(self._W2*self._W2))
         self._output_activations =self._b2+t.dot(t.tanh(self._b1+t.dot(self._input,self._W1.T)),self._W2.T)
-        self._nll,self._output = crossentropy_softmax_1hot(self._output_activations,self._target_vector)
+        self._nll,self._output = crossentropy_softmax_1hot(Print("output_activations")(self._output_activations),self._target_vector)
         self._output_class = t.argmax(self._output,1)
         self._class_error = t.neq(self._output_class,self._target_vector)
         self._minibatch_criterion = self._nll + self._regularization_term / t.shape(self._input)[0]
--- a/test_dataset.py	Tue May 13 15:12:20 2008 -0400
+++ b/test_dataset.py	Tue May 13 15:14:04 2008 -0400
@@ -4,7 +4,6 @@
 import numpy
 
 def have_raised(to_eval, **var):
-    
     have_thrown = False
     try:
         eval(to_eval)
@@ -12,6 +11,14 @@
         have_thrown = True
     return have_thrown
 
+def have_raised2(f, *args, **kwargs):
+    have_thrown = False
+    try:
+        f(*args, **kwargs)
+    except :
+        have_thrown = True
+    return have_thrown
+
 def test1():
     print "test1"
     global a,ds
@@ -325,12 +332,12 @@
   #    - 'fieldtypes': a list of types (one per field)
 
 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#????
-    #hstack([ds('x','y'),ds('z')]
-    #hstack([ds('z','y'),ds('x')]
-    #assert have_thrown("hstack([ds('x'),ds('x')]")
-    #assert not have_thrown("hstack([ds('x'),ds('x')]")
-    #accept_nonunique_names
-    #assert have_thrown("hstack([ds('y','x'),ds('x')]")
+    #assert hstack([ds('x','y'),ds('z')])==ds
+    #hstack([ds('z','y'),ds('x')])==ds
+    assert have_raised2(hstack,[ds('x'),ds('x')])
+    assert have_raised2(hstack,[ds('y','x'),ds('x')])
+    assert not have_raised2(hstack,[ds('x'),ds('y')])
+    
 #        i=0
 #        for example in hstack([ds('x'),ds('y'),ds('z')]):
 #            example==ds[i]