@@ -298,48 +298,49 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000, dataset='../data/m
298298 done_looping = False
299299 epoch = 0
300300 while (epoch < n_epochs ) and (not done_looping ):
301- epoch = epoch + 1
302- for minibatch_index in xrange (n_train_batches ):
301+ epoch = epoch + 1
302+ for minibatch_index in xrange (n_train_batches ):
303303
304- minibatch_avg_cost = train_model (minibatch_index )
305- # iteration number
306- iter = epoch * n_train_batches + minibatch_index
304+ minibatch_avg_cost = train_model (minibatch_index )
305+ # iteration number
306+ iter = epoch * n_train_batches + minibatch_index
307307
308- if (iter + 1 ) % validation_frequency == 0 :
309- # compute zero-one loss on validation set
310- validation_losses = [validate_model (i ) for i in xrange (n_valid_batches )]
311- this_validation_loss = numpy .mean (validation_losses )
308+ if (iter + 1 ) % validation_frequency == 0 :
309+ # compute zero-one loss on validation set
310+ validation_losses = [validate_model (i ) for i in xrange (n_valid_batches )]
311+ this_validation_loss = numpy .mean (validation_losses )
312312
313- print ('epoch %i, minibatch %i/%i, validation error %f %%' % \
314- (epoch , minibatch_index + 1 ,n_train_batches , \
315- this_validation_loss * 100. ))
313+ print ('epoch %i, minibatch %i/%i, validation error %f %%' % \
314+ (epoch , minibatch_index + 1 ,n_train_batches , \
315+ this_validation_loss * 100. ))
316316
317317
318- # if we got the best validation score until now
319- if this_validation_loss < best_validation_loss :
320- #improve patience if loss improvement is good enough
321- if this_validation_loss < best_validation_loss * \
318+ # if we got the best validation score until now
319+ if this_validation_loss < best_validation_loss :
320+ #improve patience if loss improvement is good enough
321+ if this_validation_loss < best_validation_loss * \
322322 improvement_threshold :
323- patience = max (patience , iter * patience_increase )
323+ patience = max (patience , iter * patience_increase )
324324
325- best_validation_loss = this_validation_loss
326- # test it on the test set
325+ best_validation_loss = this_validation_loss
326+ # test it on the test set
327327
328- test_losses = [test_model (i ) for i in xrange (n_test_batches )]
329- test_score = numpy .mean (test_losses )
328+ test_losses = [test_model (i ) for i in xrange (n_test_batches )]
329+ test_score = numpy .mean (test_losses )
330330
331- print ((' epoch %i, minibatch %i/%i, test error of best '
331+ print ((' epoch %i, minibatch %i/%i, test error of best '
332332 'model %f %%' ) % \
333- (epoch , minibatch_index + 1 , n_train_batches ,test_score * 100. ))
333+ (epoch , minibatch_index + 1 , n_train_batches ,test_score * 100. ))
334334
335- if patience <= iter :
335+ if patience <= iter :
336336 done_looping = True
337337 break
338338
339339 end_time = time .clock ()
340340 print (('Optimization complete with best validation score of %f %%,'
341341 'with test performance %f %%' ) %
342342 (best_validation_loss * 100. , test_score * 100. ))
343+ print 'The code run for %d epochs, with %f epochs/sec' % (epoch ,1. * (end_time - start_time )/ epoch )
343344 print >> sys .stderr , ('The code for file ' + os .path .split (__file__ )[1 ]+ ' ran for %.1fs expected 3.8s in our buildbot' % ((end_time - start_time )))
344345
345346if __name__ == '__main__' :
0 commit comments