diff deep/stacked_dae/v_sylvain/sgd_optimization.py @ 325:048898c1ee55

Ajout d'une fonction pour calculer l'erreur effectuee par le modele sur un ensemble pre-determine
author SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
date Fri, 09 Apr 2010 15:49:42 -0400
parents 403b9e6ecfaa
children 18dc860a4ef4
line wrap: on
line diff
--- a/deep/stacked_dae/v_sylvain/sgd_optimization.py	Thu Apr 08 11:22:11 2010 -0400
+++ b/deep/stacked_dae/v_sylvain/sgd_optimization.py	Fri Apr 09 15:49:42 2010 -0400
@@ -341,6 +341,19 @@
                 self.classifier.params[idx].value=theano._asarray(copy(x),dtype=theano.config.floatX)
             else:
                 self.classifier.params[idx].value=copy(x)
+                
+    #Calculate error over the training set (or a part of)           
+    def training_error(self,data):
+        # create a function to compute the mistakes that are made by the model
+        # on the validation set, or testing set
+        test_model = \
+            theano.function(
+                [self.classifier.x,self.classifier.y], self.classifier.errors)
+                
+        iter2 = data.train(self.hp.minibatch_size,bufsize=buffersize)
+        train_losses2 = [test_model(x,y) for x,y in iter2]
+        train_score2 = numpy.mean(train_losses2)
+        print "Training error is: " + str(train_score2)