# HG changeset patch # User James Bergstra # Date 1210706044 14400 # Node ID 9911d2cc3c0162d2d413453fce19b57d44472ee6 # Parent 4090779e39a95708e9211557e4297cf7df6e47d3# Parent 6ee54861134e1ad3088511f721b876e198178038 merged diff -r 4090779e39a9 -r 9911d2cc3c01 misc.py --- 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): """ diff -r 4090779e39a9 -r 9911d2cc3c01 mlp.py --- 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] diff -r 4090779e39a9 -r 9911d2cc3c01 test_dataset.py --- 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]