# HG changeset patch # User Yoshua Bengio # Date 1210209776 14400 # Node ID 4c2280edcaf5760d8da8846ec33284a7a2784ba0 # Parent ee5507af2c6087e2e9be8dc52f55dfd572695215 Fixed typos in learner.py diff -r ee5507af2c60 -r 4c2280edcaf5 learner.py --- a/learner.py Wed May 07 20:51:24 2008 -0400 +++ b/learner.py Wed May 07 21:22:56 2008 -0400 @@ -1,6 +1,7 @@ -from dataset import AttributesHolder +from dataset import AttributesHolder,AbstractFunction import compile +from theano import tensor as t class Learner(AttributesHolder): """Base class for learning algorithms, provides an interface @@ -136,9 +137,9 @@ of (optionally copies) values of attributes. """ if return_copy: - return [copy.deepcopy(self.__getattr__(name).data) for name in names] + return [copy.deepcopy(self.__getattribute__(name).data) for name in names] else: - return [self.__getattr__(name).data for name in names] + return [self.__getattribute__(name).data for name in names] def updateInputAttributes(self): """ @@ -252,7 +253,7 @@ Private helper function that maps a list of attribute names to a list of corresponding Op Results (with the same name but with a '_' prefix). """ - return [self.__getattr__('_'+name).data for name in names] + return [self.__getattribute__('_'+name).data for name in names] class MinibatchUpdatesTLearner(TLearner): @@ -355,7 +356,7 @@ self.updateEnd() return self.use -class OnlineGradientBasedTLearner(MinibatchUpdatesTLearner): +class OnlineGradientTLearner(MinibatchUpdatesTLearner): """ Specialization of MinibatchUpdatesTLearner in which the minibatch updates are obtained by performing an online (minibatch-based) gradient step. @@ -376,14 +377,14 @@ self.truly_online=truly_online # create the formulas for the gradient update - old_params = [self.__getattr__("_"+name) for name in self.parameterAttributes()] + old_params = [self.__getattribute__("_"+name) for name in self.parameterAttributes()] new_params_names = ["_new_"+name for name in self.parameterAttributes()] - loss = self.__getattr__(self.lossAttribute()) + loss = self.__getattribute__("_"+self.lossAttribute()) self.setAttributes(new_params_names, - [t.add_inplace(self.param, - self._learning_rate*t.grad(loss,param)) + [t.add_inplace(param,self._learning_rate*t.grad(loss,param)) for param in old_params]) - + MinibatchUpdatesTLearner.__init__(self) + def isLastEpoch(self): return self.truly_online diff -r ee5507af2c60 -r 4c2280edcaf5 mlp.py --- a/mlp.py Wed May 07 20:51:24 2008 -0400 +++ b/mlp.py Wed May 07 21:22:56 2008 -0400 @@ -7,7 +7,7 @@ # the use of theano -class OneHiddenLayerNNetClassifier(MinibatchUpdatesTLearner): +class OneHiddenLayerNNetClassifier(OnlineGradientTLearner): """ Implement a straightforward classicial feedforward one-hidden-layer neural net, with L2 regularization. @@ -83,7 +83,7 @@ self._output_class = t.argmax(self._output,1) self._class_error = self._output_class != self._target self._minibatch_criterion = self._nll + self._regularization_term / t.shape(self._input)[0] - MinibatchUpdatesTLearner.__init__(self) + OnlineGradientTLearner.__init__(self) def attributeNames(self): return ["parameters","b1","W2","b2","W2", "L2_regularizer","regularization_term"]