@@ -135,14 +135,14 @@ class dA(object):
135135
136136 """
137137
138- def __init__ (self , n_visible = 784 , n_hidden = 500 , input = None ):
138+ def __init__ (self , n_visible = 784 , n_hidden = 500 , input = None , corruption_level = 0.1 ):
139139 """
140140 Initialize the dA class by specifying the number of visible units (the
141141 dimension d of the input ), the number of hidden units ( the dimension
142142 d' of the latent or hidden space ) and by giving a symbolic variable
143143 for the input. Such a symbolic variable is useful when the input is
144144 the result of some computations. For example when dealing with SdAs,
145- the dA on layer 2 gets as input the output of the DAE on layer 1.
145+ the dA on layer 2 gets as input the output of the dA on layer 1.
146146 This output can be written as a function of the input to the entire
147147 model, and as such can be computed by theano whenever needed.
148148
@@ -152,6 +152,13 @@ def __init__(self, n_visible= 784, n_hidden= 500, input= None):
152152
153153 :param input: a symbolic description of the input or None
154154
155+ :param corruption_level: the corruption mechanism picks up randomly this fraction
156+ of entries of the input and turns them to 0
157+
158+
159+ amount of entries from the input to 0 from the input, defaul
160+ is 0.1, which means 10% of entries are corrupted to 0
161+
155162 """
156163 self .n_visible = n_visible
157164 self .n_hidden = n_hidden
@@ -198,8 +205,8 @@ def __init__(self, n_visible= 784, n_hidden= 500, input= None):
198205 # third argument is the probability of success of any trial
199206 #
200207 # this will produce an array of 0s and 1s where 1 has a
201- # probability of 0.9 and 0 if 0.1
202- self .tilde_x = theano_rng .binomial ( self .x .shape , 1 , 0.9 ) * self .x
208+ # probability of 1 - corruption_level and 0 if corruption_level
209+ self .tilde_x = theano_rng .binomial ( self .x .shape , 1 , 1 - corruption_level ) * self .x
203210 # Equation (2)
204211 # note : y is stored as an attribute of the class so that it can be
205212 # used later when stacking dAs.
@@ -358,7 +365,9 @@ def shared_dataset(data_xy):
358365 # construct the logistic regression class
359366 classifier = SdA ( input = x , n_ins = 28 * 28 , \
360367 hidden_layers_sizes = [1000 , 1000 , 1000 ], n_outs = 10 )
361-
368+
369+
370+ start_time = time .clock ()
362371 ## Pre-train layer-wise
363372 for i in xrange (classifier .n_layers ):
364373 cost = classifier .layers [i ].cost
@@ -387,7 +396,9 @@ def shared_dataset(data_xy):
387396
388397
389398
399+ end_time = time .clock ()
390400
401+ print ('Pretraining took %f minutes' % ((end_time - start_time )/ 60. ))
391402 # Fine-tune the entire model
392403 # the cost we minimize during training is the negative log likelihood of
393404 # the model
@@ -435,9 +446,9 @@ def shared_dataset(data_xy):
435446
436447 # early-stopping parameters
437448 patience = 10000 # look as this many examples regardless
438- patience_increase = 2 # wait this much longer when a new best is
449+ patience_increase = 2. # wait this much longer when a new best is
439450 # found
440- improvement_threshold = 0.995 # a relative improvement of this much is
451+ improvement_threshold = 0.99 # a relative improvement of this much is
441452 # considered significant
442453 validation_frequency = min (n_train_batches , patience / 2 )
443454 # go through this many
@@ -450,15 +461,19 @@ def shared_dataset(data_xy):
450461 best_validation_loss = float ('inf' )
451462 test_score = 0.
452463 start_time = time .clock ()
453- cost_ij = []
454- for epoch in xrange (training_epochs ):
464+
465+ done_looping = False
466+ epoch = 0
467+
468+ while (epoch < training_epochs ) and (not done_looping ):
469+ epoch = epoch + 1
455470 for minibatch_index in xrange (n_train_batches ):
456471
457- cost_ij += [ train_model (minibatch_index )]
472+ cost_ij = train_model (minibatch_index )
458473 iter = epoch * n_train_batches + minibatch_index
459474
460475 if (iter + 1 ) % validation_frequency == 0 :
461- cost_ij = []
476+
462477 validation_losses = [validate_model (i ) for i in xrange (n_valid_batches )]
463478 this_validation_loss = numpy .mean (validation_losses )
464479 print ('epoch %i, minibatch %i/%i, validation error %f %%' % \
@@ -488,6 +503,7 @@ def shared_dataset(data_xy):
488503
489504
490505 if patience <= iter :
506+ done_looping = True
491507 break
492508
493509 end_time = time .clock ()
0 commit comments