diff baseline/mlp/mlp_nist.py @ 304:1e4bf5a5b46d

added type 2 adaptive learning configurable learning weight + versionning
author xaviermuller
date Wed, 31 Mar 2010 16:06:55 -0400
parents 9b6e0af062af
children 743907366476
line wrap: on
line diff
--- a/baseline/mlp/mlp_nist.py	Wed Mar 31 15:54:47 2010 -0400
+++ b/baseline/mlp/mlp_nist.py	Wed Mar 31 16:06:55 2010 -0400
@@ -31,7 +31,7 @@
 import time 
 import theano.tensor.nnet
 import pylearn
-import theano,pylearn.version
+import theano,pylearn.version,ift6266
 from pylearn.io import filetensor as ft
 
 data_path = '/data/lisa/data/nist/by_class/'
@@ -163,7 +163,7 @@
             raise NotImplementedError()
 
 
-def mlp_full_nist(      verbose = False,\
+def mlp_full_nist(      verbose = 1,\
                         adaptive_lr = 0,\
                         train_data = 'all/all_train_data.ft',\
                         train_labels = 'all/all_train_labels.ft',\
@@ -176,7 +176,8 @@
                         batch_size=20,\
                         nb_hidden = 500,\
                         nb_targets = 62,
-			tau=1e6):
+			tau=1e6,\
+			lr_t2_factor=0.5):
    
     
     configuration = [learning_rate,nb_max_exemples,nb_hidden,adaptive_lr]
@@ -217,7 +218,7 @@
     train_size*=batch_size
     validation_size =test_size 
     offset = train_size-test_size
-    if verbose == True:
+    if verbose == 1:
         print 'train size = %d' %train_size
         print 'test size = %d' %test_size
         print 'valid size = %d' %validation_size
@@ -248,7 +249,7 @@
     y = T.lvector()  # the labels are presented as 1D vector of 
                           # [long int] labels
 
-    if verbose==True:
+    if verbose==1:
         print 'finished parsing the data'
     # construct the logistic regression class
     classifier = MLP( input=x.reshape((batch_size,32*32)),\
@@ -325,7 +326,7 @@
     
     
    
-    if verbose == True:
+    if verbose == 1:
         print 'looping at most %d times through the data set' %n_iter
     for iter in xrange(n_iter* n_minibatches):
 
@@ -371,7 +372,7 @@
             if(this_train_loss<best_training_error):
                 best_training_error=this_train_loss
                 
-            if verbose == True:
+            if verbose == 1:
                 print('epoch %i, minibatch %i/%i, validation error %f, training error %f %%' % \
                     (epoch, minibatch_index+1, n_minibatches, \
                         this_validation_loss*100.,this_train_loss*100))
@@ -397,7 +398,7 @@
                     x_float=x/255.0
                     test_score += test_model(x_float,y)
                 test_score /= len(test_batches)
-                if verbose == True:
+                if verbose == 1:
                     print(('     epoch %i, minibatch %i/%i, test error of best '
                         'model %f %%') % 
                                 (epoch, minibatch_index+1, n_minibatches,
@@ -413,7 +414,7 @@
                 # however, if adaptive_lr is true, try reducing the lr to
                 # get us out of an oscilliation
                 if adaptive_lr==1:
-                    classifier.lr.value=classifier.lr.value/2.0
+                    classifier.lr.value=classifier.lr.value*lr_t2_factor
 
                 test_score = 0.
                 #cap the patience so we are allowed one more validation error
@@ -423,7 +424,7 @@
                     x_float=x/255.0
                     test_score += test_model(x_float,y)
                 test_score /= len(test_batches)
-                if verbose == True:
+                if verbose == 1:
                     print ' validation error is going up, possibly stopping soon'
                     print(('     epoch %i, minibatch %i/%i, test error of best '
                         'model %f %%') % 
@@ -440,7 +441,7 @@
 
     	time_n= time_n + batch_size
     end_time = time.clock()
-    if verbose == True:
+    if verbose == 1:
         print(('Optimization complete. Best validation score of %f %% '
             'obtained at iteration %i, with test performance %f %%') %  
                     (best_validation_loss * 100., best_iter, test_score*100.))
@@ -460,15 +461,22 @@
 
 def jobman_mlp_full_nist(state,channel):
     (train_error,validation_error,test_error,nb_exemples,time)=mlp_full_nist(learning_rate=state.learning_rate,\
-                                                                nb_max_exemples=state.nb_max_exemples,\
-                                                                nb_hidden=state.nb_hidden,\
-                                                                adaptive_lr=state.adaptive_lr,\
-								tau=state.tau)
+										nb_max_exemples=state.nb_max_exemples,\
+										nb_hidden=state.nb_hidden,\
+										adaptive_lr=state.adaptive_lr,\
+										tau=state.tau,\
+										verbose = state.verbose,\
+										train_data = state.train_data,\
+										train_labels = state.train_labels,\
+										test_data = state.test_data,\
+										test_labels = state.test_labels,\
+										lr_t2_factor=state.lr_t2_factor)
     state.train_error=train_error
     state.validation_error=validation_error
     state.test_error=test_error
     state.nb_exemples=nb_exemples
     state.time=time
+    pylearn.version.record_versions(state,[theano,ift6266,pylearn])
     return channel.COMPLETE
                                                                 
                                                                 
\ No newline at end of file