@@ -280,7 +280,7 @@ def test_score():
280280
281281
282282def test_SdA ( finetune_lr = 0.1 , pretraining_epochs = 15 , \
283- pretrain_lr = 0.1 , training_epochs = 1000 , \
283+ pretrain_lr = 0.05 , training_epochs = 1000 , \
284284 dataset = 'mnist.pkl.gz' ):
285285 """
286286 Demonstrates how to train and test a stochastic denoising autoencoder.
@@ -337,14 +337,16 @@ def test_SdA( finetune_lr = 0.1, pretraining_epochs = 15, \
337337 print '... pre-training the model'
338338 start_time = time .clock ()
339339 ## Pre-train layer-wise
340+ corruption_levels = [.1 ,.1 ,.0 ]
340341 for i in xrange (sda .n_layers ):
341342 # go through pretraining epochs
342343 for epoch in xrange (pretraining_epochs ):
343344 # go through the training set
344345 c = []
345346 for batch_index in xrange (n_train_batches ):
346347 c .append ( pretraining_fns [i ](index = batch_index ,
347- corruption = 0.2 , lr = pretrain_lr ) )
348+ corruption = corruption_levels [i ],
349+ lr = pretrain_lr ) )
348350 print 'Pre-training layer %i, epoch %d, cost ' % (i ,epoch ),numpy .mean (c )
349351
350352 end_time = time .clock ()
@@ -363,7 +365,7 @@ def test_SdA( finetune_lr = 0.1, pretraining_epochs = 15, \
363365
364366 print '... finetunning the model'
365367 # early-stopping parameters
366- patience = 10000 # look as this many examples regardless
368+ patience = 10 * n_train_batches # look as this many examples regardless
367369 patience_increase = 2. # wait this much longer when a new best is
368370 # found
369371 improvement_threshold = 0.995 # a relative improvement of this much is
@@ -384,45 +386,43 @@ def test_SdA( finetune_lr = 0.1, pretraining_epochs = 15, \
384386 epoch = 0
385387
386388 while (epoch < training_epochs ) and (not done_looping ):
387- epoch = epoch + 1
388- for minibatch_index in xrange (n_train_batches ):
389-
390- minibatch_avg_cost = train_fn (minibatch_index )
391- iter = epoch * n_train_batches + minibatch_index
392-
393- if (iter + 1 ) % validation_frequency == 0 :
394-
395- validation_losses = validate_model ()
396- this_validation_loss = numpy .mean (validation_losses )
397- print ('epoch %i, minibatch %i/%i, validation error %f %%' % \
389+ for minibatch_index in xrange (n_train_batches ):
390+ minibatch_avg_cost = train_fn (minibatch_index )
391+ iter = epoch * n_train_batches + minibatch_index
392+
393+ if (iter + 1 ) % validation_frequency == 0 :
394+ validation_losses = validate_model ()
395+ this_validation_loss = numpy .mean (validation_losses )
396+ print ('epoch %i, minibatch %i/%i, validation error %f %%' % \
398397 (epoch , minibatch_index + 1 , n_train_batches , \
399398 this_validation_loss * 100. ))
400399
401400
402- # if we got the best validation score until now
403- if this_validation_loss < best_validation_loss :
401+ # if we got the best validation score until now
402+ if this_validation_loss < best_validation_loss :
404403
405- #improve patience if loss improvement is good enough
406- if this_validation_loss < best_validation_loss * \
407- improvement_threshold :
408- patience = max (patience , iter * patience_increase )
404+ #improve patience if loss improvement is good enough
405+ if this_validation_loss < best_validation_loss * \
406+ improvement_threshold :
407+ patience = max (patience , iter * patience_increase )
409408
410- # save best validation score and iteration number
411- best_validation_loss = this_validation_loss
412- best_iter = iter
409+ # save best validation score and iteration number
410+ best_validation_loss = this_validation_loss
411+ best_iter = iter
413412
414- # test it on the test set
415- test_losses = test_model ()
416- test_score = numpy .mean (test_losses )
417- print ((' epoch %i, minibatch %i/%i, test error of best '
418- 'model %f %%' ) %
413+ # test it on the test set
414+ test_losses = test_model ()
415+ test_score = numpy .mean (test_losses )
416+ print ((' epoch %i, minibatch %i/%i, test error of best '
417+ 'model %f %%' ) %
419418 (epoch , minibatch_index + 1 , n_train_batches ,
420419 test_score * 100. ))
421420
422421
423- if patience <= iter :
422+ if patience <= iter :
424423 done_looping = True
425424 break
425+ epoch = epoch + 1
426426
427427 end_time = time .clock ()
428428 print (('Optimization complete with best validation score of %f %%,'
0 commit comments