comparison deep/stacked_dae/v_sylvain/sgd_optimization.py @ 397:5e11dda78995

Ajout de fonctionnalite pour pouvoir facilement calculer une erreur sur differentes parties de NSIT
author SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
date Tue, 27 Apr 2010 20:50:56 -0400
parents 88cb95007670
children 09e1c5872c2b
comparison
equal deleted inserted replaced
396:116b2de2c0a4 397:5e11dda78995
392 if x.dtype=='float64': 392 if x.dtype=='float64':
393 self.classifier.params[idx].value=theano._asarray(copy(x),dtype=theano.config.floatX) 393 self.classifier.params[idx].value=theano._asarray(copy(x),dtype=theano.config.floatX)
394 else: 394 else:
395 self.classifier.params[idx].value=copy(x) 395 self.classifier.params[idx].value=copy(x)
396 396
397 def training_error(self,dataset): 397 def training_error(self,dataset,part=0):
398 # create a function to compute the mistakes that are made by the model 398 # create a function to compute the mistakes that are made by the model
399 # on the validation set, or testing set 399 # on the validation set, or testing set
400 test_model = \ 400 test_model = \
401 theano.function( 401 theano.function(
402 [self.classifier.x,self.classifier.y], self.classifier.errors) 402 [self.classifier.x,self.classifier.y], self.classifier.errors)
403 403 #train
404 iter2 = dataset.train(self.hp.minibatch_size,bufsize=buffersize) 404 if part == 0:
405 iter2 = dataset.train(self.hp.minibatch_size,bufsize=buffersize)
406 name = 'train'
407 #validation
408 if part == 1:
409 iter2 = dataset.valid(self.hp.minibatch_size,bufsize=buffersize)
410 name = 'validation'
411 if part == 2:
412 iter2 = dataset.test(self.hp.minibatch_size,bufsize=buffersize)
413 name = 'test'
405 train_losses2 = [test_model(x,y) for x,y in iter2] 414 train_losses2 = [test_model(x,y) for x,y in iter2]
406 train_score2 = numpy.mean(train_losses2) 415 train_score2 = numpy.mean(train_losses2)
407 print(('The training error is %f')%(train_score2*100.)) 416 print 'On the ' + name + 'dataset'
417 print(('\t the error is %f')%(train_score2*100.))
408 418
409 #To see the prediction of the model, the real answer and the image to judge 419 #To see the prediction of the model, the real answer and the image to judge
410 def see_error(self, dataset): 420 def see_error(self, dataset):
411 import pylab 421 import pylab
412 #The function to know the prediction 422 #The function to know the prediction